How to handle actionable notification no response from phone user

Ok, So I made an actionable notification that has a push notification with YES and NO buttons. I can handle they yes and no options if they are pressed but I can’t figure out how to handle the possibility if the timeout finishes and there was no response to the push notification. If the person presses the YES button on the phone, I want to close the door. If the person presses the NO button on the phone, I want to do nothing. IF the person doesn’t press anything, after waiting for 2 minutes, I want to go ahead and close the door. Here is my code. Any help would be greatly appreciated.

  alias: TEST
  description: message tara and ask if she wants to close the garage door 3
  trigger:
  - platform: zone
    entity_id: device_tracker.tara
    zone: zone.near_home
    event: leave
  condition:
  - condition: state
    entity_id: cover.garage_door_2
    state: open
  action:
  - service: notify.mobile_app_pixel_4
    data:
      data:
        actions:
        - action: YESCLOSEGARAGE2
          title: 'Yes'
        - action: NOCLOSEGARAGE2
          title: 'No'
      message: Door is open. Close?
  - wait_for_trigger:
    - platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: YESCLOSEGARAGEDOOR2
    - platform: event
      event_type: mobile_app_notification_action
      event_data:
        action: NOCLOSEGARAGEDOOR2

    timeout:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ wait.trigger.event.data.action == ''YESCLOSEGARAGEDOOR2'' }}'
      sequence:
      - service: mqtt.publish
        data:
          topic: sensor/garage/action2
          payload: CLOSE
    - conditions:
      - condition: template
        value_template: '{{ wait.trigger.event.data.action == ''NOCLOSEGARAGEDOOR2'' }}'
      sequence:
      - service: mqtt.publish
        data:
          topic: sensor/garage/action2
          payload: #how to say Dont Do anything?
#need something here if I don't get an answer within 2 min like:
    - conditions:
      - condition: template
        value_template: '{{ wait.trigger.event.data.action == "none" }}'
      sequence:
      - service: mqtt.publish
        data:
          topic: sensor/garage/action2
          payload: CLOSE
1 Like

Did you ever find a solution to this?

I am running into the same problem, but for me it’s compounded because I call the actionable notfication script from inside a second automation (i.e. an action in the first automation triggers another automation that contains the actionable notification script). If I do not respond, the originating automation hangs and never completes. I guess I can switch modes on both automations to “restart”, but I would like to know if there is a way to directly deal with a non-response.

You need to run your actions in parallel.
For example on my door lock notify automation, if the front door is unlocked I have the notification fire after 5 minutes. In 10 minutes if there is no response, I have the door lock and the notification clear.

alias: "Notify - Front Door Unlocked"
description: ""
trigger:
  - platform: state
    entity_id:
      - lock.front_door_lock
    to: unlocked
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - alias: Set up variables for the actions
    variables:
      action_ignore: "{{ 'IGNORE_' ~ context.id }}"
      action_lock: "{{ 'LOCK_' ~ context.id }}"
  - alias: Ask Nick to Lock the Front Door
    service: notify.mobile_app_pixel_7
    data:
      message: Front Door Unlocked. Do you want to lock it?
      data:
        persistent: true
        tag: fd_unlocked
        actions:
          - action: "{{ action_ignore }}"
            title: IGNORE
          - action: "{{ action_lock }}"
            title: LOCK
      title: Front Door Unlocked
  - parallel:
      - sequence:
          - alias: Wait for a response
            wait_for_trigger:
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ action_ignore }}"
              - platform: event
                event_type: mobile_app_notification_action
                event_data:
                  action: "{{ action_lock }}"
          - alias: Perform the action
            choose:
              - conditions: "{{ wait.trigger.event.data.action == action_ignore }}"
                sequence:
                  - service: notify.mobile_app_pixel_7
                    data:
                      message: clear_notification
                      data:
                        tag: fd_unlocked
              - conditions: "{{ wait.trigger.event.data.action == action_lock }}"
                sequence:
                  - service: lock.lock
                    data: {}
                    target:
                      device_id: f67dffda2183afc3d7945e4990cccae4
      - sequence:
          - delay:
              hours: 0
              minutes: 10
              seconds: 0
              milliseconds: 0
          - service: lock.lock
            data: {}
            target:
              entity_id: lock.front_door_lock
          - service: notify.mobile_app_pixel_7
            data:
              message: clear_notification
              data:
                tag: fd_unlocked
mode: single

1 Like