Is it possible to conditionally execute an action within a list of actions?

I have a list of actions in an automation.

action:
  - service 1
  - service 2
  - service 3

Is it possible to conditionally execute service 2, e.g. skip the execution of service 2 depending on a condition?

Yes. See the Choose action.

I am getting an error in the line using “conditions:” “mapping values are not allowed here”. Note that this is in a blueprint.

action:
  - service: camera.snapshot
    target:
      entity_id: !input 'motion_camera'
    data:
      filename: '{{ folder }}{{ filename }}'
  - choose:
      - alias "If e-mail notification is enabled send e-mail notification"
        conditions: 
          - '{{ notify_email }}'
        sequence:
          - service: script.email_snapshot
            data:
              snapshot_target: !input email
              snapshot_title: '{{ title }}'
              snapshot_message: '{{ message }}'
              snapshot_file: '{{ folder }}{{ filename }}'

You are missing the colon after - alias.

1 Like

I am embarrassed. “choose” works perfectly now. Thanks Tom.