A resilient sensor summing other sensors

Hi folks
I have a sensor summing other sensors

    storage_heater_power_phase1:
      unique_id: b3dfeb09-73f5-42d7-b92f-3fc977bb4dd6
      friendly_name: "Storage heaters phase1"
      unit_of_measurement: 'W'
      value_template: '{{ states("sensor.sutherland_storage_heater_power") | float + states("sensor.workshop_storage_heater_power") | float }}'

If one of the sensors goes offline, the sum sensor is also unavailable. How could I make it resilient to this, to return the value of the online sensor even if the other goes offline?

Many thanks in advance
Roger

Replace float with float(0) which provides a default value of zero.

If the sensor’s value is unavailable or unknown, then float(0) will convert it to 0.

0 + 21.5 = 21.5
18.25 + 0 = 18.25
0 + 0 = 0
1 Like

This will do what you want. It ensure’s you always have an average of the available sensors. And you can easily add sensors to it.

{{ ["sensor.sutherland_storage_heater_power", "sensor.workshop_storage_heater_power"] | select('is_number') | map('float') | sum }}
1 Like