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