Hello,
I have some IKEA INSPELNING smart plugs to measure energy usage. Unfortunately my energy meter is too far away for me to measure that, so I have to use my smart plugs and reading measurements directly from my energy meter is not an option.
To include them properly inside my energy dashboard, I created the following template sensor with some help from some older posts:
- sensor:
- name: "Haushalt Stromverbrauch"
unique_id: "home_energy_usage"
unit_of_measurement: "kWh"
state_class: "total_increasing"
device_class: "energy"
state: >
{{ states.sensor
| selectattr('attributes.device_type', 'equalto', 'Electric Metering')
| map(attribute='state')
| select('is_number')
| map('float')
| reject('==', 0.0)
| sum }}
This works fine as long as all energy meters properly report a value. Though if a device becomes unavailable, and for some reason they all become unavailable at the same time at night for 3 seconds, the sensor reports 0. This messes with my energy dashboard, as it creates those spikes:
Obviously this is not correct, but I figured that this happens due to the way the energy dashboard works: By using the sensor difference from the last measurement. In this case, it jumps from 0 (because all devices are unavailable) to ~250kWh.
Somewhere in the forum I read, that the energy dashboard will not use the measurement if it reports as unavailable. So I figured that I should make the accumulation template sensor unavailable when at least one device doesn’t report a proper value.
This is where I stuck now. I have literally no idea on how I should do that. Is this even the right way to do that or is there another, maybe better way?
Any help is appreciated, thanks!