AINER
July 2, 2023, 7:02pm
1
I trie to reject some entities in my counter sensor that use lights group. But something is going wrong.
- platform: template
sensors:
count_lights:
friendly_name: "Количество включенных ламп"
value_template: >-
{{ state_attr('light.lights', 'entity_id')
| select('is_state', 'on')
| rejectattr ('entity_id', 'in', [
'light.udlinitel_socket_1',
])
| list | count }}
Dujith
(Charles Evers)
July 2, 2023, 7:38pm
2
What is light.lights
?
I think you are better off with states.light
and making a list for the lights you do not want counted as it make your code simpler to adjust if needed:
{% set exclude_lights = ['light.A', 'light.B', 'light.X'] %}
{{ states.light|selectattr('state','eq','on')|rejectattr('entity_id','in', exclude_lights)|list|count}}
AINER
July 2, 2023, 7:47pm
3
Dujith:
What is light.lights
?
light.lights
is group of lights in single room which include some switches (with helpers) that i want exclude from counter.
123
(Taras)
July 2, 2023, 8:42pm
4
value_template: >-
{{ state_attr('light.lights', 'entity_id')
| select('is_state', 'on')
| reject('in', ['light.udlinitel_socket_1'])
| list | count }}
1 Like