Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus connects too soon after reloading yaml and doesnt evaluate the connection call when it fails #129940

Closed
reiffert2 opened this issue Nov 6, 2024 · 3 comments

Comments

@reiffert2
Copy link

The problem

The modbus integration has an established connection with a tcp peer.
When reloading HA yaml files it terminates the connection, establishes a new one.
The new connection fails but Modbus keeps trying to read values.

Reloading the yaml files once again then succeeds.

It would help when

  1. the modbus intergration delays creating its connection after closing the old one
  2. the modbus integration evaluates the unsuccessful new connection
  3. re-establish the connection after 2

Logs:

Successfully reading values with the first connection:
2024-11-06 08:12:05.539 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0xfe 0x0 0x0 0x0 0x6 0x55 0x3 0x4 0x2b 0x0 0x2
2024-11-06 08:12:05.546 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0xfe 0x0 0x0 0x0 0x7 0x55 0x3 0x4 0x0 0x0 0x0 0x0 old_data:  addr=None
2024-11-06 08:12:05.546 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0xfe 0x0 0x0 0x0 0x7 0x55 0x3 0x4 0x0 0x0 0x0 0x0
2024-11-06 08:12:05.547 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-11-06 08:12:05.547 DEBUG (MainThread) [pymodbus.logging] Getting transaction 254
2024-11-06 08:12:05.547 DEBUG (MainThread) [pymodbus.logging] Very short frame (NO MBAP):  wait for more data
2024-11-06 08:12:05.558 DEBUG (MainThread) [pymodbus.logging] Adding transaction 255
2024-11-06 08:12:05.559 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 
2024-11-06 08:12:05.559 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0xff 0x0 0x0 0x0 0x6 0x55 0x3 0x8 0x0 0x0 0x1
2024-11-06 08:12:05.566 DEBUG (MainThread) [pymodbus.logging] recv: 0x0 0xff 0x0 0x0 0x0 0x5 0x55 0x3 0x2 0x0 0x0 old_data:  addr=None
2024-11-06 08:12:05.566 DEBUG (MainThread) [pymodbus.logging] Processing: 0x0 0xff 0x0 0x0 0x0 0x5 0x55 0x3 0x2 0x0 0x0
2024-11-06 08:12:05.567 DEBUG (MainThread) [pymodbus.logging] Factory Response[ReadHoldingRegistersResponse': 3]
2024-11-06 08:12:05.567 DEBUG (MainThread) [pymodbus.logging] Getting transaction 255
2024-11-06 08:12:05.567 DEBUG (MainThread) [pymodbus.logging] Very short frame (NO MBAP):  wait for more data

Clicking on 'reload yaml config'

2024-11-06 08:12:05.579 WARNING (MainThread) [homeassistant.components.modbus.modbus] modbus modbuspvsystem communication closed
2024-11-06 08:12:05.580 DEBUG (MainThread) [pymodbus.logging] Connecting to 10.20.0.203:502.
2024-11-06 08:12:05.580 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-11-06 08:12:05.591 WARNING (MainThread) [pymodbus.logging] Failed to connect [Errno 111] Connect call failed ('10.20.0.203', 502)
2024-11-06 08:12:05.591 WARNING (MainThread) [homeassistant.components.modbus.modbus] modbus modbuspvsystem communication open
2024-11-06 08:12:07.590 ERROR (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 33 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]
2024-11-06 08:12:07.604 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 27 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]
2024-11-06 08:12:07.616 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 29 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]
2024-11-06 08:12:07.628 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 31 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]
2024-11-06 08:12:07.640 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 294 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]
2024-11-06 08:12:07.652 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: modbuspvsystem: Error: device: 85 address: 4541 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 10.20.0.203:502]

Upon inspecting the above logs you can see that even after 'Connect call failed' modbus thinks that the communciation is open and attempts to read values.

My config:

modbus:
  - name: modbuspvsystem
    type: tcp
    host: 10.20.0.203
    port: 502
    message_wait_milliseconds: 10
    timeout: 10                   
    delay: 1                      

What version of Home Assistant Core has the issue?

core-2024.10.1

What was the last working version of Home Assistant Core?

No response

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

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Nov 6, 2024

@siggeb
Copy link

siggeb commented Dec 20, 2024

I have a similar issue, but looking at the logs i havent seen this detail, but it sounds similar.

I have connected my heatpump with modbus to HA, but for some reason, whenever I restart HA do to any config changes, unrelated to the modbus entities, they go unavailable for several hours. Also, I have not just been reloading yaml, but rather done the full restart.

2024-12-20 00:56:44.197 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.1.248:502. 2024-12-20 00:56:44.197 DEBUG (MainThread) [pymodbus.logging] Connecting comm 2024-12-20 00:56:44.203 DEBUG (MainThread) [pymodbus.logging] Connected to comm 2024-12-20 00:56:44.203 DEBUG (MainThread) [pymodbus.logging] Resetting frame - Current Frame in buffer - 2024-12-20 00:56:44.211 DEBUG (MainThread) [pymodbus.logging] -> transport: received eof 2024-12-20 00:56:44.211 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to None 2024-12-20 00:56:44.211 DEBUG (MainThread) [pymodbus.logging] callback_disconnected called: None 2024-12-20 00:56:44.211 DEBUG (MainThread) [pymodbus.logging] Wait comm 100.0 ms before reconnecting. 2024-12-20 00:56:44.265 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: ctc: Error: device: 1 address: 61500 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.248:502] 2024-12-20 00:56:44.265 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: ctc: Error: device: 1 address: 61503 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.248:502] 2024-12-20 00:56:44.265 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: ctc: Error: device: 1 address: 61509 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.248:502] 2024-12-20 00:56:44.265 DEBUG (MainThread) [homeassistant.components.modbus.modbus] Pymodbus: ctc: Error: device: 1 address: 61513 -> Modbus Error: [Connection] Not connected[AsyncModbusTcpClient 192.168.1.248:502]

image

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants