I have a template for my energy consumption. Everything worked fine, but when I do the Home Assistant Core Update 2023.2.0 I don’t get any values anymore.
What are the states you are trying to calculate with currently? The second template is missing default values fro float (and maybe a pair of parentheses).
I did already a backup to restore former settings. One state was unknown and one 0 as far as I can remember. In the logs it said it‘s a problem with float. I could do an update again this evening to get all the details again.
I already had a similar problem several month ago and could fix it by myself- just had to change the „format“. I guess it will be the same this time but couldn‘t find the solution so far.
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:364
First occurred: 21:03:41 (1 occurrences)
Last logged: 21:03:41
TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.aktueller_uberschuss') | float) - (states('sensor.aktueller_bezug') | float) | round(0) }}' but no default was specified') while processing template 'Template("{{ (states('sensor.aktueller_uberschuss') | float) - (states('sensor.aktueller_bezug') | float) | round(0) }}")' for attribute '_attr_native_value' in entity 'sensor.template_ueberschuss_bezug'
Logger: homeassistant.helpers.event
Source: helpers/template.py:459
First occurred: 21:03:41 (1 occurrences)
Last logged: 21:03:41
Error while processing template: Template("{{ (states('sensor.aktueller_uberschuss') | float) - (states('sensor.aktueller_bezug') | float) | round(0) }}")
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1745, in forgiving_float_filter
return float(value)
ValueError: could not convert string to float: 'unknown'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 457, in async_render
render_result = _render_with_context(self.template, compiled, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1984, 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/src/homeassistant/homeassistant/helpers/template.py", line 1748, in forgiving_float_filter
raise_no_default("float", value)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1446, in raise_no_default
raise ValueError(
ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.aktueller_uberschuss') | float) - (states('sensor.aktueller_bezug') | float) | round(0) }}' but no default was specified
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 575, in async_render_to_info
render_info._result = self.async_render(variables, strict=strict, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 459, in async_render
raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.aktueller_uberschuss') | float) - (states('sensor.aktueller_bezug') | float) | round(0) }}' but no default was specified
Ok, I’ll try that out and report you again in the evening.
Sorry - I have nothing to do with computer in my life and everything is self educated. So the logs are absolutely spanish for me. I appreciate your help!
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:364
First occurred: 12:38:44 PM (1 occurrences)
Last logged: 12:38:44 PM
TemplateError('ValueError: Template error: as_timestamp got invalid input 'unknown' when rendering template '{% if as_timestamp(now()) - as_timestamp(states('sensor.power_meter_last_seen')) > 120 %} on {% else %} off {% endif %}' but no default was specified') while processing template 'Template("{% if as_timestamp(now()) - as_timestamp(states('sensor.power_meter_last_seen')) > 120 %} on {% else %} off {% endif %}")' for attribute '_state' in entity 'binary_sensor.apagon_luz'
Back again! I found the solution - the main problem was, that I got some values from MQTT. The Mqtt Integration had to be reconfigurated with the new Update so the names for the code where wrong.
I also tried a new format for the template configuration which has a bit more clarity for me: