Ughā¦it was working after my last post as indicatedā¦but now is broken again in 2023.5.2. I havenāt changed anything with the sensor. Just shows Unknown now.
Relevant error messages:
Logger: homeassistant.helpers.template
Source: helpers/template.py:544
First occurred: 1:22:16 AM (1 occurrences)
Last logged: 1:22:16 AM
Template variable error: 'homeassistant.helpers.template_entity.DummyState object' has no attribute 'device_id' when rendering '{{ iif(states(this.device_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}'
Logger: homeassistant.helpers.event
Source: helpers/template.py:546
First occurred: 1:22:28 AM (1 occurrences)
Last logged: 1:22:28 AM
Error while processing template: Template<template=({{ iif(states(this.device_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}) renders=3>
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 544, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2164, 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 835, in __call__
state = _get_state(self._hass, entity_id)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1093, 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 1445, in get
return self._states.get(entity_id.lower())
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2190, in _fail_with_undefined_error
raise ex
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2181, in _fail_with_undefined_error
return super()._fail_with_undefined_error(*args, **kwargs)
jinja2.exceptions.UndefinedError: 'homeassistant.helpers.template.TemplateStateFromEntityId object' has no attribute 'device_id'
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 665, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 546, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'homeassistant.helpers.template.TemplateStateFromEntityId object' has no attribute 'device_id'
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:379
First occurred: 1:22:28 AM (1 occurrences)
Last logged: 1:22:28 AM
TemplateError('UndefinedError: 'homeassistant.helpers.template.TemplateStateFromEntityId object' has no attribute 'device_id'') while processing template 'Template<template=({{ iif(states(this.device_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}) renders=5>' for attribute '_attr_icon' in entity 'sensor.unavailable_entities'
Logger: homeassistant
Source: components/sensor/__init__.py:583
First occurred: 1:22:28 AM (1 occurrences)
Last logged: 1:22:28 AM
Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 579, in state
numerical_value = int(value)
ValueError: invalid literal for int() with base 10: ''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 379, in _async_template_startup
result_info.async_refresh()
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 953, in async_refresh
self._refresh(None)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1133, in _refresh
self.hass.async_run_hass_job(self._job, event, updates)
File "/usr/src/homeassistant/homeassistant/core.py", line 607, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/template_entity.py", line 348, in _handle_results
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 585, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
raise ValueError(
ValueError: Sensor sensor.unavailable_entities has device class None, state class None unit entities and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: (<class 'str'>)
My Template as it has been working for weeks:
template:
- sensor:
- name: "Unavailable Entities"
unique_id: unavailable_entities
icon: "{{ iif(states(this.device_id)|int(0) > 0,'mdi:alert-circle','mdi:check-circle') }}"
unit_of_measurement: entities
state: >
{% set entities = state_attr(this.entity_id,'device_id') %}
{% if entities != none %} {{ entities|count }} {% endif %}
attributes:
device_id: >
{% set ignore_seconds = 3 %}
{% set ignored = state_attr('group.ignored_unavailable_entities','entity_id') %}
{% set ignore_ts = (now().timestamp() - ignore_seconds)|as_datetime %}
{% set entities = states|rejectattr('domain','eq','group')
|rejectattr('last_changed','ge',ignore_ts)
|rejectattr('entity_id','search','(octoprint_|_debug|scene.|device_tracker|person.|_channel|openweathermap_|var.|_active_app|emby_|camera.|agent_alarm|_led|_consumption|unavailable_entities|media_player|sensor.hacs|hall_uv|speedtest|ender3_|10_10_0_21)')
|selectattr('state','in',['unavailable','unknown']) %}
{% if ignored != none %}
{% set entities = entities|rejectattr('entity_id','in',ignored) %}
{% endif %}
{{ entities|map(attribute='entity_id')|list }}
So, whatās wrong now?