I have a device from which we read the states of three Shelly 3EM sensors. I then use templates to further process them with mathematical operations.
But the problem arises when the sensors return 0 due to the “float” and it spoils my calculations. This happens after restarting Home Assistan, or if the router is offline. How to get rid of it?
Here is a sample code:
sensor:
- platform: template
sensors:
energy_consumption_total:
friendly_name: Energy Consumption Total
icon_template: mdi:flash
unit_of_measurement: kWh
value_template: "{{ states('sensor.shelly_shem_3_40f52001972c_1_total_consumption')|float + states('sensor.shelly_shem_3_40f52001972c_2_total_consumption')|float + states('sensor.shelly_shem_3_40f52001972c_3_total_consumption')|float}}"