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

The error appears in the logs, pretty sure I wrote that already. But I will share a video.

Ok. I won’t be able to share a video because it’ll contain personal information that I’m not interested in sharing and don’t have the time to blur out.

What kind of screenshot should I share? I can take a screenshot of the logs, but I already pasted them, and I’m sure everyone here knows how an automation YAML looks like in the frontend.

I appreciate the help.

At the moment when the error message is displayed upon opening the automation in the Automation Editor.

Ok, he’s right… the error appears even when opening automation in UI

2025-01-03 16:15:27.082 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'action_disarm' is undefined when rendering '{{ action_disarm }}'
2025-01-03 16:15:27.083 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'action_ignore' is undefined when rendering '{{ action_ignore }}'

1 Like

Now that I’m back at my desk, this code should not work.

Event triggers do not allow regular templates, only limited tempates.

Upon opening, the template is resolved because it’s expecting a limited template which should have everything already defined.

The variables are only passed during automation execution, that warning will always exist because the namespace on load will never have the variables from another action.

EDIT: After reviewing the code, it does look like variables from previous actions are passed into triggers.

TLDR: This will always produce a warning on open, there is no way around it aside from suppressing the warning with Logging integration.

Thanks for looking into. If this is expected, why is it a warning? Should I open a ticket asking for that? I’m ok with ignoring it, just keen to learn if I’m doing something wrong

It’s a warning, not an error. Warning is letting you know there might be a problem.

You can, but it would be impossible to fix. The only way to fix it is to run the automation when it loads, which no one would want.

The log message is always needed in case someone actually has a non-defined variable.

It’s a damned if you do, damned if you don’t scenario.

EDIT: IF you post the full error from the logs, I can show you how to suppress it.

EDIT2: NM I see someone else posted the full error.

EDIT3: add this to configuration.yaml and restart.

logger:
  default: info
  filters:
    homeassistant.helpers.template:
    - "Template variable warning: 'action_disarm' is undefined when rendering"
    - "Template variable warning: 'action_ignore' is undefined when rendering"

I doubt this is the only way to fix it, maybe it’s only way without refactoring the whole system.

In any case, I’m thankful for all the help and open mindedness here in (re-)reviewing my issue. I can totally live with this warning.

It’s literally the only way, context.id that you’re using in the other template limits the variables to only resolve during execution. Even refactoring the system, it would still need to run to get a context id.

Ok, but I can argue that a variable should not resolve nor evaluate while I’m reviewing an automation. And in general, expected behavior should not be warned against.

So no, it’s not the only way, but once again - I’m totally fine with this.

That’s the entire point of limited templates. They are resolved when the automation loads so that the fields have the correct value.

So basically there’s a limitation when I want to use actionable notifications, and that limitation says that if I use a variable for the event_data.action (which I have to in order to embed context) in the YAML, then I’m always going to get a warning in the logs (if I open it in the frontend). I’m cool with that.

Well, the limitation is whenever you use any trigger that can use limited templates inside a wait_for_trigger where the template is accessing an external variable, it’s gonna warn you in the logs.

That’s the only case where this warning can be ignored.

BTW, any idea why the automation trigger always matches the ignore clause when I guard against a null trigger? wait.tigger|default(none) is none or wait.trigger.event.data.action == action_ignore

If I remove the OR clause the automation behaves as expected. I introduced it because I would get errors when the trigger times out.

Edit:

Yep, tiggertrigger