Dimm lights only if ON

How can I only dimm the lights, that are in the group light.wohnzimmer and are turned on.

service: light.turn_on
target:
  entity_id:
    - {{ expand('light.wohnzimmer') | selectattr('state','eq','on') | map(attribute='name') | list | join('\n- ')  }}
data:
  brightness_step_pct: -25

try this:

service: light.turn_on
target:
  entity_id: >
    {{ expand('light.wohnzimmer') | selectattr('state','eq','on') | map(attribute='entity_id') | list  }}
data:
  brightness_step_pct: -25

you need to create a list, not replicate the yaml text.