wlcrs / huawei_solar

Home Assistant integration for Huawei Solar inverters via Modbus
GNU Affero General Public License v3.0
559 stars 89 forks source link

[Bug]: The connection does not occur as the first time and not even after restoring from backup #643

Closed daxxxit closed 8 months ago

daxxxit commented 8 months ago

Describe the issue

Hardware: SUN2000-6KTL-M0 fw: V100R001C00SPC159 (latest) SDongleA-01 fw: V100R001C00SPC123 (latest)

I made the connection with the integration about 3 years ago with the wifi AP port 502 slave ID 0 (I’m not sure if 0 or 1), it went well and I never had any problems. I need to replace the NUC, I have performed the backup and restore in a Proxmox VM. Everything has started working again except for huawei-solar which tries to connect in a loop but always fails. Obviously, I have turned off the old NUC. I tried to assign the same IP ADDRESS and MAC ADDRESS of the old NUC to the VM but it does not connect.

Connection:

[Home Assistant 192.168.1.34] --LAN--> [Router 192.168.1.1] --WIFI--> [192.168.1.225 Router OperWRT 192.168.8.2] --WIFI--> [Inverter WiFi AP 192.168.8.1]

From the VM Home Assistant, if I execute the ping:

64 bytes from 192.168.8.1: seq=0 ttl=254 time=6.275 ms
64 bytes from 192.168.8.1: seq=1 ttl=254 time=5.763 ms
64 bytes from 192.168.8.1: seq=2 ttl=254 time=5.994 ms
64 bytes from 192.168.8.1: seq=3 ttl=254 time=6.045 ms
64 bytes from 192.168.8.1: seq=4 ttl=254 time=5.633 ms
64 bytes from 192.168.8.1: seq=5 ttl=254 time=5.200 ms

The port 502 is open:

Nmap scan report for 192.168.8.1
Host is up (0.0059s latency).

PORT    STATE SERVICE
502/tcp open  mbap

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

The port 6607 is close. I tried to create a ‘clean’ Home Assistant VM but it does not connect to any slave ID on port 502. If I turn on the old NUC, the connection is immediately restored and works perfectly.

In the FusionSolar APP, there is no ‘Modbus-TCP’ option and therefore it is not possible to enable ‘Advanced: elevate permissions’, but 3 years ago the old NUC connected perfectly and still connects every time I reboot. Even on FusionSolar WEB as an installer, the ‘Modbus-TCP’ option is not present. I thought that perhaps an old version of the integration created the connection, with updates it no longer creates a new connection but the existing connection continues to work, but I do not understand why it does not work with the VM created with the full backup from the NUC.

I am not interested in connecting to the dongle’s wifi but I would like to be able to connect to the inverter’s internal AP wifi as it has been so far with the old NUC.

I hope I have included all the useful and requested information, I apologize if this is not the case, for us who do not know the English language it is all very complicated even using translators.

I have searched for ‘Download diagnostis’ but it is not there.

imgsolar

Bescribe your Huawei Solar Setup

Inverter Type: SUN2000-6KTL-M0 Inverter Firmware version: V100R001C00SPC159 (latest) SDongle present: SDongleA-01 fw: V100R001C00SPC123 (latest) Power meter present: no Battery: None Battery Firmware version: None

How do you connect to the inverter?

Over serial, with a serial-to-WiFi stick

Upload your Diagnostics File

Drag & Drop your Diagnostics File here.

Upload your relevant debug logs

2024-03-08 14:52:42.248 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration huawei_solar which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-03-08 14:52:47.660 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.8.1:502.
2024-03-08 14:52:47.660 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-03-08 14:52:47.724 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-03-08 14:52:47.725 DEBUG (MainThread) [pymodbus.logging] callback_connected called
2024-03-08 14:52:47.861 DEBUG (MainThread) [huawei_solar.modbus] Waiting for 1500 milliseconds after connection before performing operations
2024-03-08 14:52:47.862 INFO (MainThread) [huawei_solar.huawei_solar] Waiting for connection ...
2024-03-08 14:52:48.918 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 948, in async_init
    flow, result = await task
                   ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 976, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 501, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mbapi2020/config_flow.py", line 128, in async_step_reauth
    self._reauth_entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
                                                                  ~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'entry_id'
