I can’t figure out why every time I open this automation “conditionally execute an action” section in the frontend (iOS), Home assistant prints the following:
Template variable warning: ‘action_disarm’ is undefined when rendering ‘{{ action_disarm }}’
Template variable warning: ‘action_ignore’ is undefined when rendering ‘{{ action_ignore }}’
alias: Suggest disarming alarm on him arrival
description: ""
triggers:
- trigger: state
entity_id:
- person.him
to: home
- trigger: state
entity_id:
- device_tracker.his_hostname
to: home
conditions:
- condition: state
entity_id: alarm_control_panel.ax_pro_master
state: armed_away
actions:
- alias: Set up variables
variables:
action_disarm: "'DISARM' ~ context.id"
action_ignore: "'IGNORE' ~ context.id"
- alias: Notify
action: notify.mobile_app_him
data:
message: Arriving home
title: Would you like to disarm the alarm?
data:
tag: alarm
actions:
- action: "{{ action_disarm }}"
title: Disarm
icon: sfsymbols:lock.slash.fill
- action: "{{ action_ignore }}"
title: Ignore
icon: sfsymbols:xmark.shield.fill
- alias: Wait for response
wait_for_trigger:
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_disarm }}"
trigger: event
- event_type: mobile_app_notification_action
event_data:
action: "{{ action_ignore }}"
trigger: event
timeout:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- if:
- alias: Answer ignore received
condition: template
value_template: >-
{{ wait.tigger|default(none) is none or wait.trigger.event.data.action
== action_ignore }}
then:
- data:
message: clear_notification
data:
tag: alarm
action: notify.mobile_app_him
- if:
- condition: template
value_template: "{{ wait.trigger.event.data.action == action_disarm }}"
alias: Answer disarm received
then:
- target:
entity_id: alarm_control_panel.ax_pro_master
action: alarm_control_panel.alarm_disarm
data: {}
mode: single
I don’t understand what your your two action_* variables are supposed to be, but guessing they are not supposed to be literal strings (as you have written them) but templates to be evaluated. If so add the curly brackets…
Thank you both. This is indeed a mistake (HA probably stripped the curly braces) but it’s not the reason why this warning is being emitted. I fixed it as suggested and the warning is still emitted. Errors after fixing the above is the same:
Template variable warning: ‘action_disarm’ is undefined when rendering ‘{{ action_disarm }}’
Template variable warning: ‘action_ignore’ is undefined when rendering ‘{{ action_ignore }}’
Then I don’t know where you’re wrong. With the code I sent, the notifications and actions work.
this is the automations I tried, just changed the entities…
If you did it correctly, that error will go away. There’s no mechanism in HA that strips {{ }}. Can you take a screenshot showing how you are adding the templates?
And the error appears when you open it or when you run the actions? Where is the error in your front end? Can you screenshot it
To clarify, no templates are executed when you open an automation. Only validation occurs which checks to see if the automation has the correct format. It doesn’t look in the templates.