The Unexpectedly Direct Path to Building the APC ECU-3 Solar Data Collector
A commentary on why everything should have API's
In the world of technology, the path to innovation is often paved with challenges. As a tech enthusiast, I've found that these challenges often act as catalysts, driving me to think creatively and develop solutions that push the boundaries of what's possible. My latest project, integrating data from an APC ECU-3 device with Home Assistant, is not an example of this.
The APC ECU-3 is an old and basic tool for those harnessing solar power. I’ve found that in Australia it’s unfortunately the device you’re likely to get stuck with installed with your panels. It very slowly provides a wealth some data about your solar power system. However, its lack of an API presented a significant challenge when it came to integrating this data with Home Assistant.
The system shows a screen like this when visiting its web page. The goal is to scrape all the info out of this table and import it into Home Assistant sensors.
I set out to build this bridge between this silly page and Home Assistant. This tool retrieves, parses, and formats the data from the APC ECU-3 device, transforming it into a JSON file that Home Assistant can interpret.
With no API to call, I had to get creative old school. I wrote a simple script using Python's requests module that fetches the data directly from the APC ECU-3 device's parameters page. The data returned was a dense basic HTML page filled with valuable basic information hidden directly exposed within an HTML table.
Next, I had to extract the required data points from this HTML table. BeautifulSoup, a Python library for parsing HTML, was instrumental here. It allowed me to sift through the HTML structure, identify the data table, and pull out the rows containing the information I needed.
I then transformed this data into a format that Home Assistant could understand. Using Python, I created a dictionary where the keys were the Inverter IDs and the values were lists containing the power data for each inverter. Then I had to remove the units since Home Assistant will put its own units in place and I would get “140 W W” in my graphs. The final step in this process was to convert this dictionary into a JSON file and save it on the Home Assistant server in an accessible location so other scripts can access it.
To help others with the integration, I wrote another Python script that automates the generation of the relevant section of HA’s configuration.yaml
file. This script reads the inverter IDs from the ECU and produces the corresponding sensor entries for the configuration.yaml
file.
Not exactly difficult, but it is tedious if you’re unfamiliar with my janky setup.
In Home Assistant, I set up an automation to run the Python script every minute. This ensured that the solar power data in Home Assistant was always up-to-date as updated as possible since the ECU doesn’t seem to provide regular updates and often fails to provide any data. The automation, coupled with the sensor entries generated by the Python script, allowed the raw APC ECU-3 data to be leveraged within Home Assistant.
Upon completion, I successfully managed to plot the power output of each solar panel!
Developing the APC ECU-3 Data Reader was a journey filled with challenges boring scripting and hack-y methods. There's still plenty of room for improvement - but at this point, I need your help!
There's an existing project, the APSystems ECU-R component for Home Assistant, which supports models with APIs. Unfortunately, the APC ECU-3 model isn't yet supported. But with our collective effort, we can expand its support to include the APC ECU-3.
So, if you're a fellow tech enthusiast, a developer, or someone with a knack for tackling challenges, I have an ask for you! I invite you to contribute. Whether it's improving the current project or adding support for the APC ECU-3 to the APSystems ECU-R component, your contribution can make a difference.
You can find the source code here: https://github.com/jeeshofone/ha-apc-ecu-3 Please reach out if you have an APC ECU-3 and found this helpful or want to help improve the project.
(I also don’t want to have sole ownership of this technical line of credit)