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.