How to branch in an automation based on actionable mobile notification?

I would like to have an automation which will send an actionable notification on my android phone when I’m entering in a zone. When I’m clicking on the actionbutton of the notification, then turn on a switch (open the gate).
This is easy so far I did it and it is working well.

I would like to develop this further on the following way. When I’m entering in the zone after 10 second timeout if I’m not clicking on the notification a switch shall be turned on. If I’m clicking on the notification in 10s the switch shall not be switched on. Until now I did not found the solution how to make this branching.

Thank you in advance for your help!

Sounds like clicking the action button is the trigger for a second automation?

The example in the Companion App docs shows how to use a Wait for Trigger with multiple triggers to perform branching logic using a Choose action.

If your goal is just to perform action on timeout but not if the button is pushed you do not need any branching actions like Choose or If/Then. Just use a template condition after the Wait for trigger action.

- condition: template
  value_template: "{{ wait.trigger is none }}"
- service: switch.turn_on
  target:
    entity_id: switch.example

Hello!
You mean like this? (It is not working currently)


wait_for_trigger:
  - platform: event
    event_type: mobile_app_notification_action
    event_data:
      action: CANCELL_AUTO_GATE_OPEN
continue_on_timeout: false
timeout:
  hours: 0
  minutes: 0
  seconds: 10
  milliseconds: 0
  
- condition: template
  value_template: "{{ wait.trigger is none }}"
- service: switch.turn_on
  target:
    entity_id: switch.uszokapu_gate

You need to set continue_on_timeout to true, and make sure your indents are correct:


  - #YOUR NOTIFICATION-RELATED ACTIONS...
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: CANCELL_AUTO_GATE_OPEN
    continue_on_timeout: true
    timeout:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - condition: template
    value_template: "{{ wait.trigger is none }}"
  - service: switch.turn_on
    target:
      entity_id: switch.uszokapu_gate

Thank you! It is working.

1 Like