Creating template sensor based on "tagging" or "custom properties" on devices and/or sensors

Hi

I’m trying to create custom sensors that contains the sum of current power for groups of devices. Typically the total current power usage for all dimmers in the house, another for all devices in the basement, another for appliances.

I’ve managed to find all sensors that are power sensors and that are currently drawing power and calculating the sum like this.

{% set ns = namespace(states=[]) %}
{%- for state in states.sensor %}
  {%-set mytype = state.attributes.device_class%}
  {%- if mytype == 'power' and state.state != '0.0' %} 
    {% set ns.states = ns.states + [ state.state | float ] %}
    test: {{ state.name | lower }} is {{state.state_with_unit}} : {{ state.object_id }} {% endif -%}
{%- endfor %}
Total {{ ns.states | sum | round(1) }}

Now, what I’d really like is be able to “tag” devices (or sensors) so I can filter my total sensor based on some sort of “tag” or “custom property”. Something like so:

{%- if mytype == 'power' and state.state != '0.0' and some.property = 'true' %}

Any ideas or thoughts on how to best do that, if at all possible?

Thanks for any help :slight_smile:

You can add custom attributes to an entity.