Automation action conditional statement

I have this automation which is run after HA has been rebooted:

automation:
- alias: enable_camera_after_reboot
  trigger:
  - platform: homeassistant
    event: start
  condition: []
  action:
  - service: script.turn_on_frontcam_recordings

In the action section, how do I add second service, but with conditional statement. Something like this:

  action:
  - service: script.turn_on_frontcam_recordings
  - if input_boolean.securemode == 'on' {
    - service: script.turn_on_backcam_recordings
    } else {
    - service: script.turn_off_backcam_recordings
    }

You could use the if/then action after your existing action.

action:
  - service: script.turn_on_frontcam_recordings
  - if:
      - condition: state
        entity_id: input_boolean.securemode
        state: 'on'
    then:
      - service: script.turn_on_backcam_recordings
    else:
      - service: script.turn_off_backcam_recordings

https://www.home-assistant.io/docs/scripts/#if-then

1 Like