-
-
Notifications
You must be signed in to change notification settings - Fork 28.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modbus - Exception since 2023.5.0: state class None: numeric value, however, it has the non-numeric value. #93297
Comments
Hey there @adamchengtkc, @janiversen, @vzahradnik, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) modbus documentation |
as pr documentation please supply a debug log, so we have a chance of seeing what is happening. Apart from that I suspect this could be caused by an outside change made by the core team, can you please confirm in which version it worked. There have not been changes to the modbus integration in the latest releases. |
Thanks, I've enabled debug for Modbus, but there's not much additional info in the logs, see below for a full copy/paste. As above, it was working with 2023.4.6, but broke with 2023.5.0
Yes, seems a breaking change to the core, many integrations are having this issue. Refer to this post.. Here's another integration fixing the issue. Let me know if I can assist further / with testing. |
Just checked the code, the modbus integration do not produce the "nan", that is a conversion in core, when native_value is None (which happens when there are e.g. read errors). I have no idea how to solve this at integration level, converting None to 0 is for many configurations just false, I think it needs to be solved at core level. |
You have a very interesting idea, actually there is a pull request open that does something similar, but I think the developer abandoned it. It would be easy for the modbus integration to make the conversion to None, I will take a look at it later. Thanks for the analysis. |
I've done little to zero python, only C# and industrial control systems.. but.. might be able to do something like this?.. please ignore if incorrect. I'm unable to test it for now, I'll have a go on the weekend (no dev environment setup, and the custom_component override is not working) def a function to check if NaN is equal to its self, as it never is... and other python methods need to use imports, like import Math
and I think this is where you're reading in the registers before passing them off... but just a guess.
|
I am not sure what you want to tell with these lines of code, if you believe that is a fix, then you need to submit a PR, and if you want to teach us, well that is really not needed (at least not at that level). I will take a deeper look, but it will be later, since I have a couple of others to help first. |
... I was just trying to help.. no need to be condescending. In the unlikely event the above works I'll submit a PR request. |
I actually just was factual but read your comment as "teaching". Looking forward to see a PR, which I can review. |
Apologies, that was not my intent. Just thinking out loud. It seems this is defaulting to a string value when the floats are returning 'nan'
Adding the following after result is set handles the issue before an exception is thrown..
I've never done a PR.. so I'll have a read up on it and submit it tomorrow. Update... Maybe 'nan' should be handled in |
home-assistant#93297 Replace NaN with None in unpack_structure_result
I made a mistake on the first PR. re-did another.. not sure what has happened.. apologies.. The code works.. any guidance on what I did wrong regarding the PR would be appreciated... |
Third time's a charm.. I think it's ready to be reviewed. Thanks |
The problem
The issue is introduced in 2023.5, without any config changes
ValueError: Sensor sensor.inverter_apparent_power has device class None, state class None unit VA and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: nan (<class 'str'>)
What version of Home Assistant Core has the issue?
2023.5.0
What was the last working version of Home Assistant Core?
2023.4.6
What type of installation are you running?
Home Assistant OS
Integration causing the issue
Modbus
Link to integration documentation on our website
https://www.home-assistant.io/integrations/modbus/
Diagnostics information
Example YAML snippet
Anything in the logs that might be useful for us?
No response
Additional information
Modbus component needs to "be adjusted to strip nan values."
#92483 (comment)
The text was updated successfully, but these errors were encountered: