A few weeks ago I wrote of a project I was starting that would adjust the charging rate of a Tesla based on the electric production coming from solar panels. The goal is to "capture" excess solar being produced (i.e. power that normally would be sold back to the utility) and direct it to the car. There are two drivers for this goal:
Since "excess power" can vary widely through the day (solar production can change based on clouds, weather, etc.; and in-house consumption varies as well with tasks such as cooking, laundry, etc.) some form of automated solution is desired to respond to these variabilities and adjust the car charging rate as needed.
The First Half Of The Solution
Prior to the car's arrival I put together some basic code to talk to our Eagle-200 hardware device. This little box connects wirelessly to our smart (electric) meter and reports whether electricity is flowing to the grid or being pulled from the grid. This is the key information that is required when deciding if the car charging rate should be increased or decreased.
The Second Half Of The Solution
Now that we've taken delivery of the car the second half of the solution has been able to be put into place: communicating with the car using Python. Initial interactions with the car's API was a fascinating experience all on its own. The amount of car information accessible via the API is simply astonishing. More on this will be written in a separate post. In order to implement this project the Tesla API is being used to:
After establishing the basics of how to communicate with the car, work could begin in earnest to debug and refine the software. After about a week of work the software is now in a pretty stable state - successfully changing the rate of car charging based on leftover or "extra" power coming from the solar array.
The images below show (on the left) a graph of solar production on a recent day and (on the right) a graph of car charging (amps) through the day. All adjustments to car charging (including identifying when the car was physically unavailable for charging and restarting charging on its return) were handled automatically by the software.
Anyone interested in running this solution is welcome to have it - free of charge. The code needs to be "cleaned up" to make it easy for users to change some settings based on how they would prefer the software to behave (e.g. how often the system checks to see if adjustments need to be made). I will also be putting together some documentation/instructions for getting the system running.
If you wish to be notified when this is ready for distribution please send me an email. I will contact you when it is ready for download. Or watch this site for new blog posts on the topic.
My wife recently read Ashlee Vance's book about Elon Musk. She found it compelling - and reported I would as well. She was right. I loved it.
As a result of learning more about Musk, his vision, and his drive we decided to order a Tesla. Delivery is a ways out (Mar 2022). But that hasn't stopped us from thinking about what driving will be like with an electric vehicle, and figuring out ways to use it as efficiently as possible.
Since we already have solar panels on our house, we started thinking about whether we'd need additional solar production, as well as strategies for optimizing charging the car. It would be great if we could automatically adjust car charging based on electricity being produced by our solar array and electric consumption in the house ... all in real time. We want to see how much power we really need to meet our needs.
Monitoring Solar Output
A number of months ago we decided we wanted a better real-time handle on whether we were sending power back to the grid or pulling power from the grid. We bought an Eagle-200 from Rainforest Automation. This little box (~$100) connects (via Zigbee) to your smart electric meter. There is a nice phone app that provides a view of what is happening at the meter. This enables us to see if power is being sent to the grid (solar production exceeding current household use) or the opposite - we're pulling power from the grid.
Controlling Car Charging
The Tesla's phone app enables the user to start and stop car charging, charging based on time of day, and also charging speed.
Putting Them Together
The easiest solution to synchronize the two is to look at the Eagle-200's app and see if excess power is going to the grid, and then use the Tesla's app to start or stop charging as appropriate. While this method clearly provides benefit, it's not ideal. Weather changes through the day impact solar production. Usage in the home also varies. This results in sometimes significant variations in how much energy is being returned or pulled from the grid at any given moment. An automated solution would be much more effective.
Fortunately both the Eagle-200 and the Tesla have APIs that can be used to programmatically communicate with each device.
Since I have the Eagle-200 I was able to work out getting instantaneous power data from it into a Python program. I wrote a simple program to start/stop car charging, as well as adjust rate of charge based on power flow at the meter. Obviously I need to actually have the car before the solution is truly implemented. But placeholders have been created where car-specific code will be placed when we take delivery of the car and the connections can be tested. (I'm also confident the code, as written below, won't behave as expected when it really gets connected to the car. I always surprise myself with unexpected realities when testing software.)
Hopefully a simple solution like this will enable us to maximize the utilization of power being generated by the solar array.
Thanks to Lalit Pandit for help with JSON and Python!