I’'m working on a template to return only lights groups added to particular areas, but the list includes only it’s members, what is the best way to return groups only?
There’s probably a better way… but this should work:
{% set lights = ['home_external_ligts_groups', 'tarrace']
| map('area_entities')
| sum(start=[])
| select('match', 'light.')
| list %}
{{ states.light
| selectattr('attributes.entity_id', 'defined')
| selectattr('entity_id', 'in', lights)
| map(attribute='entity_id')
| list }}
Option 2:
{% set groups = states.light
| selectattr('attributes.entity_id', 'defined')
| map(attribute='entity_id') | list %}
{{ groups | select('in', area_entities('home_external_ligts_groups')) | list
+ groups | select('in', area_entities('tarrace')) | list }}
Your screenshot indicates that you have adopted the convention of adding “_group” to the names of your light groups. You can use that to extract all light groups by name.
{% set lights = ['home_external_ligts_groups', 'tarrace'] |
map('area_entities') |
sum(start=[]) |
select('search', '^light.*_group$') |
list %}
{{ lights}}