ble_monitor: [Bug]: ValueError

What happened?

Lots of ValueError in the logs.

ValueError: Sensor sensor.ble_heart_rate_f5f5da96f7bc has device class 'None', state class 'measurement' unit 'bpm' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)

Already tried removing the integration, restart HA, install integration, restart HA.

Sensor type

No response

Relevant log output

2023-06-15 22:18:33.298 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform ble_monitor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity_platform.py", line 471, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_heart_rate_f5f5da96f7bc has device class 'None', state class 'measurement' unit 'bpm' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2023-06-15 22:18:33.311 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform ble_monitor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity_platform.py", line 471, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_steps_f5f5da96f7bc has device class 'None', state class 'total' unit 'steps' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2023-06-15 22:18:33.335 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity.py", line 970, in _async_registry_updated
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_heart_rate_f5f5da96f7bc has device class 'None', state class 'measurement' unit 'bpm' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2023-06-15 22:18:33.343 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity_platform.py", line 471, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_heart_rate_f5f5da96f7bc has device class 'None', state class 'measurement' unit 'bpm' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2023-06-15 22:18:33.356 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity.py", line 970, in _async_registry_updated
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_steps_f5f5da96f7bc has device class 'None', state class 'total' unit 'steps' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
2023-06-15 22:18:33.365 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, 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/helpers/entity_platform.py", line 471, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 749, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 850, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 590, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 654, in _async_write_ha_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.ble_steps_f5f5da96f7bc has device class 'None', state class 'total' unit 'steps' and suggested precision '0' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 30

Most upvoted comments

This is an bug in Home Assistant, please add your info in this issue

https://github.com/home-assistant/core/issues/86948

No, sorry, it is an issue in BLE monitor. A quote from on other issue

The problem is that modbus/sensor.py is extending RestoreEntity when it should instead extend RestoreSensor which stores the sensor’s native value instead of its state

I’ll look into it

Hi all. Sorry for my english, please) I had the same issue and that’s what i did to fix it.

  1. Run 2 queries in SQLite Web Addon:
DELETE
FROM statistics_short_term 
WHERE  statistics_short_term.metadata_id
IN ( SELECT statistics_meta.id FROM statistics_meta WHERE statistics_meta.statistic_id LIKE "sensor.ble_humidity%")
AND statistics_short_term.mean > 100
DELETE
FROM statistics
WHERE  statistics.metadata_id
IN ( SELECT statistics_meta.id FROM statistics_meta WHERE statistics_meta.statistic_id LIKE "sensor.ble_humidity%")
AND statistics.mean > 100
  1. Unchecked “Restore state after a restart”
  2. Restarted BLE Low Energy Monitor

After this steps all percent symbols returned back

Update. Of course you have to replace “sensor.ble_humidity%” with your actually name

@miguelangel-nubla Thanks for the logs. I see that the errors in your log only happen during the restart of the scanning process. The HCI scanning is restarted every minute (default period). Somehow, RSSI measurements and measured power (both in dBm) fail during that period. Strangely, @xelemorf in #1209 is saying that he still has sensors without unit of measurements. I’m still a bit lost where things go wrong, as I don’t see any of these errors.

2023-07-17 07:21:13.510 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: main event_loop stopped, finishing.
2023-07-17 07:21:13.514 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: Scanning will be restarted
2023-07-17 07:21:13.514 DEBUG (Thread-47) [custom_components.ble_monitor] 1163 HCI events processed for previous period
2023-07-17 07:21:13.514 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: Run
2023-07-17 07:21:13.521 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: BLEScanRequester._initialized is False for hci0,  waiting for connection...
2023-07-17 07:21:13.527 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.ble_rssi_8063ae90d8b711e695980800200c9a66 (<class 'custom_components.ble_monitor.sensor.MeasuringSensor'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('signal_strength') it is using; expected one of ['dB', 'dBm']; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.
2023-07-17 07:21:13.545 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: connected to hci0
2023-07-17 07:21:13.546 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: BLEScanRequester._initialized is True for hci0,  connection established, send_scan_request succeeded.
2023-07-17 07:21:13.546 DEBUG (Thread-47) [custom_components.ble_monitor] HCIdump thread: start main event_loop
2023-07-17 07:21:13.559 WARNING (MainThread) [homeassistant.components.sensor] Entity sensor.ble_measured_power_8063ae90d8b711e695980800200c9a66 (<class 'custom_components.ble_monitor.sensor.MeasuringSensor'>) is using native unit of measurement 'None' which is not a valid unit for the device class ('signal_strength') it is using; expected one of ['dB', 'dBm']; Please update your configuration if your entity is manually configured, otherwise report it to the custom integration author.