I was looking for a solution that you made…
I would like to implement the integration between the inverter and home assistant.
Question: Is your solution still working? I’m asking because just tried to implement and I’m receiving this error: "Platform error sensor.huawei_solar - No module named ‘huawei_solar’"
Have I done something wrong?
That means something went wrong loading the module. I just checked with the last version and it still loads for me. The custom_components folder should be in your configuration folder, next to configuration.yaml, automations.yaml etc.
No, you should not have to enable anything. Is it one of the supported devices? Or are you perhaps connected with another modbus client to it? The inverter does not support multiple connections.
Can’t really say anything from here The modbus implementation of those devices seems not to be very robust. You can try debugging them with python and see whether you can get it to work.
import pymodbus
import time
client = pymodbus.client.sync.ModbusTcpClient('192.168.5.34', '502')
client.connect()
time.sleep(3)
result = client.read_holding_registers(30000,15)
result.encode()
what happens if you run this code in python3? (you will need to install pymodbus first)
I think I have to be connected directly to inverter. If I’m in range I can connect directly to SUN2000 (inverter ip 192.168.8.1), but inverter is also connected to home WiFi and I see it in network with IP 192.168.5.34. It seems that only 192.168.8.1 have opened 502 port.
i have this custom components working fine without any trouble
Great Great Thank You !!!
Huawei Inverter: SUN2000L-4.6KTL
Home Assistant 0.108.6 in a docker installation
I have one question: the installer technician setup a module (Gavazzi EM111) in the electrical cabinet which is connected to inverter. Thanks to this module i can see the power taken/bought from the grid too and not only how much power the panels are producing…
So you’re saying you can see this value on the Huawei app / website? I don’t see anything in their modbus documentation, so I don’t think you’ll be able to read it out through modbus.
There is also an api which has access to more information, so maybe you can access it through there, but you will need to get a different api username and password from your installer.
root@P38:~# python3
Python 3.8.2 (default, Feb 26 2020, 04:23:39)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymodbus
>>> import time
>>> client = pymodbus.client.sync.ModbusTcpClient('192.168.5.34', '502')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'pymodbus' has no attribute 'client'
>>> client.connect()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'client' is not defined
>>> time.sleep(3)
>>> result = client.read_holding_registers(30000,15)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'client' is not defined
>>> result.encode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'result' is not defined
>>>
2020-04-23 09:16:36 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform huawei_solar is taking over 10 seconds.
2020-04-23 09:16:42 ERROR (SyncWorker_6) [huawei_solar.huawei_solar] could not read register value, is an other device already connected?
2020-04-23 09:16:42 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up huawei_solar platform for sensor
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\homeassistant\helpers\entity_platform.py", line 178, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "C:\Python38\lib\asyncio\tasks.py", line 483, in wait_for
return fut.result()
File "C:\Python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\ligez\AppData\Roaming\.homeassistant\custom_components\huawei_solar\sensor.py", line 61, in setup_platform
entities.append(HuaweiSolarSensor(inverter))
File "C:\Users\ligez\AppData\Roaming\.homeassistant\custom_components\huawei_solar\sensor.py", line 80, in __init__
self._nb_optimizers = self._inverter.get("nb_optimizers").value
File "C:\Users\ligez\AppData\Roaming\.homeassistant\deps\Python38\site-packages\huawei_solar\huawei_solar.py", line 37, in get
response = read_register(self.client, reg.register, reg.length)
File "C:\Users\ligez\AppData\Roaming\.homeassistant\deps\Python38\site-packages\huawei_solar\huawei_solar.py", line 151, in read_register
raise ReadException(message)
huawei_solar.huawei_solar.ReadException: could not read register value, is an other device already connected?
I closed python before starting HA to close connection with inverter.
Ok, what happens if you do not call sleep but try several times in a row?
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient('192.168.5.34', '502')
result = client.read_holding_registers(30000,15)
result = client.read_holding_registers(30000,15)
result = client.read_holding_registers(30000,15)
result = client.read_holding_registers(30000,15)
result.encode()
If that works I don’t know what is going wrong with HA, but if not I think I know what is going on. When I wrote the package I wrote it by debugging and found out you need to probe it several times, but maybe yours is slightly different. Later I found out it just needs a delay between connect and probing, but since it worked for me I just left it like that. I’ll update my code and then you can try again.
I paste it in python window and it was about 1 second delay between result = client …
Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pymodbus.client.sync import ModbusTcpClient
>>> client = ModbusTcpClient('192.168.8.1', '502')
>>> result = client.read_holding_registers(30000,15)
>>> result = client.read_holding_registers(30000,15)
>>> result = client.read_holding_registers(30000,15)
>>> result = client.read_holding_registers(30000,15)
>>> result.encode()
b'\x1eSUN2000-8KTL-M0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>>
That is weird since it’s exactly what my integration does. What happens if you directly use the HuaweiSolar package in python? Install HuaweiSolar through pypi and run this:
>>> import huawei_solar
>>> inverter = HuaweiSolar('192.168.8.1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'HuaweiSolar' is not defined
>>> inverter = huawei_solar('192.168.8.1')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
2020-04-23 11:59:01 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform huawei_solar is taking over 10 seconds.
2020-04-23 11:59:06 ERROR (SyncWorker_1) [huawei_solar.huawei_solar] could not read register value, is an other device already connected?
2020-04-23 11:59:06 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up huawei_solar platform for sensor
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\homeassistant\helpers\entity_platform.py", line 178, in _async_setup_platform
await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
File "C:\Python38\lib\asyncio\tasks.py", line 483, in wait_for
return fut.result()
File "C:\Python38\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\ligez\AppData\Roaming\.homeassistant\custom_components\huawei_solar\sensor.py", line 61, in setup_platform
entities.append(HuaweiSolarSensor(inverter))
File "C:\Users\ligez\AppData\Roaming\.homeassistant\custom_components\huawei_solar\sensor.py", line 80, in __init__
self._nb_optimizers = self._inverter.get("nb_optimizers").value
File "C:\Users\ligez\AppData\Roaming\.homeassistant\deps\Python38\site-packages\huawei_solar\huawei_solar.py", line 37, in get
response = read_register(self.client, reg.register, reg.length)
File "C:\Users\ligez\AppData\Roaming\.homeassistant\deps\Python38\site-packages\huawei_solar\huawei_solar.py", line 151, in read_register
raise ReadException(message)
huawei_solar.huawei_solar.ReadException: could not read register value, is an other device already connected?