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.
 
This is fascinating - But I suspect my programming days are behind me now.
Is anyone aware of a method of achieving this goal with Enphase microinverters? I have a feeling I will need to look for a proprietary approach as I think Enphase lock down access to their inverter management system...
We have Enphase micro inverters with an Envoy gateway. You can poll the Envoy to get the data. I haven’t played with it yet, but there’s sample code out there that ChargeHQ uses.
 
I don't have experience (yet with the latest Enphase gateways, but the issue with the gateways is the frequency of data updates. 5 minute updates isn't going to cut it - ideally you need data on a per-second basis (maybe 5 seconds would be good enough) and would then be able to feed that into your charger at that speed if necessary, too, to limit charging speed. 1-minute data is probably "good enough" for most cases, though, but house loads and clouds can change things quickly enough that you'd like to have more resolution.

With the latest Enphase systems which can support whole house whole energy consumption monitoring, the data must be in there somewhere to support integration with Enphase batteries without having to go to the cloud, but I'm not sure if there's a way to get the data out at the frequency needed to support charging your car with excess solar production.
Thanks for that ave. I knew the Enphase gateway is the restricting factor (but wasn't aware of the exact reason).
We are looking at adding Enphase batteries when they become available here in May. I'll talk to the installer (who also did our Enphase PV install) and see what he knows about tying it all together. I believe adding the battery(s) may well mean an upgrade to the gateway, so that may resolve the situation.
Given that charging EVs from solar is only going to be a bigger and bigger, I can't believe that companies like Enphase can ignore it for long!
 
Enphase have EVSE in development at the moment, apparently about 12 months away. They’re talking about it supporting V2L, but I doubt that will work with our cars. I think the Enphase stuff is a good product, and seems to have good support - we had an inverter die the day after installation, and it was replaced within 48 hours. I played a little bit with HomeAssistant polling the Envoy a while back, but haven’t touched it in a couple of years.
 
  • Like
Reactions: NeilA
Thanks Micky. We have the Enphase gateway - which appears to be the problem in this context.

Polling the cloud for Enphase (Enlighten) restricts it to every 5 minutes or so.

Polling the local Envoy gives instantaneous readouts.

http://<local Envoy IP>/production.json

which is what I use when feeding solar data to ChargeHQ.

Some of the newer Envoy's or firmware updates may require an extra step of authentication but it's still possible.
 
Hey, cool! ,For my script I also had started with the israndy one too! But mine is for if you have a PowerWall. With that, and a raspberry pi (or any always on computer which can run a docker container), I contributed my script to this github project: GitHub - jasonacox/pypowerwall: Python API for Tesla Powerwall and Solar Power Data

Basically, you run the docker container (it allows you to easily query Solar/Powerwall production and consumption) and get teslapy connected, then run my included script tessolarcharge.py from the tools folder (after updating a few of the variables at the top with the IP address/location/etc. of your docker computer) and it'll adjust your car's charging amps to keep it within your available excess solar, and minimize grid exports/imports. It's not quite as easy as downloading a mobile app, but $60/year for a subscription eats into your solar savings, and DIY may be worth it to some.

I have Envoy/Enphase microinverters too and had some python to do the authentication rigamarole, but I don't have consumption CTs in the Enphase system, so it would have to guess my home usage.
 
  • Like
Reactions: Hairyman
Thanks for the call out. I moved my app to PythonAnywhere today so I don't have to find a raspberry pie, I'll update my GitHub for TesSense.py when I have a few days under my belt w/o issues. Still just learning how to program with this.
 
Thanks for the call out. I moved my app to PythonAnywhere today so I don't have to find a raspberry pie, I'll update my GitHub for TesSense.py when I have a few days under my belt w/o issues. Still just learning how to program with this.
Your TesSense is great! Thanks again for being one of the pioneers!

Didn't require much to get it working with the Powerwall instead of Sense. I'm still thinking about how I might add in a feature to switch to self powered mode from Balanced mode at 4pm and keep charging the car during times when I get home after 4 and want to recharge with a few hours of solar instead of exporting to the grid during peak. (Now that I think about it it's probably economically better to export to grid during peak and charge overnight in that scenario, especially if I would be a net exporter at the end of the year but it still feels better to charge on your own solar and pay fewer non-bypassable charges).
 
  1. I needed to get my programming brain working again and I've not used Python before.
  2. My daughter was interested in doing the project.
  3. As [Zombie] said, security. I don't use any third-party Tesla apps for that reason too.
  4. However, I signed up for ChargeHQ to check it out, but due to living overseas previously my Google account wasn't set to Australia, making installation impossible.

The current version of the code is 178 lines, including comments. A decent programmer, with the help of ChatGPT, could get it done in a day.

As for working with other inverters... if an inverter has an IP address with an API endpoint that returns JSON then it will work. You'll need to know what data you need from the JSON response, but that's not too hard to work out.
An inverter interface cannot 'Know" what is not being used locally for some other purpose. Talking to inverter seems like a very wrong-headed approach, since at best it can only tell you how much solar is being generated, not what is being exported to the grid. I love this approach of instead asking what is locally surplus, being sent to grid. Sadly, ChargeHQ has chosen to talk to inverters, not panel-based power monitors. Fail to understand why.
 
An inverter interface cannot 'Know" what is not being used locally for some other purpose. Talking to inverter seems like a very wrong-headed approach, since at best it can only tell you how much solar is being generated, not what is being exported to the grid.
Most of the more modern inverters have CT clamps to monitor the grid export/import. This is required because distributor export limits are becoming more common, which requires the inverter to throttle down based on the grid export amount.
 
Yip, but I am thousands of $$'s away from owning a Tesla Solar and PowerWall setup. Lucky guys who are as this is a great feature. Although I used having the Tesla charge controller to add controlling other items around the house, working on adding the Hot Tub now, already have my 10kWh Zendure battery pack on wheels charging on free solar only.
 
So - now i have my charger installed - how would you guys automate this?

I have home battery/solar/export all integrated with home assistant - but have not implemented any command over the charge rate on the car.

there seems to be a open source tesla integration - teslamate - anyone have any experience?
 
there seems to be a open source tesla integration - teslamate - anyone have any experience?
Teslamate is awesome for tracking all the car's stats via the API, but it's read-only. It doesn't control the car in any way.

To adjust charge rate on the fly you'd need something like the thread starter's python script, or one of the many variants out there.
It would be nice if there was a central project that everybody coded to, instead of having multiple variations of the wheel.
 
  • Like
Reactions: SL666
So - now i have my charger installed - how would you guys automate this?

I have home battery/solar/export all integrated with home assistant - but have not implemented any command over the charge rate on the car.

there seems to be a open source tesla integration - teslamate - anyone have any experience?
Piece of cake - install the Tesla integration into Home Assistant. GitHub - alandtse/tesla: Tesla custom integration for Home Assistant. This requires a refresh token be generated by third-party apps to login.
You can install it via HACS, and then control your car charge rate in Home Assistant.
 
  • Like
Reactions: SL666