Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

Charging from Excess Solar with Teslapy

This site may earn commission on affiliate links.
I finally got around to playing with some Python code and the Teslapy module to use the excess solar to charge my car. My daughter (11 yo) helped out over the school holidays to get her more involved in programming. We started off by using ChatGPT to generate sample code for extracting the data from my Fronius inverter and then we borrowed bits of code from the Teslapy documentation, TesSense by @israndy and Suncatcher by @Haselsmasher.

Today was a good test of the code as there was intermittent cloud cover. I check for the solar, house power draw and export data every 60 seconds, changing the amps accordingly. If I have to stop charging then I wait 5 minutes before evaluating whether to charge again or not. There is also some buffer to allow for 1,500 W, but I'm going to increase the to 2,000 W to see if that helps with some grid usage creeping in. Ultimately the clouds are annoying! I saw 13 kW drop to 3kW as clouds pass over.

Anyway, here is the output from today. The grey is solar production, blue line is house consumption and yellow is solar consumption.

1681889080355.png


The bump from 6 am is the heat pump coming on for the hot water. Then I started charging the car after 9 am and finished before 1 pm. The block of usage that drops off after 3 pm is the pool pump. The solar system is 15 kW and I have 3 phase.

I'll clean up the code (my first Python program) and post it to Github for others to look at over the weekend.
 
When your car is on WiFi the API works through the WiFi 🤔. I think what you mean is you’d like the vehicle to have its own local API accessible by devices connected to the same local network subnet, like the PW2 Gateway has.

I did portscan my Model 3 once and there aren’t any open ports.
hmm - so 'sort of' the wifi from the car is going out to the internet and back - i guess what im saying is i'd like to be able to send commands to the car via the wifi enabled charger, or the wifi enabled car, vs having to use BLE to send commands - and the tesla charger already has an interface - why not let me send commands via that.

I can understand why they don't want everyone hammering their servers - that's probably what has been causing their issues, but if you are providing a direct control interface - open it to authenticated devices on wifi as well?

Unless someone knocks up a quick config that allows me to esphome that interface...
 
Seems like an ESP32 would be perfect to translate the API to wifi on your home network, with BLE connection to the car, but would need someone to convert Tesla's code from Rust to something that could run on microPython? (I guess a raspberry pi zero w in the garage could do it running Rust, but that's more setup to get an OS configured too).

I had been running my solar and Powerwall control python script on a raspberry pi in my network closet before deprecation of the owner api, so I need to do something different.
 
I use an OpenEVSE to charge both my EVs. It is on WiFi and has a huge range of built in functions including charge from excess solar. The API is very flexible and allows a number of techniques but in my case I use MQTT and Python (though it could be anything). I do not have to worry about car AP!s. Has been working fine for almost 6 yrs on Zoe and over 2yrs on the Tesla. Here is a typical day with the Tesla taking much of the excess solar and the balance going into two LFP banks. The only thing I have set in the Tesla is the 80% max. This display is from EmonCMS but I do not use Emon for any of the car charging- just to display what is happening.
 

Attachments

  • excess_solar.png
    excess_solar.png
    89.3 KB · Views: 30
I use an OpenEVSE to charge both my EVs. It is on WiFi and has a huge range of built in functions including charge from excess solar. The API is very flexible and allows a number of techniques but in my case I use MQTT and Python (though it could be anything). I do not have to worry about car AP!s. Has been working fine for almost 6 yrs on Zoe and over 2yrs on the Tesla. Here is a typical day with the Tesla taking much of the excess solar and the balance going into two LFP banks. The only thing I have set in the Tesla is the 80% max. This display is from EmonCMS but I do not use Emon for any of the car charging- just to display what is happening.
Going with an EVSE that has good API support would be ideal, but I also have a Powerwall and am looking forward to a future where the car(s) sitting in my driveway can suck up as much excess solar as I can produce and then use bidirectional charging to send it back to the home allowing us to basically go off grid (recognizing this would be similar to the battery use to drive about 20 miles a day in my current usage for the 5kwh we currently use from the grid when our Powerwall drains to 30% overnight before solar production recovers), and it looks like that may be possible with the Tesla chargers and future cars via their "PowerShare" support... So probably going to have to still deal with the Tesla APIs...
 
  • Like
Reactions: Jules22
I would like to share my project which I wrote to charge my Tesla using excess solar energy.
It combines power usage information gathered from eGauge to control the charging rate over Bluetooth using the Tesla Vehicle Command SDK It also integrates with TeslaMate for vehicle location and charging need determination.
Check out PVCharge!
 

Attachments

  • energy_graph.png
    energy_graph.png
    262.6 KB · Views: 7
Last edited:
I would like to share my project which I wrote to charge my Tesla using excess solar energy.
It combines power usage information gathered from eGauge to control the charging rate over Bluetooth using the Tesla Vehicle Command SDK It also integrates with TeslaMate for vehicle location and charging need determination.
Check out PVCharge!
Thanks for sharing this! Looks like you have done the hard work that will make it a lot easier for me to transition from using the owners API via teslapy to the BLE local commands to excess solar charge while production prioritizing the PowerWall to get full each day. Need to spend some time playing with it.
 
  • Love
Reactions: solarguy7
I have been exploring Home Assistant to try to get back the functionality that Tesla took when they shuttered the hobbyists API

The Owner API still works. At least it’s still working for me…

At some point it might stop working, and then I’ll look at the Fleet API options. Hopefully there will be a free hobbyist tier with say 10 calls/day permitted or something.