ERROR (MainThread) [pymodbus.logging] Connection to (<IP>, <PORT>) failed: [Errno 111] Connection refused

Hi everybody,

First message on this board… I can’t find any answer to my issue :slight_smile:
I am connecting to my solar inverter (SolarEdge) through the following integration:

It works great and I can see my data in real time, so no issue there.

The issue is in the homeassistant log file… I keep on having this error message. Technically, it works… it just spams the log file and I feel like it eventually slows things down…

The frequency of the refresh is pretty high (1 second) so it might be the reason but I am not keen on changing that.

Any idea of how to fix this?

Thanks

Philippe

2023-11-18 02:04:53.165 ERROR (MainThread) [pymodbus.logging] Connection to (192.168.4.67, 1502) failed: [Errno 111] Connection refused
2023-11-18 02:04:53.165 ERROR (MainThread) [custom_components.solaredge_modbus] Error reading modbus data
Traceback (most recent call last):
  File "/config/custom_components/solaredge_modbus/__init__.py", line 217, in async_refresh_modbus_data
    update_result = self.read_modbus_data()
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solaredge_modbus/__init__.py", line 275, in read_modbus_data
    self.read_modbus_data_inverter()
  File "/config/custom_components/solaredge_modbus/__init__.py", line 561, in read_modbus_data_inverter
    inverter_data = self.read_holding_registers(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solaredge_modbus/__init__.py", line 259, in read_holding_registers
    return self._client.read_holding_registers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pymodbus/client/mixin.py", line 102, in read_holding_registers
    return self.execute(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pymodbus/client/base.py", line 175, in execute
    raise ConnectionException(f"Failed to connect[{str(self)}]")
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.4.67:1502)]
2023-11-18 02:22:27.823 ERROR (MainThread) [pymodbus.logging] Connection to (192.168.4.67, 1502) failed: timed out
2023-11-18 02:22:27.824 ERROR (MainThread) [custom_components.solaredge_modbus] Error reading modbus data
Traceback (most recent call last):
  File "/config/custom_components/solaredge_modbus/__init__.py", line 217, in async_refresh_modbus_data
    update_result = self.read_modbus_data()
                    ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solaredge_modbus/__init__.py", line 275, in read_modbus_data
    self.read_modbus_data_inverter()
  File "/config/custom_components/solaredge_modbus/__init__.py", line 561, in read_modbus_data_inverter
    inverter_data = self.read_holding_registers(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/solaredge_modbus/__init__.py", line 259, in read_holding_registers
    return self._client.read_holding_registers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pymodbus/client/mixin.py", line 102, in read_holding_registers
    return self.execute(
           ^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pymodbus/client/base.py", line 175, in execute
    raise ConnectionException(f"Failed to connect[{str(self)}]")
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.4.67:1502)]

There is more than 15min between 2 occurrences in your sample log, so frequency is unlikely to be an issue.

Just, plainly, HA could not establish a network connection to your inverter.
Is it a network or an inverter issue, hard to tell, but very unlikely to be a problem on the HA side.

Thank you. You’re right, the logs in my example are some minutes apart but that’s because I had other logs in between.
But that led me to look into that and sometimes it’s every 5 seconds, sometimes 1 minute apart. So no real pattern here.

That being said, I understand that inverter refuses the connection and I guess that’s because you can only get 1 connection at a time using the modbus protocol. (So… that’s expected that the connection is actually refused)

My question was more in the likes of: Why does the integration needs to reconnect (and therefore re-throws this error). Is there a pool of connection that could be reused?

oh my…

I guess I need to update :smiley: :smiley:

1 Like

You can also try my integration for SolarEdge, I’m active on here and on github supporting it.