maxym
June 4, 2025, 11:56am
1
Yesterday 2 modbus based sensors went crazy, reporting surrealistically hight values of injected and purchased energy
In log I found the error reported at that exact moment.
2025-06-03 13:31:47.953 WARNING (MainThread) [pymodbus.logging] Unable to decode frame Modbus Error: [Input/Output] byte_count 4 > length of packet 1
2025-06-03 13:31:47.954 ERROR (MainThread) [homeassistant] Error doing job: Fatal error: protocol.data_received() call failed. (None)
Here is a definition of that sensor:
- name: Wattsonic Total Energy injected to grid
unique_id: wattsonic_total_energy_injected_to_grid
slave: 247
address: 31102
scale: 0.1
precision: 1
input_type: holding
unit_of_measurement: kWh
state_class: total_increasing
device_class: energy
data_type: int32
scan_interval: 600
Do we know how it is possible that it happened? Is it known modbus issue? Is it avoidable?
Is it something that can be set in modbus configuration/communication to prevent such issues?
HA core 2025.5.3
petro
(Petro)
June 4, 2025, 12:08pm
2
Your device screwed up and sent bad values, are you sure that address is an int32
?
use min_value
and max_value
. That doesn’t look like a nan_value
for int32, so I don’t think that will help.
maxym
June 4, 2025, 12:21pm
3
Thanks for prompt reaction.
our device screwed up and sent bad values
Could be, it’s made in China… Or intermediate communication device screwed that (it’s hardwired to the inverter, then communicates via wifi with HA)
Your device screwed up and sent bad values, are you sure that address is an int32
?
TBH I don’t know. I use modbus config for Wattsonic Gen3 prepared by someone else.
However, I would expect that an intercepted error results in recording no data, rather than damaged data. I saw this error several times before, but I never noticed that it caused data damage (since the inverter installation 9 months ago)
Granted, it’s possible that the HA recognized an error for some sensors and pick bad data for others at the same time. Unfortunately, the log provides no information about sensors or the Modbus address involved.
petro
(Petro)
June 4, 2025, 12:25pm
4
The error is telling you the value received is over 4 bytes, but you configured it for 4 bytes (int32). So your output comes from the configured 4 bytes. Regardless of that, the value would have been much larger but your configuration stopped that. So add a max_value to remove values larger than what you’d expect.
maxym
June 4, 2025, 12:35pm
5
Documentation found on that page mentions 31102 address as U32 datatype, which I assume is an unsigned 4-bytes int. I have no access to official documentation, makingit it possible that something changed since then (there were fw updates)
Thanks for the suggestion. Worth thinking about that. Including the rest of 90 modbus sensors
maxym
June 4, 2025, 1:19pm
7
petro:
In32 is signed fyi
Yeah… then it should be declared as uint32.
However I doubt it could be the reason. Negative value reported by the inverter (besides it’s not expected in this case) could lead to big numbers, but wouldn’t trigger the error, isn’t it?
petro
(Petro)
June 4, 2025, 1:32pm
8
No, it won’t trigger any errors because it’s just reading and applying the bytes. The bytes don’t actually hold a minus sign, the largest bit (0 or 1) is treated as positive or negative. So you’ll just get a different result
I’d suggest to get the modbus tester from this side (in case you have a windows machine at hand)
In case you’re unsure about things such as BE LE, byte-swapped, int, uint since you could try changes smoothly without modifiying YAML code to see the results.
Comes with a bunch of nice features such as live chart.
maxym
June 4, 2025, 4:49pm
10
Can you point me to how should I use it to help with my situation, considering that what I exprienced happens very rarelly?
Also, can I connect this tool to the Inverter at the same time HA is connected?
In HA connection is defined as:
pkg_wattsonic:
modbus:
- name: wattsonic
type: tcp
host: 192.168.107.40
port: 502
maxym
June 4, 2025, 4:58pm
11
Ha… it seems it’s known modbus integration issue, manifesting when communication takes a bit longer. Then modbus reports random/erroneous values to sensors
opened 06:55AM - 17 Nov 24 UTC
problem in dependency
integration: modbus
### The problem
When polling Holding Registers, response values get Randomly… assigned to another slave entity of the same Modbus Client.

