Multiple actions inside IF - Automation

Hello again!

Sorry to bother you, but I’m having some difficulties using automation.

I would like to trigger multiple actions inside a “service_template”, is that possible?

This is my YAML:

- alias: Garagem MuvRH
  trigger:
    - platform: state
      entity_id: input_boolean.entrar_muvrh
      from: 'off'
      to: 'on'
    - platform: state
      entity_id: input_boolean.sair_muvrh
      from: 'off'
      to: 'on'
  action:
    - service_template: >
        {% if is_state('input_boolean.entrar_muvrh', 'on') %}
          script.garagem_muvrh_rua
        - delay: 00:00:02
        - service: script.garagem_muvrh_interno
        - delay: 00:00:10
        - service: script.garagem_muvrh_rua
        - delay: 00:00:05
        - service: script.garagem_muvrh_interno
        - service: input_boolean.turn_off
          entity_id: input_boolean.entrar_muvrh
        {% elif is_state('input_boolean.sair_muvrh', 'on') %}
          script.garagem_muvrh_interno
        - delay: 00:00:02
        - service: script.garagem_muvrh_rua
        - delay: 00:00:10
        - service: script.garagem_muvrh_interno
        - delay: 00:00:05
        - service: script.garagem_muvrh_rua
        - service: input_boolean.turn_off
          entity_id: input_boolean.sair_muvrh
        {% endif %}

I get this error on the logs:

2017-08-25 11:06:05 ERROR (MainThread) [homeassistant.helpers.service] Template rendered invalid service: script.garagem_muvrh_interno
- delay: 00:00:02 - service: script.garagem_muvrh_rua - delay: 00:00:10 - service: script.garagem_muvrh_interno - delay: 00:00:05 - service: script.garagem_muvrh_rua - service: input_boolean.turn_off
  entity_id: input_boolean.sair_muvrh

Basiccly this is an automation to trigger when I switch a specific template boolean and the automation analyses which one is triggered and perform a multiple actions (IFS).

Can someone help me?

Thanks a lot folks!

Changing my answer because I didn’t see the “ELSE” in your automation.

I think the easiest way to do this is to make two scripts. Then, you would call one or the other in your automation like this:

service_template: >
 {% if is_state(‘input_boolean.entrar_muvrh’, ‘on’) %}
    script.script1
  {% else %}
    script.script2
  {% endif %}
1 Like

This is the method that I use. It’s simple and reliable.

1 Like

Thanks guys! I will give it a try.