Brightness of only on light by input number

Trying to make changes of brightness only if light on based on input_number.test slider. The script below is not working, can’t figure why. Any hint please?

- id: testsvetlosti
  alias: 'Světla: Jas'
  description: ''
  - entity_id: input_number.test
    platform: state
  - service: light.turn_on
      entity_id: "{% if is_state('light.mistnost', 'on') %}light.mistnost,{% endif %} 
        {% if is_state('light.postel', 'on') %}light.postel,{% endif %}
        {% if is_state('light.stul', 'on') %}light.stul,{% endif %}"
      brightness: "{{ trigger.to_state.state | int }}"

Solved it by three automations each checking the on state of the particular light. There must be better way…