core icon indicating copy to clipboard operation
core copied to clipboard

Modbus sensors logging warnings for non-numeric value: unavailable (<class 'str'>) on 2023.2.0b4

Open drthanwho opened this issue 2 years ago • 12 comments

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

drthanwho avatar Jan 29 '23 23:01 drthanwho

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

realthk avatar Feb 01 '23 22:02 realthk

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 avatar Feb 02 '23 07:02 jbouwh

@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?

realthk avatar Feb 02 '23 18:02 realthk

It seems the literal string "unavailable" is assigned to the state, that causes the warning, assign None instead.

jbouwh avatar Feb 02 '23 20:02 jbouwh

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.

jbouwh avatar Feb 02 '23 20:02 jbouwh

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)

home-assistant[bot] avatar Feb 02 '23 20:02 home-assistant[bot]

hmm that is clearly a bug, I will take a look later.

janiversen avatar Feb 02 '23 20:02 janiversen

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

rfpronk avatar Feb 03 '23 11:02 rfpronk

That is not my concern, please raise other issues so they get allocated to the correct integrations.

janiversen avatar Feb 03 '23 11:02 janiversen

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.

rfpronk avatar Feb 03 '23 12:02 rfpronk

Pull request #87519 might clear this issue soon.

realthk avatar Feb 06 '23 09:02 realthk

@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.

emontnemery avatar Feb 06 '23 13:02 emontnemery