Reject entity in group

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 }}

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}}

light.lights is group of lights in single room which include some switches (with helpers) that i want exclude from counter.

      value_template: >-
        {{ state_attr('light.lights', 'entity_id') 
          | select('is_state', 'on')
          | reject('in', ['light.udlinitel_socket_1'])
          | list | count }}
1 Like