Multiple entity_id on data_template

I have been using this automation prior to 0.60 and they’ve been working. I couldn’t turn toggle two entities (last condition, else). I’ve tried using two lines with hyphen, and putting space after the comma but it wouldn’t work.
I’ve verified nothing is wrong on my config by using services development tool, jinja dev tool as well as removing one entity id.

  action:
   - service: homeassistant.toggle
#     entity_id: light.garage
     data_template:
      entity_id: >
       {% if is_state("light.frontgate", "off") and is_state("light.garage", "off") and is_state("light.garage2", "off") %}
        light.frontgate
       {% elif is_state("light.frontgate", "on") and is_state("light.garage", "off") and is_state("light.garage2", "off") %} 
        light.garage
       {% elif is_state("light.frontgate", "on") and is_state("light.garage", "on")  and is_state("light.garage2", "off") %} 
        light.garage2
       {% elif is_state("light.frontgate", "on") and is_state("light.garage", "on")  and is_state("light.garage2", "on") %} 
        light.frontgate
       {% elif is_state("light.frontgate", "off") and is_state("light.garage", "on")  and is_state("light.garage2", "on") %} 
        light.garage
       {% else %}
        light.garage2
       {% endif %}

Any help? Thanks!

Ignore me, it’s too early for me to read apparently :stuck_out_tongue_winking_eye:

You need to verify that the if lines exclusively report true. I mean if for some reason 2 of the “condition lines” report true at the same time, neither entity_id gets through.
Check all lines in dev_tools to see only one turns true at a given time.

This is not the problem. I just realized, i posted the wrong config, it should have been:

 service: homeassistant.toggle
 data_template:
  entity_id: >
   {% if is_state("light.frontgate", "off") and is_state("light.garage", "off") and is_state("light.garage2", "off") %}
    light.frontgate
   {% else %}
    light.garage,light.garage2
   {% endif %}

where if falls under else, light.garage and light.garage2 doesn’t toggle. it worked before.

There’s a coma after garage,?

yes. comma between the two entities, without space. i already tried putting them into two lines, with or without hyphen but it doesn’t work.

Exactly, I don’t think that’s possible. You can not get 2 entities through. Only one
I have the same issue.

My work around is to repeat the whole section including the second entity. Not pretty but does the job

yeah it was working before around 0.52 - 0.58. that’s what i did too, really messy.

Hi @accelle - did you ever get this to work or did you end up using a workaround?

why use homeassistant.toggle and not just light.turn_on?
No need for the data_template and just turn on all lights even though they are already on?

End up using the workaround mentioned

Trying to revive this, since I cant get it to work.

I want to use this:

service: switch.turn_on
target:
  entity_id:
    - switch.baksidan_clips
    - switch.baksidan_detect

but, using templates, like this:

      entity_id: |
        {%- if trigger.event is search("deactivate_clips.*front_door") %}
            - switch.front_door_clips
            - switch.front_door_detect
        {%- elif trigger.event is search("deactivate_clips.*baksidan") %}
            - switch.baksidan_clips
            - switch.baksidan_clips
        {%- else %}
          false
        {%- endif -%}

But for the life of me, I cant get the system to accept my templates.

Pasting my template into dev ==> templates, everthing looks fine! But log complains with:

Template rendered invalid entity IDs: - switch.front_door_clips

Any ideas?

I had a similar problem, and did a lot of experimentation with data_template.

For some (if not most) services, you could specify multiple entity_id’s, but it must be a comma separated list, and it must not have trailing commas.

The following is what finally worked after hours of experimentation.

service: input_select.select_option
data_template:
  entity_id: >-
    {{ states | selectattr('state', 'match', 'state_to_match')
                    | map(attribute='entity_id')
                    | list
                    | join(', ') }}
  option: state_to_set