ehu156
December 27, 2024, 12:46pm
1
Hi - I want to count how many lights are on in an area, e.g. kitchen. I have created the following helper template yaml but struggling to limit it to areas?
Thanks in advance
{{ states.light | rejectattr('attributes.entity_id', 'defined') | selectattr('state', 'eq', 'on') | list | count }}
petro
(Petro)
December 27, 2024, 12:57pm
2
"{{ area_entities('the area') | select('search', '^light.') | select('is_state','on') | list | count }}"
ehu156
December 27, 2024, 1:04pm
3
Super quick reply - so thank you! What if I want to exclude certain items? Also does this work for floors (which have multiple areas)?
Thanks so much!!!
petro
(Petro)
December 27, 2024, 1:05pm
4
it does not work with floors. If you want to exclude things, use reject.
ehu156
December 27, 2024, 1:09pm
5
Thanks - this seems to work but I noticed when I turned some lights on (after having no lights on) it counted more than one going on and then when I turned off it had these phantom count as still showing up. Thoughts?
petro
(Petro)
December 27, 2024, 1:09pm
6
You likely need to remove your grouped lights using reject
ehu156
December 27, 2024, 3:18pm
8
I tried this
{{
area_entities(‘kitchen’) | select(‘search’, ‘^light.’) | rejectattr(‘entity_id’, ‘search’, ‘light.all_kitchen’) | select(‘is_state’,‘on’) | list | count }}
But I am getting ‘str object’ has no attribute ‘entity_id’’ error. Do you know why?
Thanks (And apologies)
petro
(Petro)
December 27, 2024, 6:21pm
10
{{ area_entities('the area') | select('search', '^light.') | reject('eq','light.all_kitchen') | select('is_state','on') | list | count }}
ehu156
December 29, 2024, 9:14am
11
thank you @petro and @10der
1 Like