2024-03-08 14:52:49.635 DEBUG (MainThread) [huawei_solar.huawei_solar] Reading register 43006 with length 1 from slave 0
2024-03-08 14:52:49.636 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:52:49.636 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:52:59.637 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:52:59.637 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:53:09.640 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:53:09.640 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:53:19.641 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:53:19.642 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:53:29.642 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to Server not responding
2024-03-08 14:53:29.644 DEBUG (MainThread) [pymodbus.logging] Getting transaction 1
2024-03-08 14:53:29.645 ERROR (MainThread) [huawei_solar.huawei_solar] Aborting client creation due to error.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 178, in create
    await huawei_solar._initialize()
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 107, in _initialize
    self.time_zone = (await self.get(rn.TIME_ZONE)).value
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 241, in get
    return (await self.get_multiple([name], slave))[0]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 276, in get_multiple
    response = await self._read_registers(registers[0].register, total_length, slave)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 398, in _read_registers
    return await _do_read()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 351, in _do_read
    response = await self._client.read_holding_registers(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 207, in async_execute
    raise ModbusIOException(
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries
2024-03-08 14:53:29.736 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.8.1:502.
2024-03-08 14:53:29.736 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-03-08 14:53:29.758 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-03-08 14:53:29.758 DEBUG (MainThread) [pymodbus.logging] callback_connected called
2024-03-08 14:53:29.766 DEBUG (MainThread) [huawei_solar.modbus] Waiting for 1500 milliseconds after connection before performing operations
2024-03-08 14:53:29.767 INFO (MainThread) [huawei_solar.huawei_solar] Waiting for connection ...
2024-03-08 14:53:31.268 DEBUG (MainThread) [huawei_solar.huawei_solar] Reading register 43006 with length 1 from slave 0
2024-03-08 14:53:31.268 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:53:31.269 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:53:41.271 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:53:41.273 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:53:51.275 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:53:51.275 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:54:01.277 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:54:01.277 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:54:11.279 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to Server not responding
2024-03-08 14:54:11.281 DEBUG (MainThread) [pymodbus.logging] Getting transaction 1
2024-03-08 14:54:11.282 ERROR (MainThread) [huawei_solar.huawei_solar] Aborting client creation due to error.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 178, in create
    await huawei_solar._initialize()
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 107, in _initialize
    self.time_zone = (await self.get(rn.TIME_ZONE)).value
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 241, in get
    return (await self.get_multiple([name], slave))[0]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 276, in get_multiple
    response = await self._read_registers(registers[0].register, total_length, slave)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 398, in _read_registers
    return await _do_read()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 351, in _do_read
    response = await self._client.read_holding_registers(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 207, in async_execute
    raise ModbusIOException(
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries
2024-03-08 14:54:21.625 DEBUG (MainThread) [pymodbus.logging] Connecting to 192.168.8.1:502.
2024-03-08 14:54:21.626 DEBUG (MainThread) [pymodbus.logging] Connecting comm
2024-03-08 14:54:21.633 DEBUG (MainThread) [pymodbus.logging] Connected to comm
2024-03-08 14:54:21.633 DEBUG (MainThread) [pymodbus.logging] callback_connected called
2024-03-08 14:54:21.633 DEBUG (MainThread) [huawei_solar.modbus] Waiting for 1500 milliseconds after connection before performing operations
2024-03-08 14:54:21.633 INFO (MainThread) [huawei_solar.huawei_solar] Waiting for connection ...
2024-03-08 14:54:23.134 DEBUG (MainThread) [huawei_solar.huawei_solar] Reading register 43006 with length 1 from slave 0
2024-03-08 14:54:23.135 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:54:23.136 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:54:33.138 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:54:33.139 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:54:43.141 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:54:43.141 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:54:53.143 DEBUG (MainThread) [pymodbus.logging] send: 0x0 0x1 0x0 0x0 0x0 0x6 0x0 0x3 0xa7 0xfe 0x0 0x1
2024-03-08 14:54:53.143 DEBUG (MainThread) [pymodbus.logging] Adding transaction 1
2024-03-08 14:55:03.145 DEBUG (MainThread) [pymodbus.logging] Connection lost comm due to Server not responding
2024-03-08 14:55:03.146 DEBUG (MainThread) [pymodbus.logging] Getting transaction 1
2024-03-08 14:55:03.146 ERROR (MainThread) [huawei_solar.huawei_solar] Aborting client creation due to error.
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 178, in create
    await huawei_solar._initialize()
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 107, in _initialize
    self.time_zone = (await self.get(rn.TIME_ZONE)).value
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 241, in get
    return (await self.get_multiple([name], slave))[0]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 276, in get_multiple
    response = await self._read_registers(registers[0].register, total_length, slave)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 398, in _read_registers
    return await _do_read()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/backoff/_async.py", line 151, in retry
    ret = await target(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 351, in _do_read
    response = await self._client.read_holding_registers(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pymodbus/client/base.py", line 207, in async_execute
    raise ModbusIOException(
pymodbus.exceptions.ModbusIOException: Modbus Error: [Input/Output] ERROR: No response received after 3 retries

Please confirm the following:

jolejnic-tech commented 8 months ago

Same issue - Home Assistant 2024.2.5. A day ago the integration stopped working. Removing the integration and trying to reconnect does not work

Logger: huawei_solar.huawei_solar Source: /usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py:184 First occurred: 17:21:22 (10 occurrences) Last logged: 18:01:24

Aborting client creation due to error. Traceback (most recent call last): File "/usr/local/lib/python3.12/asyncio/tasks.py", line 520, in wait_for return await fut ^^^^^^^^^ File "/usr/local/lib/python3.12/asyncio/locks.py", line 212, in wait await fut asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 178, in create await huawei_solar._initialize() File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 107, in _initialize self.time_zone = (await self.get(rn.TIME_ZONE)).value ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 241, in get return (await self.get_multiple([name], slave))[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 276, in get_multiple response = await self._read_registers(registers[0].register, total_length, slave) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 396, in _read_registers async with self._communication_lock(): File "/usr/local/lib/python3.12/contextlib.py", line 210, in aenter return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 145, in _communication_lock raise err File "/usr/local/lib/python3.12/site-packages/huawei_solar/huawei_solar.py", line 141, in _communication_lock await asyncio.wait_for(self._client.connected_event.wait(), WAIT_FOR_CONNECTION_TIMEOUT) File "/usr/local/lib/python3.12/asyncio/tasks.py", line 519, in wait_for async with timeouts.timeout(timeout): File "/usr/local/lib/python3.12/asyncio/timeouts.py", line 115, in aexit raise TimeoutError from exc_val TimeoutError

wlcrs commented 8 months ago

This issue seems to be caused by a connection failure or an unstable connection to the inverter. This integration already has already implemented a lot of logic to automatically recover from connection failures or unstable connections. The three most important ones are:

Please understand that I cannot help you solve your connection failure or unstable connection. Consider an alternative connection method. If you are convinced that there is no connectivity issue, then I invite you to debug and fix the problem yourself and submit a pull request to the underlying huawei-solar Python library. Your input would be greatly appreciated.

As there is nothing actionable for me to do in this issue, I'm closing it. You are welcome to open a topic in Discussions: Connecting to the inverter to get community support for your problem.