Hello,
I have an odd problem with an utility meter sensor that tracks my kWh. I have some Shelly EM that track some “sections” of my house and a value template to sum every section to have the total W and kWh of the house.
If one (or more) Shelly EM goes offline or reboots or turn off, the value template increase its value with an abnormal error.
Thank you very much for your reply. I thought that adding (0) was ok for unavailable too. I will try to understand more about it, now I am a bit confused
I will implement your code and report.
Got it. Could you please explain me one more thing? The first 2 sensors are 2 inputs in the first Shelly EM, the 3rd and 4th are another Shelly EM. What happens if just one out of two Shelly is offline? I think that, since there is an “and”, the total sensor will be unavailable because 2 sensors are not number. Is it a problem?
All of the sensors have to be available for the template to output a result. This prevents similar jumps in the utility meter total (though not as big) if one sensor becomes unavailable momentarily.
I faced a similar problem. I have a zigbee electricity meter with energy sensor in Wh, I also have a sensor with the conversion of these Wh to kWh and I also have a utility meter sensor in which the above-mentioned conversion sensor (Wh to kWh) is used as a source, and this utility meter sensor is calibrated with my physical electricity meter.
If my zigbee meter is unavailable or I reload templates and etc., the utility meter always adds the already accumulated last value from the sensor in Wh, and I always have 6650+ extra kWh.
My template looks like this and it solved the problem: