Exclude entities from count entities template

I am pretty new to home assistant, so please be nice in case this is the wrong category or sth. :slight_smile:

I’m a little bit exhausted here. Hopefully I’m not naively searching for so

### What is my goal ###
I want a dedicated list for exclusions where I filter out all light groups / single bulbs inside a multi bulb lamp / etc. / etc. Therefore I can’t just filter out groups…
This is going to be my approach for all “count active” entities

.
## nice to have ##
each list of exclusions would be in a seperate yaml file for organization purposes.

.
# what I already have #
:arrow_down:This works pretty great!! But returns all unwanted entities as well :arrow_down:

#####
# Count active lights
#####

platform: template
sensors:
  lights_1st_floor:
    friendly_name: 'active lights'
    unique_id: active_lights
    value_template: >
      {%- set search_state = 'on' %}
      {{ states.light
      |selectattr('state','eq',search_state)
      |list|length}}

.
:arrow_down:THIS doesn’t work. Why?? :frowning: :arrow_down:

#####
# Count active lights
#####

platform: template
sensors:
  lights_1st_floor:
    friendly_name: 'active lights'
    unique_id: active_lights
    value_template: >
      {%- set search_state = 'off' %}

      {%- set exclude_search = [
      light.schlafzimmer_1,
      light.schlafzimmer_2,
      light.hue_white_candle_1,
      light.hue_white_candle_2,
      light.alle_lichter,
      ] %}

      {{states.light
      |selectattr('state','eq',search_state)
      |rejectattr('entity_id','eq',exlclude_search)
      |list|length}}

Thanks in advance! :pray:t5:
Greetings from germany

Hi there, were you ever able to get this sorted out? If so, that’s awesome! If not, I may have figured out what was causing the issue. Not 100% sure, but thought I’d reach out, in case.

Greetings from Canada