1-
Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:68
Integration: Template (documentation, issues)
First occurred: 7:50:22 pm (1 occurrences)
Last logged: 7:50:22 pm
Error evaluating 'template' trigger for 'ttttt': UndefinedError: 'GasSensor' is undefined
2-
Logger: homeassistant.helpers.event
Source: helpers/template.py:460
First occurred: 7:50:22 pm (1 occurrences)
Last logged: 7:50:22 pm
Error while processing template: Template("{{ states(GasSensor) >= states(Warninglevel) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 744, in __call__
state = _get_state(self._hass, entity_id)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 990, in _get_state
return _get_template_state_from_state(hass, entity_id, hass.states.get(entity_id))
File "/usr/src/homeassistant/homeassistant/core.py", line 1406, in get
return self._states.get(entity_id.lower())
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2033, in _fail_with_undefined_error
raise ex
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2024, in _fail_with_undefined_error
return super()._fail_with_undefined_error(*args, **kwargs)
jinja2.exceptions.UndefinedError: 'GasSensor' 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.py", line 576, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'GasSensor' is undefined
1-
Logger: homeassistant.components.template.trigger
Source: components/template/trigger.py:68
Integration: Template (documentation, issues)
First occurred: 9:10:31 pm (1 occurrences)
Last logged: 9:10:31 pm
Error evaluating 'template' trigger for '13435': AttributeError: 'list' object has no attribute 'lower'
2-
Logger: homeassistant.helpers.event
Source: helpers/template.py:460
First occurred: 9:10:30 pm (1 occurrences)
Last logged: 9:10:30 pm
Error while processing template: Template("{{ states(GasSensor) >= states(Warninglevel) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 744, in __call__
state = _get_state(self._hass, entity_id)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 990, in _get_state
return _get_template_state_from_state(hass, entity_id, hass.states.get(entity_id))
File "/usr/src/homeassistant/homeassistant/core.py", line 1406, in get
return self._states.get(entity_id.lower())
AttributeError: 'list' object has no attribute 'lower'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 576, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: AttributeError: 'list' object has no attribute 'lower'
Ok, at least the error of the variables not being defined has gone away, so you are a step further.
The next problem is that you are trying to compare the states of gas_sensor and warning_level like comparing numbers. The template however does not automatically convert the states to numbers for you, you have to do this yourself by using the float filter.
Log Details (ERROR)
Logger: homeassistant.helpers.event
Source: helpers/template.py:460
First occurred: 9:33:17 pm (1 occurrences)
Last logged: 9:33:17 pm
Error while processing template: Template("{{ states(GasSensor)|float >= states(Warninglevel)|float }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 458, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2007, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
File "/usr/local/lib/python3.10/site-packages/jinja2/sandbox.py", line 393, in call
return __context.call(__obj, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 744, in __call__
state = _get_state(self._hass, entity_id)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 990, in _get_state
return _get_template_state_from_state(hass, entity_id, hass.states.get(entity_id))
File "/usr/src/homeassistant/homeassistant/core.py", line 1406, in get
return self._states.get(entity_id.lower())
AttributeError: 'list' object has no attribute 'lower'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 576, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 460, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: AttributeError: 'list' object has no attribute 'lower'
By the way, this template trigger will fail with rror if you have multiple entities selected, as you will be passing a list to states, which is not supported.
We can find an alternative, but before that, how you want the system to behave when multiple entities are selected? Trigger if all entities are above the threshold or if any of the entities are above the threshold?
Could you please share the yaml of the automation using this Blueprint in your tests?
I see that I was a bit quick when saying that you should just replace variables with trigger_variables, my bad.
You have a list of gas sensor entities because you use
multiple: true
in its definition. Handling lists in templates goes above my knowledge level
Sorry I canāt help you any further
Could you please share the yaml of the automation using this blueprint in your tests?
If you can capture the screen of the latest trace (whit the step related to that trigger selected) it might help.
Also, could you please go to Developer Tools and select the tab State, then double check that at least one entity selected to GasSensor and also the input number select for Warninglevel have some value?
the Idea is I have more than 12 smoke and gas DIY sensor in the house and we are 7 users
So I decided to make a blueprint for notifying users if any of the sensors have been triggered with two levels of notification Warning and Alarm by using two input_number for each type of sensor
if any sensor level is >= Warning or Alarm send a notification
for that I use
Gas_Sensor:
name: Gas Sensor
description: Select Gas Sensor entity.
selector:
entity:
domain: sensor
multiple: true
multiple: true
help me to add more sensors in one blueprint
Note: for testing purposes, I use the other two input_number as sensors to simulate the gas sensor
I got the point, Iām just trying to understand where the problem is that it is not triggering the automation, so I want to see the result of the traceā¦
But based oj what you just said, Iām thinkingā¦ If you are using the input number entity itself, then your template will result true from the beginning and will never be false, preventing your automation to run.
An automation runs when the trigger change its value from false to true. If it is always true or always false, it will never run.
Ok, the problem is that my template will look for entities only on the sensor domain, and you are using entities in the input_number domain.
I will change that, but probably will be a bit more CPU consumption compared to how it is now.
Try this:
trigger:
# - platform: template
# id: Alarm
# value_template: >-
# {{states(GasSensor) >= states(Alarmlevel)}}
- platform: template
id: Warning
value_template: >-
{{
(
states
| selectattr('entity_id', 'in', GasSensor)
| map(attribute='state')
| map('float')
| list
| count > 0
) and
is_number(Warninglevel) and
(
states
| selectattr('entity_id', 'in', GasSensor)
| map(attribute='state')
| map('float')
| list
| max
) >= states(Warninglevel) | float
}}