You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the SHA1 extension in a template for a REST sensor.
When I reboot or reload the configuration, it tried to use the function before it's ready.
Error while setting up rest platform for sensor: UndefinedError: 'sha1' is undefined
If I copy the same code into the template editor it works without an issue as spook / sha1 is ready.
This completely breaks my template unfortunately.
Anything in the logs? Paste it here!
Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:382
integration: Sensor (documentation, issues)
First occurred: 19:38:32 (6 occurrences)
Last logged: 19:38:32
Error while setting up rest platform for sensor: UndefinedError: 'sha1' is undefined
Error while setting up rest platform for sensor: TypeError: can only concatenate str (not "NoneType") to str
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 643, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2756, in _render_with_context
return template.render(**kwargs)
~~~~~~~~~~~~~~~^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1295, in render
self.environment.handle_exception()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 942, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 2, in top-level template code
File "/usr/local/lib/python3.13/site-packages/jinja2/sandbox.py", line 399, in call
if not __self.is_safe_callable(__obj):
~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 3173, in is_safe_callable
) or super().is_safe_callable(obj)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
File "/usr/local/lib/python3.13/site-packages/jinja2/sandbox.py", line 265, in is_safe_callable
getattr(obj, "unsafe_callable", False) or getattr(obj, "alters_data", False)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2788, in _fail_with_undefined_error
return super()._fail_with_undefined_error(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'sha1' is undefined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in _async_setup_platform
await asyncio.shield(awaitable)
File "/usr/src/homeassistant/homeassistant/components/rest/sensor.py", line 84, in async_setup_platform
rest = create_rest_data_from_config(hass, conf)
File "/usr/src/homeassistant/homeassistant/components/rest/__init__.py", line 206, in create_rest_data_from_config
resource = resource_template.async_render(parse_result=False)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 645, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'sha1' is undefined
I have noticed that it's the state_attr('sensor.dess_auth', 'secret') %} that causes this error.
If I input a string instead of a state_attr, it works normally.
I need the state_attr because the secret and tokens that need to be SHA1'd constantly change.
I'm guessing there's some sort of dependency / load order thing that changes when state_attr is introduced?
The text was updated successfully, but these errors were encountered:
Joannou1
changed the title
SHA1 is undefined on boot / reload
state_attr in template causes SHA1 to be undefined on boot / reload
Mar 6, 2025
What version of Spook are you using?
3.1.0
What version of Home Assistant are you using?
2025.3.0
The problem
I'm using the SHA1 extension in a template for a REST sensor.
When I reboot or reload the configuration, it tried to use the function before it's ready.
Error while setting up rest platform for sensor: UndefinedError: 'sha1' is undefined
If I copy the same code into the template editor it works without an issue as spook / sha1 is ready.
This completely breaks my template unfortunately.
Anything in the logs? Paste it here!
snippet of Configuration.yml
snippet of secret.yml
I have noticed that it's the
state_attr('sensor.dess_auth', 'secret') %}
that causes this error.If I input a string instead of a state_attr, it works normally.
I need the state_attr because the secret and tokens that need to be SHA1'd constantly change.
I'm guessing there's some sort of dependency / load order thing that changes when state_attr is introduced?
The text was updated successfully, but these errors were encountered: