Jinja template for iterating entities and summing an attribute

I’m trying to create a template which will add the values of the current power of each light. I can’t get the map filter to pick up the attribute. Any ideas?

Please don’t post pictures. Post text.

Try:

{{ states.light|map(attribute='attributes.current_power_w')|map('float')|sum }}

Hi there, managed to get it working with

{{states.light|selectattr('attributes.current_power_w')|map(attribute='attributes.current_power_w')|sum}}

As there are some entities which don’t have that attribute. Thanks for the help

1 Like