@tbloth, I have the template below for calculating total light power based on the template sensor above, my naming convention of sensor.*light_power
or sensor.*lamp_power
, and inspiration from this post.
- platform: template
sensors:
sum_power_consumption_lights:
friendly_name: "Total Light Power Consumption"
unit_of_measurement: 'W'
icon_template: mdi:home-lightbulb-outline
value_template: >
{%- macro wildcard(entity_ids, select1, select2) %}
{%- for entity_id in entity_ids %}
{% set state_value = states(entity_id) %}
{%- if select1 in entity_id or select2 in entity_id %}
{{- state_value }}{{ '' if loop.last else ',' }}
{%- endif %}
{%- endfor %}
{%- endmacro %}
{% set entity_ids = states.sensor | selectattr('attributes.device_class', '==', 'power') | map(attribute='entity_id') %}
{{ wildcard(entity_ids, 'light_power','lamp_power').split(',') | map('float') | sum | round(2) }}