Connecting to the New Deye Logger to Home Assistant using ESPHome

Good day!

I just want to share how I managed to pull data from our Deye 8K Hybrid Inverter (SUN-8KSG05LP1-EU) into HomeAssistant.

There exists a myriad of ways to do it but I was having issues establishing a connection with the inverter using an RS485 module and ESP32Dev-C Kit. I was also a bit hesitant on routing another wire into the conduits that our installer has made. There was also connective wirelessly but upon checking, Deye’s latest version of its data logger gas blocked port 8899 from being accessed preventing Solarman-based wireless integration from working (please do correct me if I missed some details on to use it correctly). This got me curious on how else to pull data.

The Deye Cloud app has a “local mode” that connects to the logger via BLE. With this, I was able to monitor the app’s and the logger’s communication and made a YAML file that pulls several values from the inverter that the logger is connected to. I tried to map the values with the corresponding UI fields by comparing them with the screenshot during the data acquisition. I came up with the following values:

Production

Sensor Unit Register
Total Production kWh 0x0060
Daily Production kWh 0x006C

PV

Sensor Unit Register
PV1 Voltage V 0x006D
PV1 Current A 0x006E
PV1 Power W computed (V × I)
PV2 Voltage V 0x006F
PV2 Current A 0x0070
PV2 Power W computed (V × I)
Total PV Power W computed (PV1 + PV2)
Max Solar Power W 0x0035

Grid

Sensor Unit Register
Grid Voltage 1 V 0x0096
Grid Voltage 2 V 0x0097
Grid Power W 0x00A9

Load

Sensor Unit Register
Daily Load Consumption kWh 0x0054
Total Load Consumption kWh 0x0055
Load L1 Voltage V 0x009D
Load L1 Current A 0x00A4
Load L1 Power W 0x00B2
Total Load Power W 0x00B0

Inverter

Sensor Unit Register
Total Power W 0x00AD
Inverter L1 Power W 0x00AF
DC Temperature °C 0x005A
AC Temperature °C 0x005B

Battery

Sensor Unit Register
Battery Voltage V 0x00B7
Battery Current A 0x00BF
Battery Power W 0x00BE
Battery SOC % 0x00B8

Battery Settings (diagnostic)

Sensor Unit Register
Battery Capacity Ah 0x00CC
Battery Empty Voltage V 0x00CD
Max Charge Current A 0x00D2
Max Discharge Current A 0x00D3
Battery Shutdown % % 0x00D9
Battery Restart % % 0x00DA
Battery Low % % 0x00DB

Selling Mode (diagnostic)

Sensor Unit Register
Selling Mode Time 1–6 HH:MM 0x00FA0x00FF
Selling Mode Power 1–6 W 0x01000x0105
Selling Mode SOC 1–6 % 0x010C0x0111
Selling Mode Charge Flag 1–6 0x01120x0117

Please note that these registers are the only ones I could map. If you have a known list of registers, perhaps we could expand these further. If you also find something not correct, please do share.

esphome_deye.yaml

Hi,
I discovered on my 5k-SG05LP1;

245 = Export Power Limit.

244:
Sell to grid= 0
Zero export load = 1
Zero export ct =2

My goal is to create an automation where the inverter output follows the grid power using battery energy. :slight_smile:

Thank you so much—it's working perfectly for me. Could you please share the latest YAML code with any new properties you've identified? I also have one more question: can the same YAML be used for a three‑phase inverter? If you have the details, please share them. I really appreciate your efforts, and I’ll share this information with the community.

Hi @dijin123 !

Glad it's working on your end. I've updated the YAML file to fix some incorrect readings. From what I am seeing, the values are spot-on when comparing to the ones I see in the Deye Cloud website.

About he YAML's usage on the three-phase model, from what I've read, some registers might be different. You can check out kbialek/deye-inverter-mqtt to see if your three-phase inverter is included in the list. I also crossed-reference some registers from kbialek so credits go to them.

Hi @drkdoesha,

Thank you for your quick response. I've successfully integrated my Deye inverter with Home Assistant via BLE using ESPHome to fetch all the data. However, the Wi-Fi logger and the BLE connection aren't working simultaneously. The Deye Cloud sync through the Logger is stop working after we started the code in ESPHome. Is there a configuration option or workaround in the ESPHome code to fix this issue?

Hello, @dijin123 !

Unfortunately, that seems to be a limit on the logger. Once we connect to via BLE, the logger won't be connecting to the Deye Cloud servers.

As a workaround, I did put a reconnect interval. When set to 0, it will not disconnect. Other values would set the reconnect countdown from the time it disconnected. So if, for example, you set the BLE Reconnect Interval to 30s, after the ESP32 reads the values, it will disconnect from the logger then attempt to reconnect after 30 seconds. This allows the logger to also get to report to the Deye Cloud server.

image

I hope this workaround fits your requirement.

You may be coming up against the design limitation of BLE of only one session permitted. This is part of the BlueTooth standard, not something unique to this app. If ESPHome is grabbing the device, then the Deye Cloud might not be getting a word in edgewise.
I haven't looked at the code algorithm - if the Deye device is emitting passive BLE packets, you should be able to sniff them from multiple sources. If a session needs to be established, you will come across this limitation.

You're correct, @IOT7712. I had to establish a session with the logger to be able to capture their communication and retrieve the values.

You have to choose between local, cloud, or both. Maybe the integration can collect the data locally, and spoof the cloud session to stuff the data into the Deye Cloud for the best of both worlds.

RS485 beckons... Dump the BLE traffic altogether - you may find it intermittent and unreliable. You may find the following Protocol Wizard app of use to help you on your journey:

Hi @drkdoesha Thanks. Let me try testing it. Is the BLE Reconnect Interval code that you just shared available?

Oh yes, it does. Give it a try!

Hi @drkdoesha,
It works fine based on my testing. Thank you for sharing the code. My friend's inverter is 3‑phase, and he asked me to help him set up something similar.

Hi @drkdoesha
I ran the code for about 10 hours, but this morning the Deye cloud sync failed again and wasn't working properly. So I restarted the ESP32 device, and then it started working again and adjusted the BLE Reconnect option to 40s. I'm not sure what caused the issue.

I would increase the BLE Reconnect Interval, just like what you've done. I have not explored any other workaround aside from this. Like what @IOT7712 has described, it's a hardware limitation to which I have no plan on investigating further.

IOT7712 is right about the BLE limits. The cloud logger will be constantly fighting for that one session. The only way to get stable HA data with the cloud sync still running is to hardwire to the RS485 port.

Since your friend is on a 3-phase inverter, just a quick heads-up: the standard 3-phase Modbus registers and RJ45 pinouts are completely different from the single-phase models. Also, make sure your ESPHome yaml parses two's complement (S16) correctly for bidirectional data (like battery/grid current), otherwise HA will throw massive wattage spikes during export.