Modbus Siemens PAC2220 integration - errno 104 connection reset by peer

Hi,
I would like to connect my Modbus TCP Siemens PAC2200 to retrieve some data which currently only the EV wallboxes are using. I am getting the error beneath:

Logger: pymodbus.logging
Source: components/modbus/modbus.py:398
First occurred: 15:16:30 (2 occurrences)
Last logged: 15:23:30

Connection to (192.168.0.9, 502) failed: [Errno 104] Connection reset by peer

I have added the beneath modbus sensors to my configurations.yaml:

modbus:
- name: "PAC2200"
  delay: 2
  type: tcp
  host: 192.168.0.9
  port: 502
  sensors:
    - name: “Active Power L1”
      slave: 1
      address: 25
      input_type: holding
      data_type: float32
      offset: 1
      count: 2
      unit_of_measurement: "W"
      device_class: "power"
      state_class: "measurement"
    - name: “Active Power L2”
      slave: 1
      address: 27
      input_type: holding
      data_type: float32
      count: 2
      offset: 1
      unit_of_measurement: "W"
      device_class: "power"
      state_class: "measurement"
    - name: “Active Power L3”
      slave: 1
      address: 29
      input_type: holding
      data_type: float32
      count: 2
      offset: 1
      unit_of_measurement: "W"
      device_class: "power"
      state_class: "measurement"
    - name: “Total active power”
      slave: 1
      address: 65
      input_type: holding
      data_type: float32
      count: 2
      offset: 1
      unit_of_measurement: "W"
      device_class: "power"
      state_class: "measurement"
      #

In the manual I have found these parmeters:

Any idea why the peer is resetting the connection?
The wallbox is using the PAC2200 successful through Modbus TCP.

Any idea who to solve this error? I have checked the settings for P2200, everything looks correct:

Hi,

did you solve your problem ? there a few things to do first set the debug mode on for the modbus component
debug

Try also to comment out the “count: 2” lines. in my case this was giving issues

1 Like

Hi,
No, I didn’t solved the issue yet.
Thanks for the tip to add a logger.
I am attaching the log:

