wlcrs / huawei_solar

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

huawei_solar.huawei_solar.ReadException: could not read register value, is an other device already connected? #13

Closed Marchellos closed 2 years ago

Marchellos commented 2 years ago

System Health details

System Health

version core-2021.12.5
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.9.7
os_name Linux
os_version 5.10.88
arch x86_64
timezone Europe/Amsterdam
Home Assistant Community Store GitHub API | ok -- | -- Github API Calls Remaining | 4982 Installed Version | 1.18.0 Stage | running Available Repositories | 932 Installed Repositories | 3
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 7.1 -- | -- update_channel | stable supervisor_version | supervisor-2021.12.2 docker_version | 20.10.9 disk_total | 30.8 GB disk_used | 4.8 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | File editor (5.3.3), Filebrowser (2.20.1), Terminal & SSH (9.2.2), MariaDB (2.4.0), phpMyAdmin (0.6.0)
Lovelace dashboards | 1 -- | -- resources | 0 views | 2 mode | storage

Describe the issue

I have followed all the steps as stated in the description..? But I can't get it to work. IP number and port number checked with https://www.advanced-port-scanner.com/

HUAWEI 17KTL M0 (SPC139) Dongle WIFI/FE (SPC123). IP 192.169.0.8

Reproduction steps

IP and port checked

  1. Install the integration with HACS,
  2. Restart HA
  3. Go to Configuration -> Integrations and click the + Add Integration button
  4. Select Huawei Solar from the list
  5. Enter the IP address 192.168.0.8
  6. Select if you have a battery (none)
  7. Select optimizers (none).
  8. slave id 0. (also tried 1)

Relevant debug logs

Logger: huawei_solar.huawei_solar
Source: /usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py:437
First occurred: 2:26:15 PM (1 occurrences)
Last logged: 2:26:15 PM

could not read register value, is an other device already connected?

---------------------------------------------------------------

This error originated from a custom integration.

