Value Template Error When Trigger Is NOT Fired

I had a wake alarm automation working using a value template as a failsafe, and something broke it, so now whenever something goes wrong with the first stage of my wake alarm (or if I were to sleep through that), the automation finishes as if I cancelled the alarm instead of entering the more aggressive stage. I slept in after editing the automation lead to something going wrong (that is outside the scope of this thread, but the thing always goes wrong until a restart after I edit the automation), and I thought maybe my changes broke the failsafe, but reverting my changes didn’t resolve the failsafe issue, so I don’t know when or what actually broke the failsafe. I suspect an update changed the underlying behavior or using the GUI to cut/paste the value template condition changed the format, but it is also possible that my original configuration didn’t have the not and that never got tested. I’m not sure how to confirm, so I’m hoping someone looking at this from a fresh perspective can help me fix it regardless of the root cause. I created a much simpler automation to verify the breakage was specific to the failsafe, and it is, so I’m looking for assistance making the value template work the way it used to. Here is the most simplified version of the automation:

alias: Wait Trigger Test No Choose
description: Proving out issue in more complex automation by removing all other variables.
trigger: []
condition: []
action:
  - service: notify.mobile_app_iphone
    data:
      title: Test Automation Triggered
      message: Take action, or don't.
      data:
        actions:
          - action: "{{'cancel_'~context.id}}"
            title: Cancel Test
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{'cancel_'~context.id}}"
    timeout:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - if:
      - condition: not
        conditions:
          - condition: template
            value_template: "{{wait.trigger.event.data.action=='cancel_'~context.id}}"
    then:
      - service: notify.mobile_app_iphone
        data:
          message: You didn't do anything, and the value template didn't fail.
          title: Test Status
    else:
      - service: notify.mobile_app_iphone
        data:
          title: Test Staus
          message: You pressed the cancel button, or the value template failed.
mode: single

If I run this automation and use the cancel button presented with the notification, I get the else action as expected, and the trace reads as follows:

if
result: false
if/condition/0
result: false
if/condition/0/conditions/0
result: false

However, if I don’t use the cancel button, I am still getting the else action; this is where I used (and want) to get the then action. In that scenario, the trace reads like this:

if
result: null
if/condition/0
Error: In ‘not’: In ‘template’ condition: UndefinedError: ‘None’ has no attribute ‘event’
if/condition/0/conditions/0
Error: In ‘template’ condition: UndefinedError: ‘None’ has no attribute ‘event’

I do realize I could get rid of the not and swap actions between then and else to get desired results here, but that isn’t a good option in the more complicated automation, because there are other conditions in the if statement that should ideally have a specific state (as opposed to not having one of multiple other possible states). Further, I’d really rather be consistently getting a true or a false result so I don’t run the risk of some other gotcha due to the null result in the future.

If you do not respond, there is no trigger from the wait and such you need to test for a none trigger as below.

alias: Wait Trigger Test No Choose
description: Proving out issue in more complex automation by removing all other variables.
trigger: []
condition: []
action:
  - service: notify.mobile_app_iphone
    data:
      title: Test Automation Triggered
      message: Take action, or don't.
      data:
        actions:
          - action: "{{'cancel_'~context.id}}"
            title: Cancel Test
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{'cancel_'~context.id}}"
    timeout:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - if:
      - condition: not
        conditions:
          - condition: template
            value_template: >-
              {{ True if wait.trigger is not none and
              wait.trigger.event.data.action=='cancel_'~context.id else
              False }}
    then:
      - service: notify.mobile_app_iphone
        data:
          message: You didn't do anything, and the value template didn't fail.
          title: Test Status
    else:
      - service: notify.mobile_app_iphone
        data:
          title: Test Staus
          message: You pressed the cancel button, or the value template failed.
mode: single

Since my root problem was more complicated, the solution posted didn’t solve it, but it was technically correct, and I have marked it as a solution accordingly.

My original issue was that the workaround I had created for `Wait for a trigger` Caused Trigger to Occur? stopped working. I’m guessing that I implemented and tested my workaround before I implemented the event trigger. That having been said, after some more testing and sleep, I determined that the reason I was getting null was because there was no event trigger. However, even none is a trigger, so I was able to resolve this in a way that solves my problem by doing the following:

alias: Wait Trigger Test No Choose
description: Proving out issue in more complex automation by removing all other variables.
trigger: []
condition: []
action:
  - service: notify.mobile_app_iphone
    data:
      title: Test Automation Triggered
      message: Take action, or don't.
      data:
        actions:
          - action: "{{'cancel_'~context.id}}"
            title: Cancel Test
  - wait_for_trigger:
      - platform: event
        event_type: mobile_app_notification_action
        event_data:
          action: "{{'cancel_'~context.id}}"
        id: iPhone Cancel
    timeout:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - if:
      - condition: not
        conditions:
          - condition: template
            value_template: "{{wait.trigger.id=='iPhone Cancel'}}"
    then:
      - service: notify.mobile_app_iphone
        data:
          message: You didn't do anything, and the value template didn't fail.
          title: Test Status
    else:
      - service: notify.mobile_app_iphone
        data:
          title: Test Staus
          message: You pressed the cancel button, or the value template failed.
mode: single

For the record, I didn’t test this exact template, as I had modified my original test quite a bit before I realized I could add trigger ids in conditions outside of the automation triggers section, but I did copy and paste the relevant bits from my last iteration, so this should at least exemplify a viable alternative solution when using the none trigger isn’t ideal.