Why does a TemplateError happen when I open this automation for editing?

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…

action_disarm: "{{ 'DISARM' ~ context.id }}"
action_ignore: "{{ 'IGNORE' ~ context.id }}"
  - alias: Set up variables
    variables:
      action_disarm: "{{ 'DISARM' ~ context.id }}"
      action_ignore: "{{ 'IGNORE' ~ context.id }}"

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 }}’
  - 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
  - alias: Perform the action
    choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_ignore }}"
        sequence:
          - action: notify. mobile_app_him
            data:
              message: clear_notification
              data:
                tag: alarm
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_disarm }}"
        sequence:
          - action: alarm_control_panel.alarm_disarm
            metadata: {}
            target:
              entity_id: alarm_control_panel. ax_pro_master

Sorry, whats different here?
Thanks, why would this prevent the error, yet what I did (based on the docs) doesn’t?

Just tried this. The warning is still emitted.

Then I don’t know where you’re wrong. With the code I sent, the notifications and actions work. :man_shrugging:
this is the automations I tried, just changed the entities…

alias: Suggest disarming alarm on him arrival
description: ""
triggers:
  - trigger: state
    entity_id:
      - device_tracker.demo_anne_therese
    to: home
actions:
  - alias: Set up variables
    variables:
      action_disarm: "{{ 'DISARM' ~ context.id }}"
      action_ignore: "{{ 'IGNORE' ~ context.id }}"
  - alias: Notify
    action: notify.mobile_app_viet_ngoc
    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
  - alias: Perform the action
    choose:
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_ignore }}"
        sequence:
          - action: notify.mobile_app_viet_ngoc
            data:
              message: clear_notification
              data:
                tag: alarm
      - conditions:
          - condition: template
            value_template: "{{ wait.trigger.event.data.action == action_disarm }}"
        sequence:
          - action: alarm_control_panel.alarm_disarm
            metadata: {}
            data:
              code: "1234"
            target:
              entity_id: alarm_control_panel.alarm_panel_1
mode: single

ScreenRecording_01-03-202515-36-15_1-ezgif.com-resize

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?

The automation was always working, the thread is about the warning in the Home Assistant logs.

That’s not the point of the post and doesn’t affect the automation working or not.

sorry to bump into this, can I ask this please:
stel using this format myself:

      - action: notify.mobile_app_marijn
        data:
          title: iOS alt
          message: Wil je de Espresso aanzetten?
          data:
            actions:
              - action: ESPRESSO_TRUE
                title: Ja
                authenticationRequired: false
                activationMode: background
                destructive: true
              - action: Laat maar
                title: Dismiss
                activationMode: background
            push:
              badge: 2
              sound: US-EN-Morgan-Freeman-Motion-In-Kitchen.wav

and then the response in a separate automation/action

      - action: notify.mobile_app_marijn
        data:
          title: iOS notification
          message: Espresso wordt aangezet
          data:
            push:
              badge: 0
              sound: US-EN-Morgan-Freeman-Motion-In-Kitchen.wav

but I now see that is ‘legacy’ and I would like to move to your syntax. can you add that sound to the action too using the new syntax?

Yes it does, the actionable notifications won’t work if the template doesn’t pull the context id

The error comes directly from those 2 variables not being in the namespace.

I already fixed this, and the error is still emitted.

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.

This is the code that OP sent here, I have my action notify set like this according to docs… I have only one automation with sound notify…

alias: Ask to perform action
data:
  message: Do you want to stop this?
  data:
    push:
      sound:
        name: findmy.wav
        critical: 1
        volume: 1
    actions:
      - action: "{{ action_stop }}"
        title: Stop alarm
  title: Alarm Clock
action: notify.mobile_app_viet_ngoc

The error in the log is because you have manually triggered ‘run actions’, if you manually change the trigger state, for example, there is no error.

The error is emitted when I open the automation, not when I run it.

No. The error is emitted when I open the automation. No need to run or trigger manually.

Can you please share a screenshot.