core: Modbus value spike issues since last update (2025.2.x) : values mixed from wrong sensor
The problem
Hello, I updated my HA last week (from 2025.1.x to 2025.2.1) and 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:
Errors over 2h:
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”
- 32°C could well be the temperature from the “Ballon”
A few other examples:
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
# 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?
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:
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 77 (22 by maintainers)
Small update: I tried to override the default timeout to let the device more time to answer and it looks like it helped as the spikes seems to have disappeared.
I changed the config by adding the 2 last lines:
Result over last day:
The handling problem of repeated frames is probably still there though, I just hid it by increasing the timeout.
Hlavně třeba proto, že ne celá Evropa mluví německy. Angličtina je starý jazyk který rozhodně nepatří Trumpovi. Jeho manželka mluví anglicky hůř než já.
Na fórech používáme angličtinu ze slušnosti abychom si všichni rozuměli. Německy se s vámi budu bavit až se potkáme v Praze na ulici. A to i přesto že tam mluví většina lidí česky.
🤷🤦
I have seen this problem myself https://github.com/home-assistant/core/issues/130791 I used another, slower mode in my slaves to work around the issue. This practically guarantees the packets will arrive in-order. This is also why this is popping up for different people with every HA core update, little changes in timing make the broken logic show its face. Core issue is the scheduling in pymodbus randomly mixing up responses despite of the received transaction ID. I did have a look in pymodbus but found more things i would rather change, so i decided not to debug further until I got enough time and energy to contribute improvements.
@janiversen I don’t think, that mentioning someone’s name in the thread related to his previous work deserve such harsh reply. We all would like to preferably address the active maintainer, but there is none. The issue was triggered by HA automatic bumping of the pymodbus versions, and is not being addressed for quite some time. So please understand desperate users to try to find literally anyone who would have knowledge to help.
You summarized the issue quite well. New versions of the pymodbus library need corresponding changes in the HA modbus integration. Especially to solve the edge case where no response or corrupted response is received. Based on my other experience with the Modbus integration I would say that the integration is due for overhaul. Some of the issues were fixed by bdraco, but as you can see the issue is getting more and more painful for users.
I am not saying that this is your fault, or that you shall solve it, but if you would point us in the proper direction how to solve this issue we would be very thankful.
Good luck, the changes needed are not as simple as “plugin and see if it starts” 😄
v3.7 -> v3.9 probably needs a good understanding of how the modbus protocol works, the problem is NOT getting it running, but all the corner cases and avoid memory leaks. There is a reason why pymodbus have 1.575 test cases.
One day, when the core developers have starts to review integrations to secure they behave well and not make other demands (like e.g. demanding internal variables be named device_id and not slave_id) , then I will consider coming back.
A pull request was opened (but not merged) in pymodbus https://github.com/pymodbus-dev/pymodbus/pull/2636 just to check if there are any issues in pymodbus.
Actually HA modbus integration has no maintainer. I bumped pymodbus 3.7.4 in January and on February someone else bumped the version 3.8.3. I tested both of them before the updates after having changed the relevant code of the modbus integration and no evidences of spikes or other failures have been logged on my side until now. (I’m currently addressing 50 modbus devices, some of those using a serial line, others by Tcp). Actually I’m running pymodbus 3.9.1 in my home installation for a possible upgrade of the modbus integration.
I’m reading with an high interest the last part of this thread because to have the possibility to interact directly with @janiversen could help us to understand what we have to improve in modbus integration.
I fixed in my mind 3 points coming from this discussion:
the new transaction concept calls for changes in the app, something that seems missing in the modbus integrationThis part of the discussion is worrying me, because It seems we forgot to do something during the update pymodbus 3.8.3. @janiversen , what do you mean? Can I ask to spent some words in explaining that?I wonder how you checked v3.9.1 because it requires changes in the modbus integration just as v3.8.3 did.I’ve updated from 3.8.3 to 3.91 wothout changing a single line in the modbus integration and no API changes have been reported in pymodbus release notes. It is working in my env and I can declare that by changing the manifest will force the HA to update also underlying library. What I miss?Not correct! I have not contributed to the modbus integration in HA. I am the maintainer of pymodbus
Due to the modbus protocol definition catching delayed responses on a serial line is next to impossible, the only real prevention is a high timeout. v3.8.6 compared to v3.8.3 contains a number of bug fixes related to that.
In tcp/tls delayed responses should be discarded, however some devices do not handle the transaction id correctly (a retry is sent with the same tid and should be ignored by the device if already received). So again a proper timeout is essential.
I understand the pain of a single spike value completely messing with the historic recorder data (resetting counters) very well, I’ve spent two days fixing historic data in the energy dashboard and even wrote tool to help with that.
While I fully understand the principle of FOSS, it is beyond my skills to fix such complex integration. But I am more worried how easily the core HA component can get into an unsupported state, without any action from the main developers.
“pipe show” uses the manifest, but HA does not use manifest at runtime but gets the demanded versions from a central file.
I am not attacking anybody (only your rudeness in pinging me), fact still remain that the current pymodbus version have no open issues, so no maintainers felt the need to report an issue, which boils down to that the customer components most likely stopped using v3.8.3
the long message you posted have 2 points:
And don’t know how much relevant this summary is - if it’s nonsense, don’t attack me just because you can, not referring anyone in particular.
@shaarkys you should be able to apply the latest pymodbus without changes if you are currently running 3.8.3. The only possible breaking change seems to be related to the slave 0 management, now allowed only if it is real slave of the device. I’m currently testing 3.9.1 for a possible PR, so testing it also in your environment is a good and appreciated feedback .
Since I switched from unreliable Dongle Modbus (SolaX) to Com Port and Waveshare Connection, Modbus Communication, the setup never ever produced any spikes.
I’m at all newest versions of inverter FW SolaX 1.50/1.47 and HA core, supervisor and wills106 Integration.
My setup use timeout 16 sec. and polling 15/15/15 at the integration.
There are some threads about the same spike stuff here at wills github and in an other thread, all waveshare settings have been shown too.
I can say, that switching to reliable waveshare connection solved all spike problems made by unreliable Dongle SolaX modbus (which was never intended by SolaX to be used by something like the integration, but just for connection to china server by internet).
I don’t think its any problem of HA, its “just” the weak connection by dongle’s modbus, which is the spike/dropout root.
Screen shows all latest versilns in use at my 2 running HA at 2 places:
I can help out with the changes needed in this repo, however maintaining a library I don’t use and don’t have a real world test case for is beyond the scope of my abilities and time constraints. I don’t think I would be able to do a better job than someone who has experience using modbus devices and working with them.
Please keep in mind that all my contributions to Home Assistant are done in my free time.
I agree that there is a recent pattern of pymodbus updates
with undocumented breaking changes and issues. (edit: Its been pointed out that the breaking changes are being documented: see https://github.com/home-assistant/core/issues/138077#issuecomment-2725752336)causing frustration.The frustration has lead to some discussion in the developer community on discord of forking
pymodbus, however I’m not sure what the final result of those discussions have been. edit: there is a fork at https://github.com/UpstreamDataInc/amodbusWhile I understand your limitations in the testing of the modbus integration, I am unhappy about the current state of the integration. It seems to be more and more broken with each release, without too much hope that this state will improve in the future. If your limitation is only about not having access to modbus device I am ready to donate HW required to test. There are also modbus simulators available.