Pool on Solar

We own a pool, and we recently installed Tesla solar panels and batteries. Our goal was to automate the activation / deactivation of the pool cleaning system so that it only runs when excess solar power is available at our place, instead of drawing electricity from the grid or our home batteries. In technical terms, this is called “time shifting” of the load, which is a way to lower carbon emissions, by using electricity when it comes from low carbon sources (the sun).

This is a feature inspired by “Charge on Solar” from Tesla, where software ensures that your car charges only when there is excess solar production at your home:

Screenshot of Tesla's Charge on Solar feature in the mobile app
Tesla's Charge on Solar: after a defined minimum, the car will only charge at home if there is excess solar production.

We wanted to do the same for another big consumer of electricity: the pool pumps. Used for filtering, cleaning and pushing water through solar heating panels, they consume around 4kW when on. Luckily, a connected controller existed for our pool system.

The idea is rather simple: On a schedule, fetch the current energy production from the Tesla solar system, and if the difference between solar electricity production and home electricity consumption is above a certain threshold, turn on the pumps. Turn them off if there isn't enough excess power. We call this “Pool on Solar”.
In the end, this is the result:

Screenshot of Tesla's Charge on Solar feature in the mobile app
Breakdown of the energy production on a sunny day: the home consumption, in blue, rises to 4kW (the consumption of the pool pumps) when there's enough production (total production is the curve) and turns off when the production drops. Green is when the home battery is charging, and grey is when the excess energy is exported to the grid. In this example, the car was not plugged in, so "Pool on solar" wasn't coupled with "Charge on solar".

It turns out that both our pool equipment and Tesla solar system are controllable by making API calls to remote servers, so we decided to host this home automation in the cloud (Google Cloud) for simpler maintenance instead of running it on a local server.

The architecture is very simple: a Cloud Run job runs every 15 minutes via Cloud Scheduler. It loads Tesla and iAquaLink credentials from Secret Manager. We use the teslapy Python module to get a live status of energy production at our house, then the iaqualink Python module to turn on/off the equipment. All parameters are configurable (proto) and stored in a proto txt file, mounted in the container via a Cloud Storage volume mount, and parsed when the job is executed.

Because our outdoor lighting is also controlled using the same equipment, we added some extra code to turn on the lights when the sun sets and when there's sufficient battery capacity left, using the suntime Python module and the latitude and longitude of our city.

Find the code of Pool on Solar on GitHub and feel free to use it if you have a similar home setup.