#Adding values from sensors by label

1 messages · Page 1 of 1 (latest)

violet saffron
#

Just sharing a success story. Hopefully someone will find it useful.

I have been using a template sensor to add the power usage values of multiple devices.

I have found the most streamlined way to set this up and easily maintain it when devices are added or removed.

I have a label called "monitored_power" that is applied to all power entities that are part of this calculation.
Then this template sensor is used to add them up, leaving out any that are offline.

{{ 
  label_entities('monitored_power')
    | map('states', 0) 
    | reject('search','unknown|unavailable') 
    | map('float') 
    | sum 
    | round(2, 'common') 
}}```
pine mural
#

I would do it like this

{{
  label_entities('monitored_power')
    | select('has_value')
    | map('states')
    | map('float')
    | sum
    | round(2)
}}
violet saffron
proud karma
#

If you have a properly configured numeric sensor, it is not possible for it to have an state that is not numeric and neither unknown or unavailable

violet saffron
#

so, same function, but a bit tidier.