How to add sensors correctly

Tags: #<Tag:0x00007f3268ae37a0> #<Tag:0x00007f3268ae3660>

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}}"

What’s the output of the template_sensor when one of the values is zero ?

{{0|float}} == 0.0

How and where do I find out? Are we a novice user?

In the developer tools/template.

1 Like

the output is as follows:

0.0 == 0.0