Problem with input_boolean in an automation (discolight)

hello community,

i have a few difficulties completing my script “disco light”.

With the help of many posts here in the forum, I managed to switch my light to “party mode”.

But now I have to specify in the code which lights should be addressed.
Of course i can do it that way, but if I want to determine for myself which lights should be in “party mode”, I have a big problem defining this.

As I have now understood, I need a certain input_boolean so that I can “filter” my lights in the script:

{% for light in states.light %}
{% set a ='input_boolean.'+light.entity_id.split('.')[1] %}   
{%- if is_state( a , 'on') %}
      {{ light.entity_id }}
 {%- endif %}
 {%- endfor %}

however, i don’t know how and where to use this filter …?!?
here you can see the absolutely complex code. maybe a bit gigantic, but it works =)

#-
#  _                   _       _                 _
# (_)_ __  _ __  _   _| |_    | |__   ___   ___ | | ___  __ _ _ __  ___
# | | '_ \| '_ \| | | | __|   | '_ \ / _ \ / _ \| |/ _ \/ _` | '_ \/ __|
# | | | | | |_) | |_| | |_    | |_) | (_) | (_) | |  __/ (_| | | | \__ \
# |_|_| |_| .__/ \__,_|\__|___|_.__/ \___/ \___/|_|\___|\__,_|_| |_|___/
#         |_|            |_____|
#
#-

party:
  name: Partymodus
  icon: mdi:PartyPopper
  initial: off

#-
#               _ _       _
#  _____      _(_) |_ ___| |__   ___  ___
# / __\ \ /\ / / | __/ __| '_ \ / _ \/ __|
# \__ \\ V  V /| | || (__| | | |  __/\__ \
# |___/ \_/\_/ |_|\__\___|_| |_|\___||___/
#
#
#-

switch:
  - platform: template
    switches:
      party:
        value_template: '{{ states("input_boolean.party") }}'
        friendly_name: 'Partymodus'
        turn_on:
          - service: input_boolean.turn_on
            entity_id: input_boolean.party
        turn_off:
          - service: input_boolean.turn_off
            entity_id: input_boolean.party

#-
#                _       _
#  ___  ___ _ __(_)_ __ | |_ ___
# / __|/ __| '__| | '_ \| __/ __|
# \__ \ (__| |  | | |_) | |_\__ \
# |___/\___|_|  |_| .__/ \__|___/
#                 |_|
#
#-

lights_partying_on:
  alias: Lights partying on
  sequence:
  - service: scene.create
    data:
      scene_id: studioprimaparty
      snapshot_entities:
      - light.extended_color_light_2
#     - light.extended_color_light_3
#     - light.extended_color_light_4
#     - light.extended_color_light_5
  - service: script.turn_on
    entity_id: script.lights_partying
  mode: single


lights_partyingv6:
  alias: lights_partyingv6
  sequence:
  - repeat:
      while:
      - condition: state
        entity_id: input_boolean.party
        state: 'on'
      sequence:
      - service: light.turn_on
        target:
          entity_id: light.extended_color_light_2
        data:
          rgb_color:
          - '{{ (range(0, 255)|random) }}'
          - '{{ (range(0, 255)|random) }}'
          - '{{ (range(0, 255)|random) }}'
          brightness: 250
          transition: '{{ (range(1, 3)|random) }}'
#      - service: light.turn_on
#        target:
#          entity_id: light.extended_color_light_3
#        data:
#          rgb_color:
#          - '{{ (range(0, 255)|random) }}'
#          - '{{ (range(0, 255)|random) }}'
#          - '{{ (range(0, 255)|random) }}'
#          brightness: 250
#          transition: '{{ (range(1, 3)|random) }}'          
      - delay: 1
  mode: single

lights_partying_off:
alias: Lights partying off
sequence:
    - service: scene.turn_on
    data:
        entity_id: scene.studioprimaparty

#-
#
#  ___  ___ ___ _ __   ___  ___
# / __|/ __/ _ \ '_ \ / _ \/ __|
# \__ \ (_|  __/ | | |  __/\__ \
# |___/\___\___|_| |_|\___||___/
#
#
#

- id: '1629180743352'
  name: studioprimaparty
  entities:
    input_boolean.party:
      restored: true
      supported_features: 0
      friendly_name: Party ON!
      icon: mdi:party-popper
      state: 'on'

#-
#              _                        _   _
#   __ _ _   _| |_ ___  _ __ ___   __ _| |_(_) ___  _ __  ___
#  / _` | | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __|
# | (_| | |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \
#  \__,_|\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/
#
#
#- 

- alias: 'Lights partying on'
  id: 'Partymodus ON'
  initial_state: true
  trigger:
  - platform: state
    entity_id: input_boolean.party
    from: 'off'
    to: 'on'
  action: 
    service: script.lights_partying_on

- alias: 'Lights partying off'
  id: 'Partymodus OFF'
  initial_state: true
  trigger:
    - platform: state
    entity_id: input_boolean.party
    from: 'on'
    to: 'off'
  action:
    - service: light.turn_off
    entity_id:
        - light.extended_color_light_2
#        - light.extended_color_light_3
#        - light.extended_color_light_4
#        - light.extended_color_light_5
    - delay: 1
    - service: script.lights_partying_off

in the code I have “commented out” some entities (- light.extended_color_light_3, - light.extended_color_light_4, etc…) if I “activate” this here, then all lights are in “party mode”

As I said, I am now looking for a solution to add and remove my lights in the dashboard.

suppose I have 4 lights in party mode.
if I now have to / want to take “Light 3” out of there, I need some way of doing this.

I may need to add all “wanted” entities. and use the “filter” (input_boolean) to remove the ones that should be switched off again

can anyone help me ?