2024-02-20 08:32:09.647 DEBUG (SyncWorker_13) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 56836)
2024-02-20 08:32:09.648 DEBUG (SyncWorker_13) [pymodbus.logging] Current transaction state - RETRYING TRANSACTION
2024-02-20 08:32:09.648 DEBUG (SyncWorker_13) [pymodbus.logging] Running transaction 4
2024-02-20 08:32:09.648 DEBUG (SyncWorker_13) [pymodbus.logging] SEND: 0x0 0x4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:09.650 DEBUG (SyncWorker_13) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:09.650 DEBUG (SyncWorker_13) [pymodbus.logging] Retry on empty response - 3
2024-02-20 08:32:09.650 DEBUG (SyncWorker_13) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:09.950 DEBUG (SyncWorker_13) [pymodbus.logging] Sleeping 0.3
2024-02-20 08:32:09.953 DEBUG (SyncWorker_13) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 56840)
2024-02-20 08:32:09.953 DEBUG (SyncWorker_13) [pymodbus.logging] SEND: 0x0 0x4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:09.955 DEBUG (SyncWorker_13) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:09.956 DEBUG (SyncWorker_13) [pymodbus.logging] Retry on empty response - 2
2024-02-20 08:32:09.956 DEBUG (SyncWorker_13) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:10.556 DEBUG (SyncWorker_13) [pymodbus.logging] Sleeping 0.6
2024-02-20 08:32:10.583 DEBUG (SyncWorker_13) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 56850)
2024-02-20 08:32:10.583 DEBUG (SyncWorker_13) [pymodbus.logging] SEND: 0x0 0x4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:10.585 DEBUG (SyncWorker_13) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:10.585 DEBUG (SyncWorker_13) [pymodbus.logging] Retry on empty response - 1
2024-02-20 08:32:10.585 DEBUG (SyncWorker_13) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:11.786 DEBUG (SyncWorker_13) [pymodbus.logging] Sleeping 1.2
2024-02-20 08:32:11.789 DEBUG (SyncWorker_13) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 56862)
2024-02-20 08:32:11.789 DEBUG (SyncWorker_13) [pymodbus.logging] SEND: 0x0 0x4 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:11.790 DEBUG (SyncWorker_13) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:11.791 DEBUG (SyncWorker_13) [pymodbus.logging] Processing: 
2024-02-20 08:32:11.791 DEBUG (SyncWorker_13) [pymodbus.logging] Frame check failed, ignoring!!
2024-02-20 08:32:11.791 DEBUG (SyncWorker_13) [pymodbus.logging] Getting transaction 4
2024-02-20 08:32:11.791 DEBUG (SyncWorker_13) [pymodbus.logging] Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
2024-02-20 08:32:11.791 DEBUG (SyncWorker_13) [homeassistant.components.modbus.modbus] Pymodbus: PAC2200: Error: device: 1 address: 65 -> Modbus Error: [Input/Output] [Errno 104] Connection reset by peer
2024-02-20 08:32:19.616 DEBUG (SyncWorker_4) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 37994)
2024-02-20 08:32:19.616 DEBUG (SyncWorker_4) [pymodbus.logging] Current transaction state - TRANSACTION_COMPLETE
2024-02-20 08:32:19.617 DEBUG (SyncWorker_4) [pymodbus.logging] Running transaction 5
2024-02-20 08:32:19.617 DEBUG (SyncWorker_4) [pymodbus.logging] SEND: 0x0 0x5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:19.617 DEBUG (SyncWorker_4) [pymodbus.logging] New Transaction state "SENDING"
2024-02-20 08:32:19.617 DEBUG (SyncWorker_4) [pymodbus.logging] Changing transaction state from "SENDING" to "WAITING FOR REPLY"
2024-02-20 08:32:19.620 DEBUG (SyncWorker_4) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:19.620 DEBUG (SyncWorker_4) [pymodbus.logging] Retry on empty response - 3
2024-02-20 08:32:19.620 DEBUG (SyncWorker_4) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:19.920 DEBUG (SyncWorker_4) [pymodbus.logging] Sleeping 0.3
2024-02-20 08:32:19.923 DEBUG (SyncWorker_4) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 37998)
2024-02-20 08:32:19.924 DEBUG (SyncWorker_4) [pymodbus.logging] SEND: 0x0 0x5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:19.927 DEBUG (SyncWorker_4) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:19.927 DEBUG (SyncWorker_4) [pymodbus.logging] Retry on empty response - 2
2024-02-20 08:32:19.928 DEBUG (SyncWorker_4) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:20.528 DEBUG (SyncWorker_4) [pymodbus.logging] Sleeping 0.6
2024-02-20 08:32:20.531 DEBUG (SyncWorker_4) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 38000)
2024-02-20 08:32:20.532 DEBUG (SyncWorker_4) [pymodbus.logging] SEND: 0x0 0x5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:20.533 DEBUG (SyncWorker_4) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:20.533 DEBUG (SyncWorker_4) [pymodbus.logging] Retry on empty response - 1
2024-02-20 08:32:20.533 DEBUG (SyncWorker_4) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:21.734 DEBUG (SyncWorker_4) [pymodbus.logging] Sleeping 1.2
2024-02-20 08:32:21.737 DEBUG (SyncWorker_4) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 38010)
2024-02-20 08:32:21.737 DEBUG (SyncWorker_4) [pymodbus.logging] SEND: 0x0 0x5 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [pymodbus.logging] Processing: 
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [pymodbus.logging] Frame check failed, ignoring!!
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [pymodbus.logging] Getting transaction 5
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [pymodbus.logging] Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"
2024-02-20 08:32:21.739 DEBUG (SyncWorker_4) [homeassistant.components.modbus.modbus] Pymodbus: PAC2200: Error: device: 1 address: 65 -> Modbus Error: [Input/Output] [Errno 104] Connection reset by peer
2024-02-20 08:32:29.618 DEBUG (SyncWorker_18) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 57668)
2024-02-20 08:32:29.618 DEBUG (SyncWorker_18) [pymodbus.logging] Current transaction state - TRANSACTION_COMPLETE
2024-02-20 08:32:29.618 DEBUG (SyncWorker_18) [pymodbus.logging] Running transaction 6
2024-02-20 08:32:29.618 DEBUG (SyncWorker_18) [pymodbus.logging] SEND: 0x0 0x6 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 08:32:29.618 DEBUG (SyncWorker_18) [pymodbus.logging] New Transaction state "SENDING"
2024-02-20 08:32:29.619 DEBUG (SyncWorker_18) [pymodbus.logging] Changing transaction state from "SENDING" to "WAITING FOR REPLY"
2024-02-20 08:32:29.619 DEBUG (SyncWorker_18) [pymodbus.logging] Transaction failed. ([Errno 104] Connection reset by peer) 
2024-02-20 08:32:29.619 DEBUG (SyncWorker_18) [pymodbus.logging] Retry on empty response - 3
2024-02-20 08:32:29.619 DEBUG (SyncWorker_18) [pymodbus.logging] Changing transaction state from "WAITING_FOR_REPLY" to "RETRYING"
2024-02-20 08:32:29.920 DEBUG (SyncWorker_18) [pymodbus.logging] Sleeping 0.3

