Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error with 'unavailable' sensor #135005

Closed
tj551955 opened this issue Jan 7, 2025 · 4 comments
Closed

error with 'unavailable' sensor #135005

tj551955 opened this issue Jan 7, 2025 · 4 comments

Comments

@tj551955
Copy link

tj551955 commented Jan 7, 2025

The problem

Error after restart of HA (see log message). I have a device that is off and thus one of the sensors of the device has the status 'unavailable'. This status cannot be processed in HA core and throws an exception. According to the log it seems to be a type conversion error.

What version of Home Assistant Core has the issue?

core-2025.1.1

What was the last working version of Home Assistant Core?

not sure, but I see this error for a while

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.core
Source: core.py:1578
First occurred: 16:07:54 (1 occurrences)
Last logged: 16:07:54

Error running job: <Job onetime listen homeassistant_start <function _async_at_core_state.<locals>._matched_event at 0x7f65bc7920> HassJobType.Callback <_OneTimeListener homeassistant.helpers.start:<function _async_at_core_state.<locals>._matched_event at 0x7f65bc7920>>>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 640, in state
    numerical_value = float(value)  # type:ignore[arg-type]
ValueError: could not convert string to float: 'unavailable'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1578, in async_fire_internal
    self._hass.async_run_hass_job(job, event)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 940, in async_run_hass_job
    hassjob.target(*args)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1439, in __call__
    self.hass.async_run_hass_job(self.listener_job, event)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 940, in async_run_hass_job
    hassjob.target(*args)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/start.py", line 44, in _matched_event
    hass.async_run_hass_job(at_start_job, hass)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 940, in async_run_hass_job
    hassjob.target(*args)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 517, in _async_template_startup
    result_info.async_refresh()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1127, in async_refresh
    self._refresh(None)
    ~~~~~~~~~~~~~^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1313, in _refresh
    self.hass.async_run_hass_job(self._job, event, updates)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 940, in async_run_hass_job
    hassjob.target(*args)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 463, in _handle_results
    self.async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1023, in async_write_ha_state
    self._async_write_ha_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1148, in _async_write_ha_state
    self.__async_calculate_state()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1085, in __async_calculate_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1029, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 642, in state
    raise ValueError(
    ...<5 lines>...
    ) from err
ValueError: Sensor sensor.current_power_delivery has device class 'power', state class 'None' unit 'W' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)

Additional information

No response

@mib1185
Copy link
Contributor

mib1185 commented Jan 7, 2025

This issue seems to be caused by an template sensor, which does not proper handle the unavailable state, but expect it to always be an integer?

@tj551955
Copy link
Author

tj551955 commented Jan 8, 2025

Yes, you are right. My own fault. I found the sensor and changed it to work correctly. Thank you very much.
If I may ask, what in the error message pointed you to the template sensor?

@mib1185
Copy link
Contributor

mib1185 commented Jan 8, 2025

glad to hear, you found and fixed the issue on your own 👍
the line File "/usr/src/homeassistant/homeassistant/components/template/template_entity.py", line 463, in _handle_results indicated, that an template sensor is involved 😉

@tj551955
Copy link
Author

tj551955 commented Jan 8, 2025

Thank you.

@tj551955 tj551955 closed this as completed Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants