Solar Car Charging Dance In Software

After thinking about how to use the solar power my home generates in the most efficient way I realised that this is a generic problem. Effectively we have three types of devices in play :

  • Generation Sources. eg. my solar panels, the house battery, the grid.
  • Switchable Consuming Devices. eg. My car, a heat pump, the house battery. The load generated by these devices can be turned on/off.
  • Background Load. The overall usage at the site. eg. my house load.

This general abstraction is a way of trying to come up with a common interface for each type of device so that we can easily add new devices as households get more connected.

Notice that the house battery is both a generation source and a consuming device as it can both proved power to the house when it is discharging, and consume power when it is charging.

My Tesla can only consume power, but Vechicle To Grid and Vehicle To Home technology is growing and vehicles like the Ford F150 Lightning recently released in the US are providing this. In this case the vehicle can become a generation source for the house as well.

So the general idea of the software is to set priorities and rules for how power is routed within the home. i.e. we want a system that pulls information from all of these devices regularly and then makes decisions on what to turn on/off or adjust the level of consumption.

My home is fairly straightforwards as I have the following generation sources :

  • Solar panels. (the device I communicate with is the inverter).
  • The National Grid. (the local power grid)
  • House Battery. (Connected to the solar inverter).

I only have two Switchable Consuming devices :

  • House Battery.
  • My Tesla.

Then I have the house that has a background load running all the time.

I could have used the data stored in Prometheus to get much of the required information. However, in an attempt to simplify the solution I have instead called out to Solismon3 to pull information directly from the invertor.

To talk to the car I use a simple Java wrapper around the Tesla API.

At a simple level, the system polls devices regularly to determine what the current state is. The calculation is simply to determine if we have an excess of power or a deficit.

My approach is simple :

Calculate gridPower - power going to or from the grid. (-ve value means we are consuming).

Calculate batteryPower - the power going to or from the house battery. (-ve value means we are discharging).

The excess or deficit power available is therefore the gridPower+batteryPower.

If this value is >0 then we have excess power that we can send to other devices. If it is <0 then we have to either reduce the consumption of a device or switch it off.

So the SpringBoot application simply performs this calculation every few minutes. If it has an excess of power say 6kWh, it offers that to the highest priority chargeable device. That device calculates how much power it can use, adjusts the charge rate and returns any leftover power to the software. Any leftover power is offered to the next highest priority device etc.

When we have a deficit, reverse calculations are performed.

As with all things life is a little more complicated than this. For example, it isn’t desirable to turn a car charger off as a cloud passes over the solar array for 5 minutes (but it might be desirable to turn it off after 15 mins) etc.

A control plane was also needed to allow things to be overridden. eg. I’m leaving on a long journey first thing tomorrow and the car has to be charged to 90% by morning or I’ll have to stop and charge on the way.

I’ve had a simple Docker container running on a Raspberry Pi that has happily automated this throughout the summer.

I’ve been very happy with the results and it has had a measurable impact on our energy costs.

Overall Impact

The above shows that 83% of all the electricity we have used throughout the summer has been provided by solar.

A quick explanation on ‘Room to charge’ for my Tesla. It isn’t advisable to leave the battery system with a charge greater than 80% if it isn’t being used for a longer trip. This is a limitation that has been removed in newer battery packs. So for the really sunny periods when the car was already at that charge level then we had to export to the grid. Our peak generation day this summer was June 3rd when the panels produced 65.5kWh. Despite filling the house battery and 20kWh into the car we still exported a significant amount of energy that day.

When the system has been running and the car has been home with room to charge we have reduced the exported energy to under 1kWh per day.

I can’t justify the extra expense of adding significant additional battery capacity to my solar installation with its current pricing. However, having crunched the numbers, vehicle to grid/home would have vitually eliminated all our grid consumption through the entire summer. It would only have been weeks when we needed to perform longer trips in the car on repeated days that would have caused us to import any energy at all.