Integration Solar inverter huawei 2000L

I had 2 new issues and Inverter appears to be connected and hearing at port 502.

Port Scanning host: 192.168.0.20

	 Open TCP Port: 	502    		asa-appl-proto
Port Scan has completed…

1- It requests a dependency…what do I have to do in this case?

Logger: pymodbus.client.asynchronous
Source: custom_components/huawei_solar/sensor.py:4 
First occurred: 8:07:58 (1 occurrences) 
Last logged: 8:07:58

Not Importing deprecated clients. Dependency Twisted is not Installed

2- Don’t know if it’s the same as @nedwos, but just here is the log too.

Logger: homeassistant.components.sensor
Source: custom_components/huawei_solar/sensor.py:168 
Integration: Sensor (documentation, issues) 
First occurred: 8:08:06 (1 occurrences) 
Last logged: 8:08:06

Error while setting up huawei_solar platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
    self._async_write_ha_state()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 324, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/config/custom_components/huawei_solar/sensor.py", line 168, in device_state_attributes
    ATTR_NB_ONLINE_OPTIMIZERS: self._nb_online_optimizers,
AttributeError: 'HuaweiSolarSensor' object has no attribute '_nb_online_optimizers'

You’re using the async sensor I see, I haven’t updated that because there are several issues with async pymodbus anyways. I advice you to use the sync version.

I did not modify anything at the folder, just downloaded and place in custom_components.

Anyway, I deleted the file with the name sensor_async.py on the folder and restarted HA.

Then it give the message still mentioning async things…

Am I doing anything wrong?

Logger: homeassistant.components.sensor
Source: custom_components/huawei_solar/sensor.py:168 
Integration: Sensor (documentation, issues) 
First occurred: 10:39:16 (1 occurrences) 
Last logged: 10:39:16

Error while setting up huawei_solar platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity
    entity.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
    self._async_write_ha_state()  # type: ignore
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 324, in _async_write_ha_state
    attr.update(self.device_state_attributes or {})
  File "/config/custom_components/huawei_solar/sensor.py", line 168, in device_state_attributes
    ATTR_NB_ONLINE_OPTIMIZERS: self._nb_online_optimizers,
AttributeError: 'HuaweiSolarSensor' object has no attribute '_nb_online_optimizers'
Logger: pymodbus.client.asynchronous
Source: custom_components/huawei_solar/sensor.py:4 
First occurred: 10:39:11 (1 occurrences) 
Last logged: 10:39:11

Not Importing deprecated clients. Dependency Twisted is not Installed

Try

pip3 install twisted

Twisted is not needed, that’s an incorrect message from pymodbus.

I think it should work now

1 Like

Hey! Updated the files… 3 errors still popping up…

Log Details (ERROR)

Logger: huawei_solar.huawei_solar
Source: custom_components/huawei_solar/sensor.py:98
First occurred: 11:30:18 PM (1 occurrences)
Last logged: 11:30:18 PM

could not read register value, is an other device already connected?
Log Details (WARNING)
Logger: homeassistant.components.sensor
Source: __main__.py:347
Integration: Sensor (documentation, issues)
First occurred: 11:30:15 PM (1 occurrences)
Last logged: 11:30:15 PM

Setup of sensor platform huawei_solar is taking over 10 seconds.
Log Details (WARNING)
Logger: pymodbus.client.asynchronous
Source: custom_components/huawei_solar/sensor.py:4
First occurred: 11:30:05 PM (1 occurrences)
Last logged: 11:30:05 PM

Not Importing deprecated clients. Dependency Twisted is not Installed

OOOOOOO Hang on… Another reboot might have fixed the issues!

Wow, it worked now! Many thanks @Emilv2!

Dummy question… :shushing_face:

How do I get a state value to be shown in Lovelace, I managed only to show a entity but did’t to show a state of an instance… Tried to search with no lucky…

entity: sensor.sun2000l_5ktl
daily_yield: 11.33

You could use this custom card or use a template sensor.

1 Like

Thank you @Emilv2! Here how it looks like right now :heart_eyes:

@ligeza, well done, beautiful cards configuration! How did you manage put the “image” of the lines with the inverter, strings, and so on?

I used https://www.home-assistant.io/lovelace/picture-elements/ .

Guys, it has been quite a steep learning curve getting to know home assistant, but now i could really need some help. I have followed your instructions and installed the sensor.py (not async), init.py and manifest.json in the folder config/custom_components/huawei_solar/.

