Error in logs even after removing offending trigger

I keep getting this error in my logs. It happens when I reboot HA, or reload all yaml.

Here’s the error:

Error while processing template: Template<template=({{ states(this.entity_id ) == “on” }}) renders=3>

The error message is that “this” is undefined.

I know the error comes from a trigger in my automation, because of the space between entity_id and the parenthesis ‘)’. I put those spaces in to debug these issues because there’s no indication of what yaml source / automation is causing the issue.

(Let’s note that the automation in question actually works, just the error happens on reboot. After boot it seems to work as intended.)

However, I’ve removed this line from the automation, and searching all my automations I can no longer find this text – its been removed from my packages.

FYI, the line of error would seem to be (have been) from a yaml automation that is incorporated via “!include dir_named mypackages/”. Generally speaking I don’t get error messages on triggers to “this.entity_id” from automations.yaml – those errors only from included packages.

Still, I get this error in the logs despite having removed the offending line. I have restarted the whole system yet keep getting this error on reboot. How can I clear it, or better yet debug it??

Hello,
the message is on boot?
Maybe the template does not availability set so when starting there is no value in thisentityid and it is undefined.

That’s not correct. The space isn’t impacting the template. This template trigger won’t work everywhere because this isn’t populated when triggers occur. The exception might be automations. I’m not 100% sure if this is populated prior to template triggers in automations.

It will not populated for template entities. Source: I wrote the code.

I didn’t mean to imply that the space was cause of error. What I mean is that I recognize that line of code as I wrote that space. I put a space like that in there to help determine what automation is causing the error since the log doesn’t contain the file & line number of the offending yaml automation, but instead shows lines of python that had some error.

Well, the only way the error will appear is if the automation is still loading. The only way it can be loaded is if it reads that yaml. On startup, the automation will register templates to watch and then those templates will produce the error above. That’s what is happening. It’s impossible for that error to appear without the offending trigger being in your automation. I’d to a search for this.entity_id in all of your configuration files.

I have removed that line from the yaml that had it and cannot find any further occurrence of that. Is there any way to get the system to tell me what yaml it came from?

No, not with how that trigger is registered. This should take 5 minutes tops with notepad++ or vscode. Just do a “find in files” for this.entity_id. It should give you a list of all the hits it finds.

I search for the exact phrase {{ states(this.entity_id ) and no longer find it.

I do find {{ states(this.entity_id) all over my automations (without the space), dozens of places. But not the one with the extra space inserted as I have done in the past to help identify what yaml is causing what error.

Also, I only seem to get an error regarding “this” being undefined from yaml loaded with !include_dir_named mypackages/ , never from automations.yaml.

Here are the log error messages:

Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:63
integration: Template ([documentation](https://www.home-assistant.io/integrations/template), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+template%22))
First occurred: March 15, 2026 at 6:59:07 PM (3 occurrences)
Last logged: 9:40:35 AM

Error initializing 'template' trigger for 'websocket_api': UndefinedError: 'this' is undefined
Logger: homeassistant.helpers.template
Source: helpers/template/__init__.py:1757
First occurred: March 15, 2026 at 6:59:07 PM (6 occurrences)
Last logged: 9:40:35 AM

Template variable error: 'this' is undefined when rendering '{{ states(this.entity_id ) == "on" }}'
Logger: homeassistant.helpers.event
Source: helpers/template/__init__.py:463
First occurred: March 15, 2026 at 6:59:07 PM (3 occurrences)
Last logged: 9:40:35 AM
Error while processing template: Template<template=({{ states(this.entity_id ) == "on" }}) renders=3>

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template/__init__.py", line 461, in async_render
    render_result = render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template/context.py", line 45, in render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.14/site-packages/jinja2/sandbox.py", line 319, in getattr
    value = getattr(obj, attribute)
  File "/usr/src/homeassistant/homeassistant/helpers/template/__init__.py", line 1776, in _fail_with_undefined_error
    return super()._fail_with_undefined_error(*args, **kwargs)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'this' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template/__init__.py", line 579, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
        variables, strict=strict, log_fn=log_fn, **kwargs
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template/__init__.py", line 463, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'this' is undefined

Well that first error is coming from developer tools / templates

Interesting. I checked Developer Tools / Template and don’t have this.entity_id there…

1 is external to HAs backend (HA’s frontend or something else) i.e. It’s not an automation error. Do you use nodered? Did you put this template in the template editor?

2 and 3 are the same error. 2 is the logged error, 3 is the traceback.

Ok. I show #1 because it always occurs with the other two errors. Probably just has to do with the general reloading of yaml.

No: no nodered

Checked my Developer Tools / Template tab and find no “this” therein.

(btw, thanks for your time looking at this.)

Did you check all your devices? Dev tools caches information on a per device basis.

I’ll look; how to do that? Or how to clear cache?

just go to settings → developer tools → template editor on every device you own that you may have used and clear the template.

Ok, have updated from core-2026.3.1 to core-2026.3.2 and no such errors anymore so far…