Run automations based on if/else

Hi
I am trying to change the following behaviour at sunrise:

alias: "Sunrise all lights off"
trigger:
  platform: sun
  event: sunrise
  # offset: "-00:45:00"
action:
  - service: homeassistant.turn_off
    entity_id:
      - group.all_lights
  - service: shell_command.ss_disarm

This turns off my security lights and disarms my CCTV at sunrise. However, what I would like is to NOT disarm the CCTV when input_boolean.vacation_mode is ON, ie I am on vacation.

How can I use an if/else loop within the action? I am confused from the various advice on the forums.

Thanks

Check conditions:

Surely that is a condition for the entire automation, not just my last action. I still want the lights off at sunrise no matter what.

action:
  - service: homeassistant.turn_off
    entity_id:
      - group.all_lights
  - service_template: >-
           {% if states.input_boolean.vacation_mode.state != "on" %}
              shell_command.ss_disarm
           {%endif%}
1 Like

thanks! will give it a go

don’t use @Odianosen25’s suggestion. Whenever the if statement {% if states.input_boolean.vacation_mode.state != "on" %} resolves to false, you will get an error in home assistant.

Use this:

action:
  - service: homeassistant.turn_off
    entity_id:
      - group.all_lights
  - condition: template
    value_template: "{{ is_state('input_boolean.vacation_mode', 'off') }}"
  - service: shell_command.ss_disarm

everything after the condition will not run if the condition is not met.

1 Like

Ah OK. Didn’t know you could escape out of a action like that :slight_smile: thanks