First Warning.
in my sensor file a last call for my alexa’s and i’m getting this in my logs
Logger: homeassistant.helpers.template
Source: helpers/template.py:1779
First occurred: 6:33:25 PM (4 occurrences)
Last logged: 6:33:32 PM
Template variable warning: No first item, sequence was empty. when rendering '{{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first }}'
{{ states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | first }}
Obviously, states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') does not return a list. Probably because the ‘last_called’ attribute is empty (upon re-start).
Sorry, no. You can extend value_template to some slightly complex if list is empty, return empty string, else first entity_id script, that would make the warning disappear.
Logger: homeassistant.components.template.sensor
Source: helpers/config_validation.py:796
Integration: Template (documentation, issues)
First occurred: 8:14:51 PM (1 occurrences)
Last logged: 8:14:51 PM
The 'entity_id' option near /config/sensors/power.yaml:149 is deprecated, please remove it from your configuration
Is there actually a template for this sensor or are you just trying to set the unit. Because that can be done with customize. No need for a template sensor.
value_template: >-
{%- set last = (states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') | list ) -%}
{{ last | first if (last | length > 0) else 'none' }}
Logger: homeassistant.helpers.event
Source: helpers/template.py:408
First occurred: 8:48:37 PM (1 occurrences)
Last logged: 8:48:37 PM
Error while processing template: Template("{% set last_player = states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') %} {{ last_player|first if last_player|length > 0 else none }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 406, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1771, in _render_with_context
return template.render(**kwargs)
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1291, in render
self.environment.handle_exception()
File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
raise rewrite_traceback_stack(source=source)
File "<template>", line 1, in top-level template code
TypeError: object of type 'generator' has no len()
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 522, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 408, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: TypeError: object of type 'generator' has no len()
Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:140
Integration: Template (documentation, issues)
First occurred: 8:48:37 PM (1 occurrences)
Last logged: 8:48:37 PM
TemplateError('TypeError: object of type 'generator' has no len()') while processing template 'Template("{% set last_player = states.media_player | selectattr('attributes.last_called','eq',true) | map(attribute='entity_id') %} {{ last_player|first if last_player|length > 0 else none }}")' for attribute '_attr_native_value' in entity 'sensor.last_alexa'
This value_template returns the String ‘none’, if no media_player matches the attribute filter. I am not familiar with Python / Jinja, maybe something other than ‘none’ must be returned. Maybe NoneType (without quotes).