I recently created light entities out of shelly switches and while i was at it I created light groups of those newly created light entities as well as existing light entities. I’m looking for a way to count total lights on per light group. I’ve seen posts on using if statements and manually adding each entity which defeats the purpose of my newly created light groups, same way expanding a standard group wont work as i did not make these standard groups.
I saw this code to expand a light group and it works great at expanding the light group
This is code I found to expand a standard group and get count of on state ,which appears to work.
{{ expand('group.davidsroom') | selectattr('state', 'eq', 'on') | list }}
I tried the below as a merge of both lines above but clearly I dont know if its meant to work or I’m missing anything. Code doesn’t error, it does return the list of entities in developer tools template but it does not give me a count (always shows 0)
Tom thanks for your help. This works quite well. Is there a code to define specific open light entity name? With this code I can only get total numbers.
action:
- service: notify.telegrambot
data:
message: >
Evden Ayrıldın ama {{expand(state_attr('group.allhouse', 'entity_id'))|
selectattr('state','eq','on')|map(attribute='entity_id')|list|count}}
ışık açık
mode: single
The above code gives me the total number of lights whos state is on. I would like to know if we can change it as it can exactly state the name of the identity whic is currently on. For example a message like “Corridor hue light is open”.
totally forgot to reply. I got so excited when I tested and it worked that I just went into why I needed this. Thanks a lot. Worked perfect first time.