Actionable notification on phone - auto-clear notification

Hi,
I am trying to create an actionable notification for my garage door. I want it to trigger when the door is open with an option to close it in the notification. I also want the notification to disappear automatically when the door is closed because the notification and option to close the door is now not needed.

I have a working automation but it only works if I put mode: parallel. I believe this is because once the notification is created, the automation will wait forever at “wait_for_trigger” and wait until the button in the notification is pressed. Simply adding a trigger id in the trigger section to clear the notification (the code is there, but it is disabled in this code example) will trigger a new instance of the automation to run (because mode=parallel) and correctly clear the notification but the original automation will still be stuck at “wait_for_trigger”. To help solve this, I added a second trigger to the “wait_for_trigger” so that it can trigger on the garage door closing. This however does not seem to work.

Can someone help suggest what I need to fix or maybe suggest a way that I do not need to set the mode to parallel. Allowing for parallel runs and enabling the original trigger for closed seems to suggest that it is possible to continually create orphaned automations until we reach 10 (setting this to a higher number would solve the issue but that doesn’t seem like a great idea)

alias: Phone - Door/Garage Notifications
triggers:
  - entity_id:
      - cover.garage_door_1
    to: closed
    id: garage_1_closed
    trigger: state
    enabled: false
  - entity_id:
      - cover.garage_door_1
    to: open
    id: garage_1_open
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - garage_1_closed
        sequence:
          - data:
              message: clear_notification
              data:
                tag: garage_1_open
            action: notify.mobile_app_pixel8_phone
      - conditions:
          - condition: trigger
            id:
              - garage_1_open
        sequence:
          - variables:
              action_close_garage_1: "{{ 'CLOSE_GARAGE_DOOR_1' ~ context.id }}"
          - action: notify.mobile_app_pixel8_phone
            data:
              message: Van Garage is Open
              data:
                tag: garage_1_open
                ttl: 0
                priority: high
                actions:
                  - action: "{{ action_close_garage_1 }}"
                    title: Close Garage Door
          - wait_for_trigger:
              - event_type: mobile_app_notification_action
                event_data:
                  action: "{{ action_close_garage_1 }}"
                trigger: event
              - trigger: state
                entity_id:
                  - cover.garage_door_1
                to: closed
                id: garage_1_closed_with_notification_on
          - choose:
              - conditions:
                  - condition: template
                    value_template: >-
                      {{ wait.trigger.event.data.action == action_close_garage_1
                      }}
                sequence:
                  - action: cover.close_cover
                    target:
                      entity_id: cover.garage_door_1
                    data: {}
              - conditions:
                  - condition: trigger
                    id: garage_1_closed_with_notification_on
                sequence:
                  - action: notify.mobile_app_pixel8_phone
                    metadata: {}
                    data:
                      message: clear_notification
                      data:
                        tag: garage_1_open

mode: parallel
max: 10

The Trigger condition only reads the main trigger, it does not have access to the triggers from the Wait for Trigger action… you will need to use a Template condition to check the Wait’s trigger ID:

- condition: template
  value_template: >-
    {{ wait.trigger.id == 'garage_1_closed_with_notification_on'}}

“Restart” may be a more appropriate mode than “Parallel” since that would automatically close out the waiting “open” automation when the cover’s state changes to “closed”, so you could eliminate the entire second trigger and branched actions in the wait.

alias: Phone - Door/Garage Notifications
triggers:
  - entity_id:
      - cover.garage_door_1
    to: closed
    id: garage_1_closed
    trigger: state
    enabled: false
  - entity_id:
      - cover.garage_door_1
    to: open
    id: garage_1_open
    trigger: state
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - garage_1_open
        sequence:
          - variables:
              action_close_garage_1: "{{ 'CLOSE_GARAGE_DOOR_1' ~ context.id }}"
          - action: notify.mobile_app_pixel8_phone
            data:
              message: Van Garage is Open
              data:
                tag: garage_1_open
                ttl: 0
                priority: high
                actions:
                  - action: "{{ action_close_garage_1 }}"
                    title: Close Garage Door
          - wait_for_trigger:
              - event_type: mobile_app_notification_action
                event_data:
                  action: "{{ action_close_garage_1 }}"
                trigger: event
          - action: cover.close_cover
            target:
              entity_id: cover.garage_door_1
            data: {}
    default:
      - action: notify.mobile_app_pixel8_phone
        metadata: {}
        data:
          message: clear_notification
          data:
            tag: garage_1_open
mode: restart

Thanks!! that was perfect!! It works now. Adding the value_template for the trigger id worked for me.

Actually I can’t use “restart”. I took out some code to simply the example. I use a single automation for my locks and garage doors. The trigger id has made it much easier to combine many of my automations into one so it is much easier to maintain. I want separate notifications for when my garage door and my front doors are unlocked. At the very least, i need to enable at least 4 parallel notifications.

Thanks again for the help!