Logger: custom_components.huawei_solar.config_flow
Source: custom_components/huawei_solar/config_flow.py:47
Integration: Huawei Solar
First occurred: 2:26:15 PM (1 occurrences)
Last logged: 2:26:15 PM

Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 419, in read_register
    response = await client.protocol.read_holding_registers(
  File "/usr/local/lib/python3.9/site-packages/pymodbus/client/asynchronous/async_io/__init__.py", line 35, in execute
    resp = await asyncio.wait_for(req, timeout=self._timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
    return fut.result()
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Connection lost during request

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/huawei_solar/config_flow.py", line 77, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/config/custom_components/huawei_solar/config_flow.py", line 47, in validate_input
    model_name = (await inverter.get(ATTR_MODEL_NAME)).value
  File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 394, in get
    response = await self.read_register(await self.client, reg.register, reg.length)
  File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 438, in read_register
    raise ReadException(message)
huawei_solar.huawei_solar.ReadException: could not read register value, is an other device already connected?

-------------------------------------------------------------

Logger: pymodbus.client.asynchronous.async_io
Source: /usr/local/lib/python3.9/site-packages/pymodbus/client/asynchronous/async_io/__init__.py:307
First occurred: 2:26:16 PM (15 occurrences)
Last logged: 2:48:05 PM

Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)

---------------------------------------------------------

2022-01-07 14:25:14 WARNING (SyncWorker_0) [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
2022-01-07 14:25:14 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs 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
2022-01-07 14:26:15 ERROR (MainThread) [huawei_solar.huawei_solar] could not read register value, is an other device already connected?
2022-01-07 14:26:15 ERROR (MainThread) [custom_components.huawei_solar.config_flow] Unexpected exception
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 419, in read_register
response = await client.protocol.read_holding_registers(
File "/usr/local/lib/python3.9/site-packages/pymodbus/client/asynchronous/async_io/__init__.py", line 35, in execute
resp = await asyncio.wait_for(req, timeout=self._timeout)
File "/usr/local/lib/python3.9/asyncio/tasks.py", line 481, in wait_for
return fut.result()
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Connection lost during request
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/config/custom_components/huawei_solar/config_flow.py", line 77, in async_step_user
info = await validate_input(self.hass, user_input)
File "/config/custom_components/huawei_solar/config_flow.py", line 47, in validate_input
model_name = (await inverter.get(ATTR_MODEL_NAME)).value
File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 394, in get
response = await self.read_register(await self.client, reg.register, reg.length)
File "/usr/local/lib/python3.9/site-packages/huawei_solar/huawei_solar.py", line 438, in read_register
raise ReadException(message)
huawei_solar.huawei_solar.ReadException: could not read register value, is an other device already connected?
2022-01-07 14:26:16 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:16 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:16 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:17 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:19 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:22 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:28 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:26:41 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:27:07 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:27:58 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:29:40 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:33:05 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:38:05 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:43:05 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
2022-01-07 14:48:05 WARNING (MainThread) [pymodbus.client.asynchronous.async_io] Failed to connect: Multiple exceptions: [Errno 111] Connect call failed ('::1', 502, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 502)
wlcrs commented 2 years ago

As I already said to you in #3: The inverter closes the connection instead of answering the query after issuing a read_register (0x03) command, so having an open 502 port to connect to is clearly not enough.

The device will always close the previous connection when another connection is made to that 502 modbus port. So make sure that nothing else is trying to connect to the inverter via Modbus. This can also cause the behavior that you're seeing.

To debug, you should verify that you can succesfully retrieve a value via Modbus from the inverter.

I've only worked with Modbus directly via Python. A minimal example to debug:

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
client = ModbusClient('<ip>', port=502)
client.connect()
client.read_holding_register(address=30000, count=15 ,unit=0)

If you want to use a GUI to query, you'll have to search for yourself (maybe http://www.minaandrawos.com/tcp-modbus-examiner-tool/ works for you?)

Marchellos commented 2 years ago

Hello Thijs,

Thank you very much for your help. I am sure there are no other connections. My inverter hangs in a barn in the countryside. The inverter can only connect to the router. Huawei recommended SPC126. By default, the modbus is turned off. But to enable the modbus I need an android phone. And I only have an iPhone cellphone. I just got this response from the helpdesk:

I escalate this issue and R&D confirmed that this month they will enable the option for Sdongle MODBUS TCP through Fusion Solar Web!

Until then we cannot do anything.

We are sorry for the inconveniences!

I wish you a nice evenin

So I will have to be patient until the update comes. In the meantime I will study modbus protocol to understand this.

Thanks again for your help and have a nice weekend..

Op vr 7 jan. 2022 om 18:17 schreef Thijs W. @.***

:

As I already said to you in #3 https://github.com/wlcrs/huawei_solar/issues/3: The inverter closes the connection instead of answering the query after issuing a read_register (0x03) command, so having an open 502 port to connect to is clearly not enough.

The device will always close the previous connection when another connection is made to that 502 modbus port. So make sure that nothing else is trying to connect to the inverter via Modbus. This can also cause the behavior that you're seeing.

To debug, you should verify that you can succesfully retrieve a value via Modbus from the inverter.

I've only worked with Modbus directly via Python. A minimal example to debug:

from pymodbus.client.sync import ModbusTcpClient as ModbusClient client = ModbusClient('', port=502) client.connect() client.read_holding_register(address=30000, count=15 ,unit=0)

If you want to use a GUI to query, you'll have to search for yourself (maybe http://www.minaandrawos.com/tcp-modbus-examiner-tool/ works for you?)

— Reply to this email directly, view it on GitHub https://github.com/wlcrs/huawei_solar/issues/13#issuecomment-1007585239, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWXEGKJKCMKVKFE7MFFVMWTUU4N3RANCNFSM5LO2UNFA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

wlcrs commented 2 years ago

It may be possible that you'll need to contact your installer to enable it via that way. My account certainly doesn't have enough access rights for that kind of changes to the installation.