Control only on active lights

hey,
I don’t succeed to create a group or sth similar, that I can for example to control only the brigthness of active lights in specific room.

how can I achieve it?

thanks!

Something like this:

- service: light.turn_on
  target:
    entity_id: >
      {{ expand(area_entities("living room"))|selectattr('domain', 'eq', 'light')|selectattr('state', 'eq', 'on')|list }}
  data:
    brightness: 42

Note: that entity_id template has no test for the case where no lights are on so it would generate an error if you tried to use it there. Can this happen?

Or will there always be lights on when you use it?

I have slider of brightness and color.
I want to change the this depand only to the lights that are on.