[Solved] Script: change brightness of all turned on lamps (in a group)

Hey there,

how can I select only turned on lamps in a script?

I need to create three different brightness and color states and want to apply them only to already turned on lamps.

Found something in this thread:

This is working for me:

# Max Brightness
brightness100:
  alias: Brightness100
  sequence:
  - variables:
      light_entities: '{{ entity_ids }}'
      entities_to_regulate: |
        {{ expand(light_entities) | selectattr('state', 'eq', 'on') | map(attribute='entity_id') | list }}
  - condition: template
    value_template: '{{ entities_to_regulate | count > 0 }}'
  - service: light.turn_on
    data_template:
      entity_id: '{{ entities_to_regulate | join('', '') }}'
    data:
      brightness: 250
      transition: 1.5
call100bright:
  alias: Call 100 Brightness
  sequence:
  - service: script.brightness100
    data:
      entity_ids:
        - light.1
        - light.2
        - light.3
        - light.4
        - light.5