The Sensor is always sending 0, the Peaks in the graph are exactly the numbers previously read from another slave.
Note the right sequence number but with wrong slave address and data in the Debug output:
```
send: 0x18 0xe0 0x0 0x0 0x0 0x6 **0x12** 0x3 0x1 0xe 0x0 0x2
recv: 0x18 0xe0 0x0 0x0 0x0 0x7 **0xd** 0x3 0x4 0x0 0x0 0x0 0x0
```
Data on the Network looks fine according to Wireshark. This Issue seems to sit deep in the parser before the debug output.
Even if such packets were to be sent from a TCP client, they should be discarded because of the mismatch in the slave address.
I tried to dig in the Modbus Parser Code, but Several layers with Asynchronous execution are a little overwhelming for me at the moment. But I am happily providing as much info as neccessary.
### What version of Home Assistant Core has the issue?
core-2024.11.2
### 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
https://www.home-assistant.io/integrations/modbus/
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
modbus:
- name: modbus_hub
type: tcp
host: 192.168.12.160
port: 8888
delay: 60
timeout: 5
sensors:
- name: E_S5_P11_W_S1
slave: 18
address: 0x104
input_type: holding
unit_of_measurement: W
device_class: power
state_class: measurement
scale: 1
offset: 0
precision: 0
data_type: int32
scan_interval: 60
- name: E_S5_P12_A_S2
slave: 13
address: 0x102
input_type: holding
unit_of_measurement: A
device_class: current
state_class: measurement
scale: 0.001
offset: 0
precision: 3
data_type: int32
scan_interval: 60
```
### Anything in the logs that might be useful for us?
```txt
2024-11-17 06:36:19.815 DEBUG (MainThread) [pymodbus.logging] Adding transaction 6368
2024-11-17 06:36:19.815 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer -
2024-11-17 06:36:19.815 DEBUG (MainThread) [pymodbus.logging] send: 0x18 0xe0 0x0 0x0 0x0 0x6 0x12 0x3 0x1 0xe 0x0 0x2
2024-11-17 06:36:19.931 DEBUG (MainThread) [pymodbus.logging] recv: 0x18 0xe0 0x0 0x0 0x0 0x7 0xd 0x3 0x4 0x0 0x0 0x0 0x0 old_data: addr=None
2024-11-17 06:36:19.931 DEBUG (MainThread) [pymodbus.logging] Processing: 0x18 0xe0 0x0 0x0 0x0 0x7 0xd 0x3 0x4 0x0 0x0 0x0 0x0
2024-11-17 06:36:19.931 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-11-17 06:36:19.931 DEBUG (MainThread) [pymodbus.logging] Getting transaction 6368
2024-11-17 06:36:19.931 DEBUG (MainThread) [pymodbus.logging] Very short frame (NO MBAP): wait for more data
```
### Additional information
Possibly related to several previous unsolved Modbus outlier issues such as
https://github.com/home-assistant/core/issues/119649
https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/issues/299
https://github.com/binsentsu/home-assistant-solaredge-modbus/issues/126
https://github.com/home-assistant/core/issues/87876
opened 02:50PM - 09 Feb 25 UTC
integration: modbus
### The problem
Hello,
I updated my HA last week (from 2025.1.x to 2025.2.1) an… d since then I have issue with my Modbus sensor which record erroneous spikes.
It matches the update of the pyModbus library as well.
It used to work flawlessly but now I have regular issues.
What I noticed is that I am getting erroneous value, for example room temperature jumping multiple degrees or flowsensor jumping from 0 to a value for just 1 frame.
It looks like this value is the answer from another request.
**This only happens when the Modbus telegram is sent again after 3sec (probably due to timeout).**
Is there a way to avoid sending this new telegram after timeout ? (I am polling values each 10s anyway)
Before / after HA update:
<img width="948" alt="Image" src="https://github.com/user-attachments/assets/f2958fc5-189e-4ebd-a34d-0a34fab6bf04" />
Errors over 2h:
<img width="948" alt="Image" src="https://github.com/user-attachments/assets/82f9eb8a-97de-4d35-b475-5ddbebb30008" />
Now the interesting part: this spikes are only generated when the request is repeated.
Here are 2 examples:
* 30°C could well be the temperature from the "Retour condensateur"
<img width="1913" alt="Image" src="https://github.com/user-attachments/assets/41dd3a32-0936-42f3-a8a2-0e381f7316d7" />
* 32°C could well be the temperature from the "Ballon"
<img width="1911" alt="Image" src="https://github.com/user-attachments/assets/49f7bb52-d0a5-473e-9319-d7de6384a9b4" />
A few other examples:
<img width="747" alt="Image" src="https://github.com/user-attachments/assets/bd6b7983-65e9-43f9-bbf3-985f9d304a9c" />
<img width="748" alt="Image" src="https://github.com/user-attachments/assets/b7224127-415a-4786-9551-d530951f565f" />
<img width="748" alt="Image" src="https://github.com/user-attachments/assets/7ddb0347-0557-47a4-ae31-fcbecf19c479" />
### What version of Home Assistant Core has the issue?
core-2025.2.1
### What was the last working version of Home Assistant Core?
core-2025.1.x
### 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
It looks like as soon as a Modbus frame is repeated (due to timeout), the next Modbus telegram is taken as answer.
This leads to value mixing between MB sensors.
The sequence of Modbus frame seems to be off.
A first approach would be to disable the Modbus timeout and wait for the next polling.
### Example YAML snippet
```yaml
"""yaml
# Read info from PAC
modbus:
- name: PAC
type: tcp
host: 192.168.1.23
port: 502
sensors:
- name: Température extérieure
slave: 1
address: 1003
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: Température départ condensateur
slave: 1
address: 1004
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: Température retour condensateur
slave: 1
address: 1005
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: Débit capteur
slave: 1
address: 1020
input_type: holding
unit_of_measurement: l/min
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: Température ballon
slave: 1
address: 1100
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: PAC Temp Z1 appartement
slave: 1
address: 1111
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: PAC Temp Z2 Culte RdC
slave: 1
address: 1121
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: PAC Temp Z3 Culte sous-sol 1er
slave: 1
address: 1131
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: PAC Temp Z4 salle fête
slave: 1
address: 1141
input_type: holding
unit_of_measurement: °C
state_class: measurement
scale: 0.1
offset: 0
precision: 1
scan_interval: 10
- name: PAC état
slave: 1
address: 102
input_type: holding
state_class: measurement
scale: 1
offset: 0
precision: 0
scan_interval: 10
switches:
- name: Appartement
slave: 1
address: 6011
command_on: 1
command_off: 4
write_type: holding
verify:
- name: Salle culte
slave: 1
address: 6012
command_on: 1
command_off: 4
write_type: holding
verify:
- name: Sous-sol
slave: 1
address: 6013
command_on: 1
command_off: 4
write_type: holding
verify:
- name: Salle fête
slave: 1
address: 6014
command_on: 1
command_off: 4
write_type: holding
verify:"""
```
### Anything in the logs that might be useful for us?
```txt
Log covering both event (14:48:15 and 14:50:27):
2025-02-09 14:48:10.910 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2025-02-09 14:48:10.910 DEBUG (MainThread) [pymodbus.logging] send: 0x1d 0xf 0x0 0x0 0x0 0x6 0x1 0x3 0x4 0x4c 0x0 0x1
2025-02-09 14:48:13.911 DEBUG (MainThread) [pymodbus.logging] send: 0x1d 0xf 0x0 0x0 0x0 0x6 0x1 0x3 0x4 0x4c 0x0 0x1
2025-02-09 14:48:14.377 DEBUG (MainThread) [pymodbus.logging] recv: 0x1d 0xf 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x1 0x40 old_data: addr=None
2025-02-09 14:48:14.378 DEBUG (MainThread) [pymodbus.logging] Processing: 0x1d 0xf 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x1 0x40
2025-02-09 14:48:14.378 DEBUG (MainThread) [pymodbus.logging] decoded PDU function_code(3 sub -1) -> ReadHoldingRegistersResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[], registers=[320], status=1)
2025-02-09 14:50:22.693 DEBUG (MainThread) [pymodbus.logging] Frame advanced, resetting header!!
2025-02-09 14:50:22.693 DEBUG (MainThread) [pymodbus.logging] send: 0x1d 0xb0 0x0 0x0 0x0 0x6 0x1 0x3 0x3 0xed 0x0 0x1
2025-02-09 14:50:25.695 DEBUG (MainThread) [pymodbus.logging] send: 0x1d 0xb0 0x0 0x0 0x0 0x6 0x1 0x3 0x3 0xed 0x0 0x1
2025-02-09 14:50:26.708 DEBUG (MainThread) [pymodbus.logging] recv: 0x1d 0xb0 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x1 0x2c old_data: addr=None
2025-02-09 14:50:26.708 DEBUG (MainThread) [pymodbus.logging] Processing: 0x1d 0xb0 0x0 0x0 0x0 0x5 0x1 0x3 0x2 0x1 0x2c
2025-02-09 14:50:26.708 DEBUG (MainThread) [pymodbus.logging] decoded PDU function_code(3 sub -1) -> ReadHoldingRegistersResponse(dev_id=0, transaction_id=0, address=0, count=0, bits=[], registers=[300], status=1)
```
### Additional information
Full log attached covering both events:
[home-assistant_modbus_2025-02-09T14-25-35.079Z.log](https://github.com/user-attachments/files/18724847/home-assistant_modbus_2025-02-09T14-25-35.079Z.log)
While one of issues has been reported in Nov’24, other points to Feb’25 release providing graph with timing since when the issues have escalated.
Possible woraround is to extend timout settings
timeout: 9
message_wait_milliseconds: 200
But IMO the current behaviour which records invalid values due to timeout is critical one, although not picked by modbus devs till today.
One of reports is deep enough that proves that the assigned value comes from the other sensor (address). If true it’s really serious issue.
In case you read multiple addresses from the very same device, ever tried using
count: + data_type: custom + structure: “><python struct>” ?
It surely frees the modbus since splitting the bunch of received values is done at a later stage where modbus could idle again.
maxym
June 4, 2025, 8:45pm
13
Not sure what do you mean and who this message is directed for.
But if you have knowledge maybe you are a proper person to help devs to resolve that.