Since updating Home Assistant to > 2023.4 the entities provided by OMG through MQTT create plenty of errors like these:
2024-07-19 21:06:15.263 ERROR (MainThread) [homeassistant.components.mqtt.models] Exception raised when updating state of sensor.xiaomi_smart_band_7_mac, topic: 'OpenMQTTGateway/ESP_OMG_ABC/BTtoMQTT/XXXXXXXXX' with payload: b'{"id":"XX:XX:XX:XX:XX:XX","rssi":-98,"distance":45.0994,"brand":"Xiaomi/Amazfit","model":"Mi Band/Smart Watch","model_id":"MB/SW","type":"BODY","device":"Xiaomi/Amazfit Tracker","mac":"XX:XX:XX:XX:XX:XX"}'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
numerical_value = int(value)
^^^^^^^^^^
ValueError: invalid literal for int() with base 10: 'XX:XX:XX:XX:XX:XX'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/mqtt/models.py", line 270, in process_write_state_requests
entity.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.xiaomi_smart_band_7_mac has device class 'None', state class 'measurement' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'XX:XX:XX:XX:XX:XX' ()
if (state := self.state) is None:
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 585, in state
raise ValueError(
ValueError: Sensor sensor.xiaomi_smart_band_7_mac has device class 'None', state class 'measurement' unit 'None' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'XX:XX:XX:XX:XX:XX' ()
Therefore sensors are unknown:
This is due to more strict handlings of entities in HA Core:
Following other cases like MQTT Discovery, unit_of_measure · Issue #93071 · home-assistant/core · GitHub or homeassistant.components.mqtt.models · Issue #93059 · home-assistant/core · GitHub it seems the sensor attributes are sent wrong.
How can one run into such an issue when upgrading to a release after more than one year…
I tried to play a bit with setting the UoM and state_class manually using customize.yaml, unfortunately it made no difference. It is configured wrongly before already looking at the MQTT payload:
state_topic: +/+/BTtoMQTT/XXXXXXXXXXXX
name: MB/SW-mac
unique_id: XXXXXXXXXXXXX-mac
value_template: '{{ value_json.mac | is_defined }}'
state_class: measurement
device:
identifiers:
- XXXXXXXXXXXX
connections:
- - mac
- XXXXXXXXXXXX
manufacturer: Xiaomi/Amazfit
model: MB/SW
name: Mi Band/Smart Watch-XXXXXX
via_device: ESP_OMG_XYZ
platform: mqtt
So can you please take care and fix this in OMG so no rubbish data arrives at MQTT and in HA anymore?