Automation trigger is not triggering

Hello all. I’m a little new to the template language so any help would be appreciated. I have an automation that mostly works. It sends a notification when one of two garage doors is left open with actions. The part that doesn’t work is supposed to clear the notification if only the triggering door is closed manually. That’s the part that doesn’t trigger. Thanks!

alias: Garage Door Timer
description: Actionable notification for garage door left open
trigger:
  - platform: state
    entity_id:
      - cover.garage_door_1
    to: open
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: state
    entity_id:
      - cover.garage_door_2
    to: open
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - alias: Set up action variables
    variables:
      action_close: "{{ 'CLOSE_' ~ context.id }}"
      action_ignore: "{{ 'IGNORE_' ~ context.id }}"
  - alias: Send the notification
    service: notify.mobile_app_alex_iphone
    data:
      message: >-
        {{ trigger.from_state.attributes.friendly_name }} has been open for 10
        minutes. Would you like to close it?
      title: Garage Door
      data:
        tag: doorleftopen
        actions:
          - action: "{{ action_close }}"
            title: Close
          - action: "{{ action_ignore }}"
            title: Ignore
          - action: URI
            title: Security Dash
            uri: /dashboard-homeview/security
          - action: URI
            title: Garage Dash
            uri: /dashboard-homeview/garage
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_close }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_ignore }}"
      - platform: template
        value_template: "{{ trigger.entity_id.state == closed }}"
  - alias: Handle the response
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_close }}"
        sequence:
          - service: notify.notify
            data:
              message: Closing {{ trigger.from_state.attributes.friendly_name }}
          - service: cover.close_cover
            data: {}
            target:
              entity_id: "{{ trigger.entity_id }}"
      - conditions: "{{ wait.trigger.event.data.action == action_ignore }}"
        sequence:
          - service: notify.notify
            data:
              message: Leaving the garage door open
      - conditions: "{{ trigger.entity_id.state == closed }}"
        sequence:
          - service: notify.mobile_app_alex_iphone
            data:
              message: clear_notification
              data:
                tag: doorleftopen
mode: parallel
max: 10

You need single quotes around the state so that it know it’s matching a string not a variable.

- conditions: "{{ states(trigger.entity_id) == 'closed' }}"

Make sure to use them both in the trigger of the Wait and in the condition of the Choose.

I have some assumptions what might the problem here, but before going into details, i can advise some first;

  • try to keep automations short in terms of running time, don’t wait in an automation unknown duration, it might be interrupted by many other things (restart, exception, timeout, run mode)
  • by default, automation runs in single mode, which means if it is triggered first and it is still ongoing, another triggered instance cannot be started. There are other modes captured here: Automation YAML - Home Assistant
  • keep it simple as much as possible, tracing would be much more easier

I would split this automation into 2 different one.

  1. When any of doors are open for 10 minutes, send an actionable notification
  2. When an action has received to close, close the respective door

Thank you both for the suggestions. Splitting into two automations is a good idea which I will do eventually, however I wanted to get it working as one first.

I finally found the issue. "{{ trigger.entity_id.state == ‘closed’ }}" was never resulting as true. Even when replacing the trigger.entity_id with an actually closed entity id. If someone knows why, please let me know.

Using value_template: “{{is_state(trigger.entity_id, 'closed') }}" in both places worked perfectly.

I wanted to share in case anyone else has a similar issue. Here’s the whole working automation.

alias: Garage Door Timer
description: Actionable notification for garage door left open
trigger:
  - platform: state
    entity_id:
      - cover.garage_door_1
    to: open
    for:
      hours: 0
      minutes: 10
      seconds: 0
  - platform: state
    entity_id:
      - cover.garage_door_2
    to: open
    for:
      hours: 0
      minutes: 10
      seconds: 0
condition: []
action:
  - alias: Set up action variables
    variables:
      action_close: "{{ 'CLOSE_' ~ context.id }}"
      action_ignore: "{{ 'IGNORE_' ~ context.id }}"
  - alias: Send the notification
    service: notify.mobile_app_alex_iphone
    data:
      message: >-
        {{ trigger.from_state.attributes.friendly_name }} has been open for 10
        minutes. Would you like to close it?
      title: Garage Door
      data:
        tag: doorleftopen
        actions:
          - action: "{{ action_close }}"
            title: Close
          - action: "{{ action_ignore }}"
            title: Ignore
          - action: URI
            title: Security Dash
            uri: /dashboard-homeview/security
          - action: URI
            title: Garage Dash
            uri: /dashboard-homeview/garage
  - alias: Wait for a response
    wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_close }}"
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{ action_ignore }}"
      - platform: template
        value_template: "{{ is_state(trigger.entity_id, 'closed') }}"
  - alias: Handle the response
    choose:
      - conditions: "{{ wait.trigger.event.data.action == action_close }}"
        sequence:
          - service: notify.notify
            data:
              message: Closing {{ trigger.from_state.attributes.friendly_name }}
          - service: cover.close_cover
            data: {}
            target:
              entity_id: "{{ trigger.entity_id }}"
      - conditions: "{{ wait.trigger.event.data.action == action_ignore }}"
        sequence:
          - service: notify.notify
            data:
              message: Leaving the garage door open
      - conditions:
          - condition: template
            value_template: "{{ is_state(trigger.entity_id, 'closed') }}"
        sequence:
          - service: notify.mobile_app_alex_iphone
            data:
              message: clear_notification
              data:
                tag: doorleftopen
mode: parallel
max: 10