Same trigger for several conditions/actions

Hi guys,

Does anyone know if it’s possible to have 1 trigger to do different actions according to their conditions?
Something like this:

- alias: Do stuff when someone rings the doorbell
  trigger:
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_xxxx
        click_type: single
  action:
    - service: shell_command.get_entrance_image
    - service: notify.slack_general
      data:
        message: "Ding Dong! Someone just rang the doorbell!"
    - delay:
        seconds: 5
    - service: shell_command.send_doorbell_image_to_slack
  condition:
    condition: state
    entity_id: device_tracker.living_room_tv
    state: home
  action:
    - service: scene.turn_on
      entity_id: scene.play_entrance_camera_to_tv

So basically always send a slack notification/image when someone rings the bell BUT if the tv is on, also send the image to the TV.
I know I can duplicate the trigger and it works but I hate to duplicate so many things all over the place.

Thanks

You can put a condition inside your action block. If an action reaches a condition that tests false, then it stops. So put all of the stuff you want to happen every time at the beginning of the action, put in the condition, then finish with the the thing you only want when TV is on: (not 100% sure if I’ve got the condition expressed right, but you get the idea…)

  action:
    - service: shell_command.get_entrance_image
    - service: notify.slack_general
      data:
        message: "Ding Dong! Someone just rang the doorbell!"
    - delay:
        seconds: 5
    - service: shell_command.send_doorbell_image_to_slack

    # action stops if this is false
    - condition: state
      entity_id: device_tracker.living_room_tv
      state: home
  
    - service: scene.turn_on
      entity_id: scene.play_entrance_camera_to_tv

That is cool, does that condition also work with and/or? ex:

...
- condition: and
    condition: state
    entity_id: some.entity
...

It’ll work with any valid condition. I have it set up both as a single condition and as a group of and-ed conditions in my configuration.

1 Like