Helper Sum "Unavailable"

Team,

In quite a few scenarios I use helpers to combine values of several entities. (“SUM”)

shelly_officedesk_power
shelly_officeac_power
shelly_officeequipment_power

If one of these sensors becomes unavailable:
the helper becomes unavailable, otherwise it nicely shows the sum value.

As a result I cannot use the GUI and have to revert to YAML confuguration:

template:
  - sensor:
    - name: "Electricity OFFICE Total"
      unit_of_measurement: "kWh"
      state: >
        {{ (states('sensor.shelly_officedesk_power') | float(0) + states('sensor.shelly_officeac_power') | float(0) + states('sensor.shelly_officeequipment_power') | float(0) ) | round(1) }}

With the YAML config the ‘fallback value’ of these entities is 0 (| float(0))

All of the other settings of this helper do seem to deal with the unavailable sensor: Minimum, Maximum, Arithmetic mean, median, most recently updated, statistical range, except for sum.

Would it make sense that a SUM helper ignores “unavailable” entities in its configuration?

2 Likes

if you have a solution, please let me know. i would also be interested. i also had to solve it with a float 0 and am not happy with this solution.

1 Like
avg_sensor:

  value_template: >
    {% set sensors = [
      states('sensor.sensor1'),
      states('sensor.sensor2')
    ] %}

    {% set available_sensors = sensors | select('is_number') | list %}

    {% if available_sensors | length > 0 %}
      {{ (available_sensors | map('float') | sum / available_sensors | length) | float }}
    {% else %}
      unavailable
    {% endif %}