When you have a group within a group, is it possible to use the expand function and include the nested group entity but not the entities inside that nested group?
I have a light group that contains multiple light entities and also contains a second light group inside of it which is a group of bulbs. I want to count the lights that are on, but not the individual bulbs. I want that bulb group to be counted as 1.
Using this code, I get a count of each individual bulb which Iām trying to avoid.
{{expand(state_attr('light.master_bedroom_light_group', 'entity_id'))| selectattr('state','eq','on')| map(attribute='entity_id')|list|count}}
I figured I could just reject any entities containing bulb. This excludes the bulbs but doesnāt count the light group they belong to.
{{expand(state_attr('light.master_bedroom_light_group', 'entity_id'))| selectattr('state','eq','on')| rejectattr('entity_id', 'search', '_bulb')| map(attribute='entity_id')|list|count}}
Manually assigning the light entities to a variable does work
{% set lights = [
states.light.master_bedroom_fan_lights,
states.light.closet_light,
states.light.master_bathroom_counter_lights,
states.light.master_bathroom_shower_light,
states.light.master_bathroom_light
] %}
{{ lights | selectattr('state','eq','on') | map(attribute='entity_id')|list|count }}
But doing it this way when I go to implement a whole home light count will be 100+ lines of code and a bit of a pain to update and maintain if anything ever changes.
I feel this may be a limitation to the expand function and I may have no other choice. I figure other people have wanted a count of lights on but donāt want individual bulbs counted so I figured Iād check before manually assigning every light entity in the house to a variable.