In Energy Meter I added new sensor which is calculating spent kWh (A) as deducting kWh from other three sensors: Shelly EM (B), Shelly 1PM (C) and Shelly 1PM (D).
Sensor:
A = B - C - D
Everything was fine until power loss in house. After power was back, Shelly EM kept last total energy consumption while both Shelly 1PMs resets their counter to zero (this is normal behavior because they don’t have battery like Shelly EM).
Of course, in that case, calculation in Energy tab was wrong because sensor A showed higher kWh spent because Shelly 1PMs C and D were back to zero.
Is there any hack or code in HA to prevent this or to remember last total energy for Shelly 1PMs before power loss in order to have correct calculation of sensor A?
You have a template for A right? So you can just add the last correct value like A = (B + 217) - (C + 33) - (D +1000)
Or you use an Utility Meter and then make a new template with A = UMb - UMc - UMd
Well… It’s a tricky because I am not sure what is last correct value for Shelly 1PM before drop to zero. Also, for variable B I don’t need to add anything because Shelly EM remembers last value on power outage.
Additionally, if I change template A, then all other values will be wrong because this modified template is valid only after power outage.
I hope you understand me.
Yeah alright then you should make Utility Meters and calibrate them with the last value. Why dont you know the last value? It should be in Home Assistant.
Also you can edit the wrong values from the energy dashboard by going to Developer tools → Statistics and then the graph icon of the right sensor.