core: Modbus incorrect reading multiple registers & swap: word & slave_count > 0
The problem
If the data of one sensor occupies more than one register, then when using “slave_count” > 0, the data is written to the sensors in reverse. For example, int32 occupies 2 registers: 6160 and 6161 Reading these registers we get: [AB][CD][EF][GH] After “swap: word” we get: [GH][EF][CD][AB]
Ok. But if we use this configuration:
address: 6160
slave_count: 2
count: 6
data_type: int32
swap: word
Then we read 6 registers. And we get: [AB][CD][EF][GH] [IG][KL][MN][OP] [QR][ST][UV][XY] => [XY][UV][ST][QR] [OP][MN][KL][IG] [GH][EF][CD][AB] And the value that should be in the last sensor is written to the first sensor: [XY][UV][ST][QR] (from registers 6164, 6165) But it’s not right. The first sensor should have the value: [GH][EF][CD][AB] (from registers 6160, 6161) That is, we must divide the received data into an array (size of 1 element = data_type) and then do a swap word in a loop. This is only if slave_count > 0.
What version of Home Assistant Core has the issue?
core-2023.8.0
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Supervised
Integration causing the issue
modbus
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
- name: map12e_voltage_peak
unique_id: map12e_voltage_peak
scan_interval: 30
slave: 46
address: 6160
slave_count: 2
count: 6
input_type: input
data_type: int32
scale: 0.01
swap: word
state_class: measurement
device_class: voltage
unit_of_measurement: V
Anything in the logs that might be useful for us?
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (8 by maintainers)
Confirmed
swap works on the received data, and thus converts correctly. This is how it is supposed to work.
However you have made a nice case, why it should work differently with slaves > 0. This is really an enhancement, but we will make a fix for a later HA release.