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: ''
  trigger:
  - entity_id: input_number.test
    platform: state
  action:
  - service: light.turn_on
    data_template:
      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…