twistedpear
New Member
Thought I'd share my journey of integrating data from the SolarCloudSystem/EG4 API directly into Home Assistant using custom sensors and scripts. This approach bypasses alternative solutions that rely on LuxPower or Solar Assistant, providing a direct connection to the web API ( e.g.
) . Additionally, I'll share a little about reverse engineering the API, defining an OpenAPI Spec, and creating a simple Python script for data retrieval.
I am very much at the beginning of my Home Assistant journey, but maybe this will help someone. There are plenty of improvements to make, especially around timing and handing of errors. Also note that my experience is limited and only with a SINGLE 12000XP, so I don't know the values for other inverters though MOST would likely be the same.

The HA integration is setup as follows (I attached the files, except secrets.yaml) :
See the config files and steps above
Stay tuned for updates on my progress!
I am very much at the beginning of my Home Assistant journey, but maybe this will help someone. There are plenty of improvements to make, especially around timing and handing of errors. Also note that my experience is limited and only with a SINGLE 12000XP, so I don't know the values for other inverters though MOST would likely be the same.

The HA integration is setup as follows (I attached the files, except secrets.yaml) :
- create secrets.yaml entries for account, password and serial number.
- eg4_account: <username to log into monitor.eg4electronics.com>
- eg4_password: <password to log into monitor.eg4electronics.com>
- eg4_serial_number: serialNum=<serialnumber of the inverter you want to monitor>
- create a shell_command (configuration.yaml) to perform authentication and capture the provided cookie (JSESSIONID)
- create an automation (automation.yaml) to run the shell_command on interval or when the API call fails
- create a command_line sensor (configuration.yaml) to read the token captured in 2.
- create REST sensors (configuration.yaml) to pull data, using the cookie from 4 and assign it to attributes
- create template sensors (configuration.yaml) to read and manipulate the REST sensors attributes
- restart home assistant
- add info to your energy dashboard
- create your own dashboards
Reverse Engineering the EG4 API
The SolarCloudSystem/EG4 API doesn't have official public documentation. To explore the API:- I intercepted the network traffic using browser developer tools and MITMProxy to observe API requests.
- From these requests, I built an OpenAPI Spec to simplify interactions and used that in Insomnia and created an insomnia collection (file included)
- With this spec, I wrote a simple Python script to query the API, which I later adapted for use with my ESP32 project (https://diysolarforum.com/threads/eg4-rest-api.98576/post-1361390)
Creating Custom Sensors in Home Assistant
Since no existing integration directly connected to the API, I created custom REST sensors and template sensors in Home Assistant, as I learn Home Assistant. I've seen a few "official" integrations and may produce something like that later (if needed).See the config files and steps above
Next Steps and Future Plans
Currently, this integration is read-only, but I may expand it by:- Implementing control functionality for generator start/stop.
- Setting parameters such as Charge current
- Writing a dedicated Home Assistant Integration for improved installation and user experience.
- May make considerations for connecting directly to the inverter on the local network.
- Creating a YouTube Tutorial to guide others in replicating this solution...but maybe not lol.
Feedback and Collaboration
If you're working on a similar project or have insights on optimizing this integration, I'd love to hear from you. Whether through a dedicated forum post or future video content, I’m excited to share what I’ve learned and improve the solution further.Stay tuned for updates on my progress!
Attachments
Last edited: