core
core copied to clipboard
Modbus sensors logging warnings for non-numeric value: unavailable (<class 'str'>) on 2023.2.0b4
The problem
The following warnings are logged for modbus sensors on the 2023.0 beta. But there is no availability setting or anything along those lines to fix this manually
What version of Home Assistant Core has the issue?
core-2023.2.0b4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
modbus
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
- name: Siemens Current a
address: 13
slave: 1
data_type: float32
unit_of_measurement: A
precision: 2
device_class: current
- name: Siemens Current b
address: 15
slave: 1
data_type: float32
unit_of_measurement: A
precision: 2
device_class: current
- name: Siemens Current c
address: 17
slave: 1
data_type: float32
unit_of_measurement: A
precision: 2
device_class: current
Anything in the logs that might be useful for us?
2023-01-29 20:11:31.366 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.siemens_current_a has device class current, state class None and unit A thus indicating it has a numeric value; however, it has the non-numeric value: unavailable (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+modbus%22
2023-01-29 20:11:31.387 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.siemens_current_b has device class current, state class None and unit A thus indicating it has a numeric value; however, it has the non-numeric value: unavailable (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+modbus%22
2023-01-29 20:11:31.392 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.siemens_current_c has device class current, state class None and unit A thus indicating it has a numeric value; however, it has the non-numeric value: unavailable (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+modbus%22
2023-01-29 20:11:31.403 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.siemens_average_current has device class current, state class None and unit A thus indicating it has a numeric value; however, it has the non-numeric value: unavailable (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+modbus%22
Additional information
No response
Same here since today's 2023.2 to all my modbus sensors. Seems to be a bug, "unavailable" state should not be checked against valid values, as all Modbus sensors are unavailable at start.
MQTT sensors seems to have similar issue with empty values: https://github.com/home-assistant/core/pull/87004
Have a look at https://github.com/home-assistant/core/pull/87013 that was recently merged. The sensor entity now has a new protected property _numeric_state_expected
that can be used to determine the sensor expects numeric values.
@jbouwh Do you reckon it could help? Because I guess the problem is that the status is validated if it is a numeric value, which "unavailable" is not - and it won't be affected by a property like this.
Or does it mean if the sensor entity was set up with numeric_state_expected
then it won't be validated?
It seems the literal string "unavailable"
is assigned to the state, that causes the warning, assign None
instead.
You can use entity._numeric_state_expected
to check if a sensor expects a number or None
. If a non numeric string is assigned the warning will popup.
Hey there @adamchengtkc, @janiversen, @vzahradnik, mind taking a look at this issue as it has been labeled with an integration (modbus
) you are listed as a code owner for? Thanks!
Code owner commands
Code owners of modbus
can trigger bot actions by commenting:
-
@home-assistant close
Closes the issue. -
@home-assistant rename Awesome new title
Change the title of the issue. -
@home-assistant reopen
Reopen the issue. -
@home-assistant unassign modbus
Removes the current integration label and assignees on the issue, add the integration domain after the command.
(message by CodeOwnersMention)
modbus documentation modbus source (message by IssueLinks)
hmm that is clearly a bug, I will take a look later.
Same is happening to other parts aside modbus, eg with the uptime sensor
2023-02-03 12:03:51.992 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.system_uptime has device class None, state class measurement and unit None thus indicating it has a numeric value; however, it has the non-numeric value: 002+02:29:08.848 (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mqtt%22
or data from the HA iOS app
2023-02-03 12:03:33.085 WARNING (MainThread) [homeassistant.components.sensor] Sensor sensor.ipad_robin_battery_state has device class battery, state class None and unit None thus indicating it has a numeric value; however, it has the non-numeric value: Not Charging (<class 'str'>); Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+mobile_app%22
That is not my concern, please raise other issues so they get allocated to the correct integrations.
That is not my concern, please raise other issues so they get allocated to the correct integrations.
Sorry it wasn't my intention to put it on your plate, I just wanted to indicate that probably something more generic broke or changed.
Pull request #87519 might clear this issue soon.
@realthk no, issue #87519 will not fix this.
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.