I have a template energy sensor. very simple (see config bellow). I have noticed a strange behavior. sometimes the value drops to 0 literally for one reading, that’s of course further screws up my utility meters.
the sensors used in this template gets data from ESPHome integration. I thought maybe in some cases I got 0 from integration. but if I check this sensors, everything looks like ok, there are no zeros recorded.
The other option is to use an availability template:
- platform: template
sensors:
energy_total_usage:
friendly_name: "Total energy usage"
unit_of_measurement: Wh
value_template: >-
{{ (states('sensor.energija_a_faze')|float + states('sensor.energija_b_faze')|float + states('sensor.energija_c_faze')|float) }}
availability_template: >-
{{ states('sensor.energija_a_faze') not in ['unknown', 'unavailable'] and states('sensor.energija_b_faze') not in ['unknown', 'unavailable'] and states('sensor.energija_c_faze') not in ['unknown', 'unavailable'] }}
Though I don’t think any of the sensors it is composed of should ever be zero. They should only ever increase. However one of them may become available before the rest so this would be better:
Thanks, man. I have checked the data archive, and I see that, indeed, all composing sensors were unavailable at this time. Probably because ESP has lost wifi connection or were some issues with Modbus. anyway this is another story.
I like your solution with the availability template. And will try this way.
I think it would be good to have quality value for analog sensors We have our own remote control system where we also have qualities like GOOD, OLD, UNK, HI, LOW, etc very convenient.
Sensors actually can be 0 if I decide to reset or change the meter or meter overflow
This is interesting. For anyone else doing this same setup with utility meter, I’d suggest using the value_template method…
I had this same issue and used first the availability template to fix it. Now I’ve found that while unavailable, the utility meter loses all the energy used during that time period.
For example, say I lost my kWh sensor for 1 hour. The sensor was at 6 kWh, then went unavailable, but came back at 7 kWh 1 hour later. The utility meter will continue increasing from 6 kWh, completely ignoring the 1 kWh increase that happened while unavailable.
I’m going to try the value_template hack of setting the template sensor to it’s own state when the original sensors go unavailable, as I think that would allow the utility meter to “catch up” and be accurate again.