GleDel
(Gle Del)
September 27, 2021, 4:32pm
1
Hello,
I am trying to count the individual lights that are on in my house without including deconz_groups or other groups.
I figured out how to count all lights. But groups are still included. Anyone figured this out already?
- platform: template
sensors:
count_lights_on:
friendly_name: 'Totaal aantal lampen aan'
value_template: "{{ states.light | selectattr( 'state', 'eq', 'on') | list | count }}"
The deconz groups can be identified by “is_deconz_group: true”. Not sure how to detect light goup templates.
123
(Taras)
September 27, 2021, 4:55pm
2
- platform: template
sensors:
count_lights_on:
friendly_name: 'Totaal aantal lampen aan'
value_template: "{{ states.light | rejectattr('attributes.is_deconz_group', 'eq', true) | selectattr('state', 'eq', 'on') | list | count }}"
2 Likes
GleDel
(Gle Del)
September 27, 2021, 5:16pm
3
This does filter out the deconz groups! Thank you for that!
Any idea on how to also filter out template light groups?
light:
- platform: group
name: Rail
entities:
- light.rail_1
- light.rail_2
- light.rail_3
- light.rail_4
- light.rail_5
123
(Taras)
September 27, 2021, 6:58pm
4
A Light Group entity has an attribute called entity_id so we can reject any light entity that has this attribute defined.
- platform: template
sensors:
count_lights_on:
friendly_name: 'Totaal aantal lampen aan'
value_template: >
{{ states.light
| rejectattr('attributes.is_deconz_group', 'eq', true)
| rejectattr('attributes.entity_id', 'defined')
| selectattr('state', 'eq', 'on')
| list | count }}
10 Likes
jo-jo
(Jo-Jo Homburg)
May 6, 2022, 1:15pm
6
- platform: template
sensors:
count_lights_on:
friendly_name: "Totaal aantal lampen aan"
value_template: "{{ states.light | rejectattr('attributes.is_Purifier_leds', 'eq', true) | selectattr('state', 'eq', 'on') | list | count }}"
I tried this also with my own settings (Purifier_leds)
But everytime when i add this in my configuration.yaml it says that i am not able to restart home assistant any more...
I just want to have a counter with all my light entities. But i am reading multiple solutions in the same value_template.
And mine are not working.
Probleem tijdens het herstarten van Home Assistant
argument of type 'NoneType' is not iterable
I feel i am doing something dumb because i don't understand those value_template stuff.
pedolsky
(Pedolsky)
May 6, 2022, 2:46pm
7
Would you be so kind and copy the code (not a picture) into the code editor here by using the </> button?
pedolsky
(Pedolsky)
May 9, 2022, 4:28pm
9
Thank you (I wasn’t sure if you had the right quotes in it). The indendation is wrong, it has to be like that:
- platform: template
sensors:
count_lights_on:
friendly_name: "Totaal aantal lampen aan"
value_template: "{{ states.light | rejectattr('attributes.is_Purifier_leds', 'eq', true) | selectattr('state', 'eq', 'on') | list | count }}"
jo-jo
(Jo-Jo Homburg)
May 9, 2022, 10:04pm
10
it does count all lights.
But somehow the exclusion for purifier_leds are not working or not used to count off the total. What is wrong.
pedolsky
(Pedolsky)
May 9, 2022, 10:26pm
11
Check the spelling in Developer Tools - States.
I’m trying to make this work not counting the hue groups. Hoping this was simular as the deconz_groups.
When I try the code given below in the developer tools i get
'UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'is_hue_group' Does anyone has an idea?
- platform: template
sensors:
count_lights_on:
friendly_name: 'Totaal aantal lampen aan'
value_template: >
{{ states.light
| rejectattr('attributes.is_hue_group', 'eq', true)
| selectattr('state', 'eq', 'on')
| list | count }}
pedolsky
(Pedolsky)
November 27, 2022, 10:29am
13
value_template: >
{{ states.light
| rejectattr('attributes.is_hue_group', 'defined')
| selectattr('state', 'eq', 'on')
| list | count }}
1 Like
I’m trying to set up this with Z2M light groups. Unfortunately, the entities don’t include such an attribute like ‘light’ or ‘…group’.
Is there a way to get the attribute set by z2m or is there another way to exclude such z2m light groups from counting?
Edit:
Never mind… just noticed, that (light) groups don’t have the attribute ‘linkquality’. So I can check against this
1 Like
jeleniain
(Jeleniain)
September 8, 2023, 11:36am
16
Any chance you can tell me how you did it? I am also running into the issue that my z2m light groups are counted. Thanks!