Closed Frantik85 closed 3 months ago
Hey there @janiversen, 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!
(message by CodeOwnersMention)
modbus documentation modbus source (message by IssueLinks)
That is not a bug, the service write to a register which is defined as 16bit which eguals UINT16, so it does not know how to convert a negative value.
Hey @janiversen , I am confused - in the communication matrix of the modbus in my heating it is clearly stated that it can use negative numbers. Also, int16 is not uint16 AFAIK or do you mean, that the modbus integration itself is only able to work with UINT16 internally?
A device typically interpret registers, e.g, many devices combine 2 registers to have a INT32 or UINT32, but that is a device definition. The modbus protocol defines a register as 16bit and not as int16 or uint16, and for that reason the service expects a UINT16.
The UINT16 was chosen because it is really 16bit. The integration and lib uses bytes internally, but that is difficult to handle in HA.
If you like the service to work differently Pull Requests are welcome, but please remember if you move away from writing a register users will expect support for int/float/string of different lengths 16/32/64.
hm, alright, understood. So I might work around this by converting my negativ numbers to the corresponding positive integer numbers. Say I want to apply an offset of "-1" this will result in a binary value: 65535 --> just tested this, and it worked. ^^ To be fair - this behavior is nevertheless unexpected ;)
Thx for your comment and help! I could dive into the code and see if I could work my way through to support signed integers too.
Not sure how this can be unexpected, the documentation states
(write_register) A single value or an array of 16-bit values. Single value will call modbus function code 0x06. Array will call modbus function code 0x10. Values might need reverse ordering.
nothing about int16.
The problem
I think I may have found a bug, though I am not sure - that's why I am here ;)
Situation:
used modbus configuration (excerpt):
the script used:
The error I get when I pass in negative values to this script: value must be at least 0 @ data['value'][0]
If you have further questions, please let me know!
What version of Home Assistant Core has the issue?
core-2024.5.2
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
No response
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response