jeroenterheerdt / HADailySensor

Sensor for Home Assistant that gets reset at midnight
MIT License
73 stars 18 forks source link

Home Assistant crashes when changing input sensor #71

Open johannes1984 opened 3 days ago

johannes1984 commented 3 days ago

Hi,

I have the reproducable issue, that when I change the input sensor HA fully crashes. The only way to bring it back is to reboot the VM in Proxmox. Running HA 2024.10.2 and Daily Sensor v2024.10.1

I started the debug mode and then tried the change and got this:

-------------------------------------------------------------------
Daily Sensor
Version: v2024.10.1
If you have any issues with this you need to open an issue here:
https://github.com/jeroenterheerdt/HADailySensor/issues
-------------------------------------------------------------------

2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] auto_reset: True
2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] registered for time change.
2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] Updating Daily Sensor Temperatur_Innen_Max
2024-10-17 16:40:34.092 DEBUG (MainThread) [custom_components.daily] Finished fetching Temperatur_Innen_Max data in 0.000 seconds (success: True)
2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] auto_reset: True
2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] registered for time change.
2024-10-17 16:40:34.092 INFO (MainThread) [custom_components.daily] Updating Daily Sensor Temperatur Aussen Minimum
2024-10-17 16:40:34.093 DEBUG (MainThread) [custom_components.daily] Finished fetching Temperatur Aussen Minimum data in 0.000 seconds (success: True)
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] auto_reset: True
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] registered for time change.
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] Updating Daily Sensor Temperatur Aussen Maximum
2024-10-17 16:40:34.093 DEBUG (MainThread) [custom_components.daily] Finished fetching Temperatur Aussen Maximum data in 0.000 seconds (success: True)
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] auto_reset: True
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] registered for time change.
2024-10-17 16:40:34.093 INFO (MainThread) [custom_components.daily] Updating Daily Sensor  Temperatur_Innen_Min
2024-10-17 16:40:34.093 DEBUG (MainThread) [custom_components.daily] Finished fetching  Temperatur_Innen_Min data in 0.000 seconds (success: True)
2024-10-17 16:40:35.473 WARNING (MainThread) [homeassistant.components.fan] Platform xiaomi_miio_fan not ready yet: Unable to discover the device 192.168.2.110; Retrying in background in 30 seconds
2024-10-17 16:40:37.671 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template<template=({{ (states('sensor.badezimmer_absolute_feuchtigkeit') | float - states('sensor.wohnung_absolute_feuchtigkeit') | float) | round(2) }}) renders=2>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2348, 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 632, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2729, in _render_with_context
    return template.render(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.12/site-packages/jinja2/environment.py", line 939, 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 2351, in forgiving_float_filter
    raise_no_default("float", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1905, in raise_no_default
    raise ValueError(
ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.badezimmer_absolute_feuchtigkeit') | float - states('sensor.wohnung_absolute_feuchtigkeit') | float) | round(2) }}' 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 749, in async_render_to_info
    render_info._result = self.async_render(  # noqa: SLF001
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 634, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.badezimmer_absolute_feuchtigkeit') | float - states('sensor.wohnung_absolute_feuchtigkeit') | float) | round(2) }}' but no default was specified
2024-10-17 16:40:37.672 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.badezimmer_absolute_feuchtigkeit') | float - states('sensor.wohnung_absolute_feuchtigkeit') | float) | round(2) }}' but no default was specified') while processing template 'Template<template=({{ (states('sensor.badezimmer_absolute_feuchtigkeit') | float - states('sensor.wohnung_absolute_feuchtigkeit') | float) | round(2) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.badezimmer_differenz_absolute_feuchte'
jeroenterheerdt commented 3 days ago

most likely the sensors don't provide a value at boot, that's why you are getting this issue. that should not be blocking HA though. You should handle this by adding a delay on update or handle it in your template. This does not have anything to do with HADailySensor AFAIK.

johannes1984 commented 3 days ago

When I tried to edit the daily sensor the first time, HA was running for days, so the value was definetly set.

jeroenterheerdt commented 3 days ago

what's the value the sensors provide and what does the template evaluate to in the Template UI?

Xenomes commented 2 days ago

The same issue occurs here: when editing a daily sensor, changing the sensor input, and saving, Home Assistant goes offline. I have to reboot Docker to get it back online. Current version: v2024.10.2. Last known working version: v2024.9.1.

Did a bypass edit in the file: core.config_entries pro with backup only.

johannes1984 commented 2 days ago

what's the value the sensors provide and what does the template evaluate to in the Template UI?

grafik

sensor.master_wohnung_temperatur is a Helper, combining two sensors to one, using arithmetic mean