Integration Solar inverter huawei 2000L

@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.

Do anyone experiencing problems after updating to Home Assistant 0.110.1?

Now I get this Log:

Translation Error: The intl string context variable "Level" was not provided to the string "Detalhes do log ({Level})"
Logger: homeassistant.config
Source: custom_components/huawei_solar/sensor.py:4 
First occurred: 19:37:46 (1 occurrences) 
Last logged: 19:37:46

Platform error: sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config.py", line 777, in async_process_component_config
    platform = p_integration.get_platform(domain)
  File "/usr/src/homeassistant/homeassistant/loader.py", line 273, in get_platform
    f"{self.pkg_path}.{platform_name}"
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/huawei_solar/sensor.py", line 4, in <module>
    from huawei_solar import HuaweiSolar, ReadException
ModuleNotFoundError: No module named 'huawei_solar'

I’m not sure what is causing this, I think you can fix it for now by commenting out (adding # in front of it) all the _LOGGER lines.

Whoop whoop! You solved it. Many thanks for your help! I’ve got my sensor set up now as you can see in my pic

. Will start building a dashboard in Lovelace now. Hoping I can mimic yours. Should keep me busy for a while!

Another question: how do you store data long term? As rules in the Netherlands will change in ‘23 (no longer able to net the power bought with the power returned to the network) I probably need to look into hooking up a battery. For this I want to have enough historical data to make a return analysis based on period averages as well as intraday profile of power usage and generation from my panels. So what would be the application best used for building a local database?

I’m useing influx in HA.

influxdb:
  host: 192.168.5.75
  database: hass
  max_retries: 3
  include:
    domains:
      - sensor
      - binary_sensor

I have all data from every day. With grafana you can draw nice graphs.

Great stuff. Will dive into that. I did jump ahead a bit to enthusiastic I’m afraid, as it looks like i can only use the power output data from the invertor in Lovelace. How do i get to all the additional data (like daily yield etc) that is shown when i click on the sensor in the “entities” tab and follow up with the settings button? Do i set up additional sensors for this?

Sorry for the noob questions, maybe you can redirect me to another topic if you want me read up on the basics.

I’m using something like this:

- platform: template
  sensors:
    pv_input_power:
      friendly_name: "Produkcja DC"
      entity_id: sensor.sun2000_8ktl_m0
      unit_of_measurement: 'W'
      icon_template: mdi:solar-power
      value_template: "{{ state_attr('sensor.sun2000_8ktl_m0', 'input_power') }}"

For influx you don’t need it, you can read data directly from attribute.


If you need any help just let me know.

1 Like

I’ve got that working. I think i’m getting the hang of it. Thanks for getting me on the right track. Next post from me will hopefully be a full fledge dashboard…

Hi there, just getting started with HA so sorry for the probably newbie question.

I’ve in putted the files in the specified folder and set up the stib platform in configuration.yaml.
When I go to check config the yaml file before I reboot I get the error

Configuration invalid

Platform error sensor.huawei_solar - cannot import name ‘HuaweiSolar’ from ‘huawei_solar’ (/config/huawei_solar/init.py)

Thanks

I’ve in putted the files in the specified folder and set up the stib platform in configuration.yaml .

I suppose that’s a typo and you mean you set up the huawei_solar platform?

I just checked with the latest version and I can’t reproduce this problem using the check_config script, but I’m not sure if that’s exactly the same as what the UI does. Is your custom_components folder in the same folder as your configuration.yaml file? And have you tried rebooting?

Same issue happened to me.
After clicking on Configuration validation for the first time something failed in the background.
I removed the sensor from the configuration, and restarted HA.
After that I added the sensor again and it took its time to check the configuration but if worked, restart again and you should have the sensor readings ready.

1 Like

Yesterday I woke up with this component not working, not even after a restart.
After inspecting the logs I found this:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 319, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 472, in async_device_update
await self.hass.async_add_executor_job(self.update)
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 224, in update
self._shutdown_time = self._inverter.get(“shutdown_time”).value.time()
File “/usr/local/lib/python3.7/site-packages/huawei_solar/huawei_solar.py”, line 58, in get
tmp2 = datetime.utcfromtimestamp(tmp - 60 * self._time_offset)
OverflowError: timestamp out of range for platform time_t

Apparently there is something wrong with the property “shutdown_time”, I changed the code to not parse it as date time, just expose the string, but it was failing anyway so I removed the whole “shutdown_time” property. It is now working correctly.

I would suggest reading the properties inside a try-catch to avoid having your important readings down just because a non important field is failing.