3 months ago I added python3 code to four raspberry pi’s, to query for updates.
The results of “sudo apt update” are sent to HA via MQTT.
I use MQTT Discovery to create the devices.
I do not have any manual yaml for MQTT in configuration.yaml.
I created the four dashboard cards using the “Add To Dashboard” in the core-mosquitto MQTT integration.
Everything worked fine until the 2023.5.2 update
I am using a Raspberry Pi 3b with the default 64 bit installation.
All HA updates applied.
The messages are getting through and look correct in the Device info/MQTT Info dialog box.
The card displays “Unknown” where it used to show the update status.
This error is in the logs.
Logger: homeassistant.components.mqtt.models
Source: components/sensor/__init__.py:583
Integration: MQTT (documentation, issues)
First occurred: May 9, 2023 at 8:39:11 AM (9 occurrences)
Last logged: 8:42:48 AM
Exception raised when updating state of sensor.updates_2, topic: 'check4updates/iHackAutomation/updates' with payload: b'1 package can be upgraded\n'
Exception raised when updating state of sensor.updates, topic: 'check4updates/iHackPlexMediaServer/updates' with payload: b'8 packages can be upgraded\n'
Exception raised when updating state of sensor.updates_4, topic: 'check4updates/iHackPi/updates' with payload: b'1 package can be upgraded\n'
Exception raised when updating state of sensor.updates_3, topic: 'check4updates/iHackWeb/updates' with payload: b'7 packages can be upgraded\n'
Exception raised when updating state of sensor.updates_2, topic: 'check4updates/iHackAutomation/updates' with payload: b'All packages are up to date\n'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
numerical_value = float(value) # type:ignore[arg-type]
ValueError: could not convert string to float: 'All packages are up to date\n'
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 585, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
raise ValueError(
ValueError: Sensor sensor.updates_2 has device class None, state class None unit and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: All packages are up to date
(<class 'str'>)
unit of measure is = ’ ’
That includes a space
in Discovery message
Tried the following just now
= None
generated script error
= “”
same float to string error
Logger: homeassistant.components.mqtt.models
Source: components/sensor/__init__.py:583
Integration: MQTT (documentation, issues)
First occurred: 11:18:35 AM (3 occurrences)
Last logged: 11:27:24 AM
Exception raised when updating state of sensor.updates_2, topic: 'check4updates/iHackAutomation/updates' with payload: b'All packages are up to date\n'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 581, in state
numerical_value = float(value) # type:ignore[arg-type]
ValueError: could not convert string to float: 'All packages are up to date\n'
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 585, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 649, in _async_write_ha_state
state = self._stringify_state(available)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 591, in _stringify_state
if (state := self.state) is None:
File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 583, in state
raise ValueError(
ValueError: Sensor sensor.updates_2 has device class None, state class None unit and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: All packages are up to date
(<class 'str'>)
In the 7th line of log …with payload:b’All pack…
where did the b come from???
not in line 13
I added str(results of sudo apt update) to ensure the returned value was only a string when this problem poped up.
This all worked fine just a little while ago…
Looking at the HA documents for MQTT Discovery sensor
All the unit_of_measure does is put the character specified at the end of the payload.
SO
unit_of_measure = “%”
would make a temperature payload read 98% instead of 98
My use of a space in the past worked fine.
I just tried “.” to put a period at the end of the payload string.
The card still says Unknown
BTW after a reboot of HA the cards say Unavailable until my scripts run.
I will try that.
AND
The documentation for the optional unit_of_mesurement should include a comment that any value of unit_of_measurement will also set a flag that the payload will be a floating point number.
unit_of_measurement string (optional, default: None)
Defines the units of measurement of the sensor, if any. The unit_of_measurement can be null.
Python does not accept a null value
I tried
unit_of_measurement =
This should have invoked the Default None
AND
unit_of_measurement = None
Both threw exceptions.
Not including a unit_of_measurement string in the Discovery payload fixed the issue of the payload data being displayed on the card,
I think HA handled this properly in a previous version, and now is missing a validation somewhere.
Where do I go to suggest a solution?