I also added to the configuration.yaml:

sensor:
  - platform: huawei_solar   
    host: '192.168.8.3'

I also added the connection to the SUN2000 internal wifi (192.168.8.3) to home assistant via the USB method. When i check with nmcli (on SSH & Web Terminal) using “nmcli con show” i can see i’m both connected to my ethernet as well as the SUN2000 internal wifi. However my log shows the inverter is not reachable. I tried to ping and result is “disconnected”. What am i missing?

Below the log output:

2020-05-20 12:48:56 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for 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.
2020-05-20 12:48:56 WARNING (MainThread) [pymodbus.client.asynchronous] Not Importing deprecated clients. Dependency Twisted is not Installed
2020-05-20 12:48:59 ERROR (SyncWorker_17) [pymodbus.client.sync] Connection to (192.168.8.3, 502) failed: [Errno 113] Host is unreachable
2020-05-20 12:49:02 ERROR (SyncWorker_17) [pymodbus.client.sync] Connection to (192.168.8.3, 502) failed: [Errno 113] Host is unreachable
2020-05-20 12:49:02 ERROR (SyncWorker_17) [huawei_solar.huawei_solar] failed to connect to device, is the host correct?
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/huawei_solar/huawei_solar.py", line 147, in read_register
    response = self.client.read_holding_registers(register, length)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
    return self.execute(request)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/sync.py", line 107, in execute
    raise ConnectionException("Failed to connect[%s]" % (self.__str__()))
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.8.3:502)]
2020-05-20 12:49:02 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up huawei_solar platform for sensor
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/huawei_solar/huawei_solar.py", line 147, in read_register
    response = self.client.read_holding_registers(register, length)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/common.py", line 114, in read_holding_registers
    return self.execute(request)
  File "/usr/local/lib/python3.7/site-packages/pymodbus/client/sync.py", line 107, in execute
    raise ConnectionException("Failed to connect[%s]" % (self.__str__()))
pymodbus.exceptions.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.8.3:502)]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 178, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/huawei_solar/sensor.py", line 78, in setup_platform
    entities.append(HuaweiSolarSensor(inverter))
  File "/config/custom_components/huawei_solar/sensor.py", line 90, in __init__
    self._name = self._inverter.get("model_name").value
  File "/usr/local/lib/python3.7/site-packages/huawei_solar/huawei_solar.py", line 40, in get
    response = self.read_register(reg.register, reg.length)
  File "/usr/local/lib/python3.7/site-packages/huawei_solar/huawei_solar.py", line 150, in read_register
    raise ConnectionException(ex)
huawei_solar.huawei_solar.ConnectionException: Modbus Error: [Connection] Failed to connect[ModbusTcpClient(192.168.8.3:502)]

If you can’t even ping to your inverter the problem is not with Home Assistant but with your network configuration. Maybe @ligeza can help you with how he did this configuration?

What do you mean by:

My inverter default IP is 192.168.8.1 did you change it?

I didn’t setup WiFi upon installation of the Pi so use the method in which I connect a USB stick named “CONFIG” with directory network and a file named “my-network” with below code. (I’m on the road now so not able to give you the exact code, but below my best recollection)


[connection]
id=my-network
uuid=72111c67-4a5d-4d5c-925e-f8ee26efb3c3
type=802-11-wireless

[802-11-wireless]
mode=infrastructure
ssid= SUN2000-HV1990005631
# Uncomment below if your SSID is not broadcasted
#hidden=true

[802-11-wireless-security]
auth-alg=open
key-mgmt=wpa-psk
psk=Changeme

[ipv4]
method=auto

[ipv6]
addr-gen-mode=stable-privacy
method=auto

I don’t have PI, but if I correctly understand you are connected to home network with ethernet cable and with inverter by WiFi. Can you check your network status if Pi is connected correctly?

sudo ip addr show

You should see two ip addresses. One for home network and second for inverter.

Indeed Rafal, I have two connections. One on Ethernet cabled home network and a wlan to inverter WiFi.

Don’t have the nmcli screen print here, but the IP details match the one I got on my iPhone when connected to the SUN WiFi and ran Net Analyzer app. Gateway is at 192.168.8.3 and WiFi is at 192.168.8.3.

From screenshot I see that gateway is 192.168.8.1 so you should use this IP in configuration.

sensor: 
  - platform: huawei_solar 
    host: '192.168.8.1'

192.168.8.3 is IP given to your Iphone.