Help on Expanding group of sensors and adding their values. (Warning spam on float values)

Hey everyone,

I have created a system generated group that rounds up all the power consumption sensors of my house.
This script runs on startup.

Next step, i want to expand the group, add them up and substract them from the total consumption of my house, in order to see what’s unaccounted for.

The code works well so far, but i’m getting tens of thousands of warnings on the log.
Template warning: 'float' got invalid input 'unavailable' when rendering template...

I suspect this is because while expanding the group, the floats that get added up do not have a (default =…) value or a (0) after them.

Here is my code:

sensor:
  - platform: template
    sensors:
        paleo_rest_of_the_house_power:
          friendly_name: Rest of the house power consumption
          unit_of_measurement: W
          icon_template: mdi:flash
          value_template: >-
            {% if is_state('binary_sensor.power_usage_745989_available', 'on') %} #this checks if my efergy home measurement sensor is online
                {{(states('sensor.power_usage_745989')|float(0) - expand('group.all_sensors_home_power') |map(attribute='state')|map('float')|sum)|round(2)}}
            {% else %}
                Unavailable
            {% endif %}

What can i do to get rid of the warnings?
Maybe somehow only sum up the sensors that are positive, or available will solve it? (also how would i do that?)

Thank you in advance

Solved it by rejecting the “unavailable” power sensors from the sum.
(Some of my sensors are generated by powercalc, and become unavailable when the equivalent switches are offline)
I added | reject('eq','unavailable') before selecting the floats.
New code now is:

{{(states('sensor.power_usage_745989')|float(0) - expand('group.all_sensors_home_power') |map(attribute='state')| reject('eq','unavailable')|map('float')|sum)|round(2)}}

No more log spam :slight_smile:
Short of a workaround i guess, so i’d gladly listen to any input on better addressing this.

1 Like