Huawei Sun2000 Modbus RTU with ESPhome

Hi world!

I have a Huawei SUN2000 solar inverter at home. After reading many complains about the instability of our inverter when connected through Modbus TCP I decided that I would go the RTU way instead. This setup has been rock solid for me for as long as I had it installed and it got to a point where I think is ready to be released to the world.

The ESPhome code contains some additional attributes that are helpful for other stuff:

You can find the code in this github repository.

imagen

Enjoy!

6 Likes

For now, I using HA component connecting to inverter wifi, but, I am happy with this alternative. We donā€™t know if in the future huawei block direct connection too.

@jesusrop Do you need to have installer access in irder to see data for each string? I am asking as I do not have installer access to my inverter.

Using Modbus RTU AFAIK all data is available without any special access. Certainly it is not needed for string voltage and current. String power is calculated with a lambda

Interesting, indeed. It is always nice to have alternatives. My Wifi-connection is rock-solid now, so I have no immediate need to switch.
One question: Can you write to the Huawei with this solution? I ā€œneedā€ to be able to change the battery charge and discharge values, as well as the ā€œWorking modeā€ (i.e. Maximise Self Consumption and TOU)
Is this possible to do with your integration?

I have no battery so I did not set that up. But according to the documentation and online sources, those registers are available and writable. ESPhome also has the ability to write registers so it should be easy to setup.

If you are interested and able to test, we can try to add it to the template.

It is good that it should work! Unfortunately at the moment, I have no ESP32 hardware and not really time to spare for investigating this. I hope that someone else have a battery and time to try this out. It looks promising! Iā€™ll let you know if I find time to get some ESP32-stuffā€¦

1 Like

Nice work! :+1:

I have an M5Stack ATOM RS485 lying around which packages an ESP8266 + RS485-to-tll module together. It seems like a good (the best?) option for everybody who wants to use your solution without having to solder/use a breadboard.

I was planning to use it as an ModbusRTU-to-TCP bridge (via this library) to validate the use of the RS485-pins on the inverter. But youā€™ve already proven that these work as expected!

It seems to be a nice alternative for using my integration, maybe the only difficult thing to achieve via ESPHome is reading the optimizer-data via the Huawei-specific ā€œfiles uploadā€ mechanism. I do plan to add native ModbusRTU-support to the library/integration in the future, and I might even make it the recommended way to use my library, as a lot of users struggle with getting the networking-stuff to the inverter right :upside_down_face:

Note: you can use ā€˜WLCRSā€™ to get a 5% discount in the M5Stack-store.

2 Likes

Hi and first a big thanks for your contribution! However, I am struggeling to set it up. When I paste your yaml code, the esphome device goes offline. When I comment out the sensor parts, everything works. I also get some errors regading ā€œlambdaā€ when reviewing the code in the file editor.
Unfortunately, I have no coding knowledge. Any idea what could be wrong? Note that I have not connected my esp to the inverter yet.
Thanks,
/Martin

@jesusrop did you change anything in the setup of the fusionsolar app for activating the rs485 or is this data always coming out of the com port.

No, i did not change anything in the fusion solar app

Hi,

did you get it right? Iā€™ve checked the code in the repo against the last esphome version and seems fine.

Iā€™ve had some bad esp specimens. Have you tried a different microcontroller?

Also, AFAIK the esp2886 does not have a HW UART. I use this code with an ESP32.

If you have any log output I can try to check it to see if I find any errors, but Iā€™m no programmer neither.

Good luck!

@jesusrop Do you have any pictures on how you connected the esp to the rs485 board? I am not able to get any data out of my invertor with this setup. I think I have connected everything up like you described in the wiring section. But a pictures tells more then 1000 words :wink: and also probably my incorrect wiring.

By using Modbus RTU AFAIK, all data is available without any special access, but can you tell me if the FusionSolar app continues to work correctly, and if it remains available for the installer???
Parameters defined as RW and WO in MODBUS Huawei Solar Inverter Interface Definitions.pdf, are they changeable using Modbus RTU AFAIK (and what happens to inverter updates by Huawei??)

Connecting the hardware to the inverter bus gets logged in the inverter memory? My setup is under warranty and I donā€™t really want to give them reason to void my warranty just because Iā€™ve connected my device to the inverter.
Iā€™ve managed to pull data over IP, but itā€™s a horrible setup. One esp that talks to the inverter and another one that sends data to a mosquitto server. The two esps should communicate over serial/i2cā€¦unreliable.