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: Image

Errors over 2h: Image

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” Image
  • 32°C could well be the temperature from the “Ballon” Image

A few other examples: Image

Image Image

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:

home-assistant_modbus_2025-02-09T14-25-35.079Z.log

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 4
  • Comments: 77 (22 by maintainers)

Most upvoted comments

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:

modbus:
  - name: PAC
    type: tcp
    host:192.168.1.23
    port: 502
    timeout: 9
    message_wait_milliseconds: 200

Result over last day:

Image

The handling problem of repeated frames is probably still there though, I just hid it by increasing the timeout.

Leute, warum Englisch, wenn hier meistens Deutsche Interesse haben und Trump die Sprache zum no go macht 🤷🏼‍♂️.

Zum Thema: Mit Abfrage via COM Port (Waveshare) und NICHT dem schlechten Dongle Modbus UND nur der wirklich benötigten Entitäten, läuft ALLES auch unter neuster FW, HA und Addon/Integrationen = whatever, so stabil wie nie zuvor. Spikes = Datenfehler… da zu viel, zu langsam usw. abgefragt wird. Das wurde doch schon länger oft klar und zumindest funktionierend per Updates gelöst.

Wer nun deutsch moniert… use Google Translation or bust 😎. Denn mir reicht es inzwischen mit Manchen dermaßen… 🤣☝️.

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.

  1. it seems the current HA modbus integration have a competing implementation to that in pymodbus
  2. Just read the API changes and release notes, 3.7 -> 3.8 introduced a number of new concepts some of which have influence on the HA modbus integration
  3. That is absolutely NOT true…v3.9.0 reported several API changes !!

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:

  1. timeouts play a fundamental role. And I can add that also the retries have the same importance and probably that parameter should be not hardcoded as it is now.
  2. the new transaction concept calls for changes in the app, something that seems missing in the modbus integration This 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?
  3. 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:

  • v3.8.0 to v3.8.5 have known problems, some affect the transaction handling, so upgrade is recommended
  • the new transaction concept calls for changes in the app, something that seems missing in the modbus integration

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.

The evidence strongly indicates a regression in the pymodbus library’s Modbus TCP transaction handling introduced in v3.8.x. In particular, the new TransactionManager and framing logic (added in 3.8.0) appear to mishandle delayed responses. When a request times out and is retried, a late-arriving response from the earlier attempt can be misinterpreted as the reply to a different query. This leads to cross-talk between sensor readings, i.e. a value from one register being delivered where another was expected​ github.com . The Home Assistant logs confirm this behavior: “It looks like this value is the answer from another request… only happens when the Modbus telegram is sent again after 3 sec (timeout)”​ github.com . In short, the client may not be properly discarding or segregating responses that come out-of-sync.

Two major changes in pymodbus 3.8.0 likely set the stage for this bug: a “new framer concept” and a “much simpler TransactionManager”​ github.com . The framer is responsible for parsing incoming bytes into Modbus messages, and the TransactionManager coordinates request/response pairs. The refactored code introduced stricter Modbus compliance checks (per the maintainer’s notes)​ github.com but also altered how the client buffers and matches responses. It appears that under certain conditions (especially with flaky TCP gateways like WiFi dongles), the new logic doesn’t flush or ignore a stale response. Instead, that stale data gets processed as if it were the current poll response, producing a one-time spike in the sensor reading (often matching a different sensor’s value).

Notably, multiple users across different Modbus setups (Solax, Sofar, Growatt, etc.) all observed erratic spikes after upgrading pymodbus. All report that rolling back to pymodbus 3.7.4 immediately cures the issue​ github.com . This strongly implicates changes between 3.7.4 and 3.8.0. Indeed, pymodbus v3.8.0’s release notes call out the new framer and TransactionManager as the largest overhaul since v3.0​ github.com . The symptoms – values “mixed from wrong sensor” – are consistent with a transaction ID or buffer management bug. If the library fails to match the response’s transaction ID to the request (or if it reuses the same ID on a retry without handling a late first response), a register read from an earlier query can be delivered to the next caller. The logs from Home Assistant’s Modbus integration show telltale signs: messages like “Frame advanced, resetting header!!” when a response arrives unexpectedly​ github.com , and the data old_data: addr=None being carried over, implying leftover bytes in the buffer​ github.com .

Other changes in 3.8.x are likely not the primary cause of these spikes but are worth noting. For example, v3.8.1 included an endianness overhaul (“Convert endianness”​ pymodbus.readthedocs.io ) and v3.8.0 deprecated the BinaryPayloadDecoder/Builder in favor of new utility functions​ pymodbus.readthedocs.io . These affect how multi-byte registers are decoded. If misused, they could yield incorrect values, but they would cause systematic errors (e.g. consistently swapped byte order or wrong scaling), not random transient spikes. The fact that the erroneous readings match valid values of other sensors (rather than nonsense data) points back to the transaction handling. In summary, a race condition or buffer mix-up in the new TransactionManager/Framer is the suspected root cause of the unstable peaks in the readings.

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).

wills106/homeassistant-solax-modbus#1238

@steps56 unfortunately this is not solution, as you can see, many has different problems with different vendors and solutions. There is something not managed properly in the modbus library since the switch from 3.7.4 to Version 3.8.3 (and tested also with 3.8.6), where all issues started, particularly for Solax integration. Haven’t tried yet 3.9.0 or 3.9.1 because it’s hard to clean up the mess later and not sure if there are not breaking changes, yet the change log is interesting : https://pymodbus.readthedocs.io/en/latest/source/changelog.html

@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:

Image

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/amodbus

While 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.