core icon indicating copy to clipboard operation
core copied to clipboard

Template helpers logs errors during HA start

Open kukulich opened this issue 2 years ago • 4 comments

The problem

I've rewritten template sensors from YAML to helpers. Now I get some errors in logs during HA start. See logs below.

The template works and the template entity too. I expect there's problem that the source entity in template is not ready when the template is processed.

What version of Home Assistant Core has the issue?

2023.9.0b3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

template

Link to integration documentation on our website

https://www.home-assistant.io/integrations/template/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-09-03 16:26:52.421 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ ((states('sensor.monthly_water_consumption') | float) * (states('sensor.cena_za_kubik_vody') | float)) | round(0) }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1907, 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 562, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2178, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.11/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 1910, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1608, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ ((states('sensor.monthly_water_consumption') | float) * (states('sensor.cena_za_kubik_vody') | 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 683, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 564, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ ((states('sensor.monthly_water_consumption') | float) * (states('sensor.cena_za_kubik_vody') | float)) | round(0) }}' but no default was specified


### Additional information

_No response_

kukulich avatar Sep 03 '23 14:09 kukulich

Hey there @phracturedblue, @tetienne, @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (template) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of template can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign template Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


template documentation template source (message by IssueLinks)

home-assistant[bot] avatar Sep 03 '23 14:09 home-assistant[bot]

me too After update core to 2023.9.3 in HA start :

Logger: homeassistant.helpers.event Source: helpers/template.py:570 First occurred: 19:32:28 (67 occurrences) Last logged: 19:32:39

Error while processing template: Template<template=({{ states("sensor.producao_diaria")| round(2)}} KWh) renders=22> Error while processing template: Template<template=({{ states("sensor.custo_online")| round(2)}} €) renders=22> Error while processing template: Template<template=({{ states("sensor.consumo_energia_mensal")| round(2)}} KWh) renders=22> Error while processing template: Template<template=({{ states("sensor.poupanca_online")| round(2)}} €) renders=22> Error while processing template: Template<template=({{ states("sensor.energia_retorno_a_rede")| round(2)}} KWh) renders=18> Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1647, in forgiving_round value = round(float(value), precision) ^^^^^^^^^^^^ 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 568, in async_render render_result = _render_with_context(self.template, compiled, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2198, in _render_with_context return template.render(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 1301, in render self.environment.handle_exception() File "/usr/local/lib/python3.11/site-packages/jinja2/environment.py", line 936, in handle_exception raise rewrite_traceback_stack(source=source) File "

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 694, in async_render_to_info render_info._result = self.async_render( ^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 570, in async_render raise TemplateError(err) from err homeassistant.exceptions.TemplateError: ValueError: Template error: round got invalid input 'unknown' when rendering template '{{ states("sensor.producao_diaria")| round(2)}} KWh' but no default was specified

jocamane avatar Sep 27 '23 18:09 jocamane

Solved in my case: I change round(2) --> round(2,default=2)

jocamane avatar Sep 27 '23 23:09 jocamane

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.