How to perform the an action at the even if timeout occured before?

Dear all,
I have an automation that is triggered once somebody pressed the doorbell button. The following amin steps are performed:

  • Take snapshot of doorbell camera
  • Change suveillance camera’s angle to look at the entrance door
  • Send image to my smartphone along with an actionable notification.
  • Set the wait-for-trigger statement to 30 seconds to make a selection (e.g. open door or go to dashboard).

If there is no selection within 30 seconds, there’s a timeout and the script stops.
However, what I want to do in any case - regardless of timeout or trigger was received - is to change the camera back to another position after 2 minutes.

The problem is that after the timeout, the script does reach the second “change-camera-angle”. The camera keeps pointing at the entrace door.

Here is the yaml code

alias: doorbell_button_pressed
sequence:
  - target:
      entity_id: camera.g8t1_tv02_3155_0j71
    data: {}
    action: blink.trigger_camera
  - action: select.select_option
    metadata: {}
    data:
      option: Gate Person
    target:
      entity_id: select.tapo_c210_einfahrt_move_to_preset
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 100
  - data: {}
    target:
      entity_id: camera.g8t1_tv02_3155_0j71
    action: homeassistant.update_entity
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 100
  - target:
      entity_id: camera.g8t1_tv02_3155_0j71
    data:
      filename: >-
        /media/blink_doorbell_image/{{ now().strftime("%Y-%m-%d")
        }}/tuerklingel_{{ now().strftime("%Y-%m-%d-%H%M") }}.jpg
    action: camera.snapshot
  - data:
      message: Someone is at the door
      title: Doorbell button pressed
      data:
        ttl: 0
        priority: high
        channel: Doorbell
        image: /api/camera_proxy/camera.g8t1_tv02_3155_0j71
        actions:
          - action: OPEN_DOOR
            title: Open door
          - action: URI
            title: Open Blink App
            uri: app://com.immediasemi.android.blink
          - action: URI
            title: Open Dashboard
            uri: /lovelace/default_view
    enabled: true
    action: notify.all_devices
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: OPEN_DOOR
    timeout:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
    continue_on_timeout: false
  - metadata: {}
    data: {}
    target:
      entity_id: switch.toroeffner_switch_0
    action: switch.toggle
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 100
  - action: select.select_option
    metadata: {}
    data:
      option: Garage
    target:
      entity_id: select.tapo_c210_einfahrt_move_to_preset
mode: single
icon: mdi:doorbell-video

Can you advise please ?

You told it to stop on timeout:

Change that to

continue_on_timeout: true

If you do not want the switch toggled after a timeout you will need to use an if action that check to see it the timeout occurred or not. (wait.completed == false means it timed out, true means the trigger occured), see: https://www.home-assistant.io/docs/scripts#wait-variable

Hi Tom,
thanks for guding me.
I tried your solution as follows:

...
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: OPEN_DOOR
    timeout:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    continue_on_timeout: true
  - if:
      - condition: template
        value_template: "{{ wait.completed == true}}"
    then:
      - action: switch.toggle
        metadata: {}
        data: {}
        target:
          entity_id: switch.toroeffner_switch_0
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 100
  - action: select.select_option
    metadata: {}
    data:
      option: Garage
    target:
      entity_id: select.tapo_c210_einfahrt_move_to_preset
mode: single

The problem is that the condition always evaluates to false regardless of if I press open door in the actionalbe notification or not. I allso tried {{ wait.completed == false}} and {{ wait.completed }} and {{ not wait.completed}}.
Either the door opener is always triggered or never. Once again, there is no effect of pressing “open door” in the push notification of the actionable notification

Hmm. There are a couple of other templates you could try (shown in template condition shorthand) here: How can i handle exit from wait_for_trigger function? - #2 by tom_l

Edit: yeah you’ll have to use one of those two templates. As on closer inspection the wait.completed variable is only available for wait templates, not wait for trigger templates. Sorry for misleading you.

https://www.home-assistant.io/docs/scripts#wait-variable

Screenshot 2024-09-06 at 20-53-25 Script Syntax - Home Assistant

So either:

  - if:
      - condition: template
        value_template: "{{ wait.remaining == 0 }}"

or

  - if:
      - condition: template
        value_template: "{{ wait.trigger == none }}"

Thanks, the second snippet works like a charm.
I also tried the first one with remaining == 0 and remaining !=0, but it didn’t work.

Anyways, I am Happy with the second solution. Thanks for helping

1 Like