Help with list of entity_id in Data Template

Hello, i’m trying to do this automation, but won’t work.

- id: '1562784314041'
  alias: 0.38Pulsante Luci Veranda OFF
  trigger:
  - entity_id: sensor.0x00158d000200886a_click
    platform: state
    to: double
  condition: []
  action:
  - data_template:
      entity_id: > 
        {% if is_state('sun.sun', 'above_horizon') %} 
          - light.veranda
          - light.veranda_2
          - light.veranda_notte
          - light.veranda_blindata
          - light.veranda_blindata_2
          - light.veranda_blindata_3
        {% else %} 
          - light.veranda
          - light.veranda_2
          - light.veranda_blindata
          - light.veranda_blindata_2
          - light.veranda_blindata_3 
        {% endif %}
    service: light.turn_off

Thanks a lot for your help
Stefano

Would managing as groups be easier perchance?

Probably, i need to now how can i set a group (i can search on the web).
But is not possible without group?
Thanks
Stefano

I would solve this a different way:

- id: '1562784314041'
  alias: 0.38Pulsante Luci Veranda OFF
  trigger:
    - entity_id: sensor.0x00158d000200886a_click
      platform: state
      to: double
  action:
    - data:
        entity_id:
          - light.veranda
          - light.veranda_2
          - light.veranda_notte
          - light.veranda_blindata
          - light.veranda_blindata_2
          - light.veranda_blindata_3
      service: light.turn_off
    - condition: state
      entity_id: sun.sun
      state: 'above_horizon'
    - data:
        entity_id: light.veranda_notte
      service: light.turn_off

Thanksa a lot David!!
Is a really beautiful solution.
Works Perfectly

1 Like

Just to reiterate…

you can’t put a list (denoted by the “-”) in a template. A template can only return a string.

so you could do this and it should work:

action:
  - data_template:
      entity_id: > 
        {% if is_state('sun.sun', 'above_horizon') %} 
          light.veranda, light.veranda_2, light.veranda_notte, light.veranda_blindata, light.veranda_blindata_2, light.veranda_blindata_3
        {% else %} 
          light.veranda, light.veranda_2, light.veranda_blindata, light.veranda_blindata_2, light.veranda_blindata_3 
        {% endif %}
    service: light.turn_off