is this the IP of your HA instance ?
the modbus seem to be on another IP range. did you check if there is a route setup for the modbus to reply ?

Indeed, 192.168.13.60 is the local IP of my HA instance.
192.168.0.9 is the IP address of my PAC2200.
I have an Ubiquiti EdgeRouter X between these two networks which has IP routes and firewall settings for the interconnection of these two networks.
I have noticed that sometimes the integration works:


But I have no clue why it starts some point in time, works for a few minutes or even hours and stops again.

I turned off PAC2200 device for a few seconds. Instantly afterwards the data flows in and the log shows:

2024-02-20 09:45:32.303 DEBUG (SyncWorker_59) [pymodbus.logging] Connection to Modbus server established. Socket ('192.168.13.60', 37162)
2024-02-20 09:45:32.303 DEBUG (SyncWorker_59) [pymodbus.logging] Current transaction state - TRANSACTION_COMPLETE
2024-02-20 09:45:32.303 DEBUG (SyncWorker_59) [pymodbus.logging] Running transaction 15
2024-02-20 09:45:32.304 DEBUG (SyncWorker_59) [pymodbus.logging] SEND: 0x0 0xf 0x0 0x0 0x0 0x6 0x1 0x3 0x0 0x41 0x0 0x2
2024-02-20 09:45:32.304 DEBUG (SyncWorker_59) [pymodbus.logging] New Transaction state "SENDING"
2024-02-20 09:45:32.304 DEBUG (SyncWorker_59) [pymodbus.logging] Changing transaction state from "SENDING" to "WAITING FOR REPLY"
2024-02-20 09:45:35.308 DEBUG (SyncWorker_59) [pymodbus.logging] Changing transaction state from "WAITING FOR REPLY" to "PROCESSING REPLY"
2024-02-20 09:45:35.308 DEBUG (SyncWorker_59) [pymodbus.logging] RECV: 0x0 0xf 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x46 0xc 0xfa 0x13
2024-02-20 09:45:35.308 DEBUG (SyncWorker_59) [pymodbus.logging] Got response!!!
2024-02-20 09:45:35.308 DEBUG (SyncWorker_59) [pymodbus.logging] Processing: 0x0 0xf 0x0 0x0 0x0 0x7 0x1 0x3 0x4 0x46 0xc 0xfa 0x13
2024-02-20 09:45:35.309 DEBUG (SyncWorker_59) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-02-20 09:45:35.309 DEBUG (SyncWorker_59) [pymodbus.logging] Adding transaction 15
2024-02-20 09:45:35.309 DEBUG (SyncWorker_59) [pymodbus.logging] Getting transaction 15
2024-02-20 09:45:35.309 DEBUG (SyncWorker_59) [pymodbus.logging] Changing transaction state from "PROCESSING REPLY" to "TRANSACTION_COMPLETE"```

hey

is it still working now ?

Hey,
Unfortunately, not.
But it doesn’t look to be an HA issue. I figured out that by restarting the PAC200, one of the connected EV charging stations showed an error that connection to the PAC2200 through Modbus is not possible. It seems like a maximum of 3 concurrent Modbus connections are supported to the PAC2200. If any connection is lost, HA or one of the charging stations acting as master reconnect and the fourth node is failing. Hence, I currently disabled the HA sensor for the time being.
I already integrated the charging station through OCPP HACS addon but for full dynamic charging management I am looking either for an additional HA integration or need to work on my own automation scripts. That said, I could disable Modbus integration at the charger station and connect HA instead. Overall, this could become the best solution.
Thanks for your support! :slight_smile: