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

Adjust Tesla charge rate from mobile app, API & PW2 to allow use of excess solar

This site may earn commission on affiliate links.
Thanks @whiten0ise - I’ve PM’d you.
IMG_20211009_093436.jpg


Car got .36 Update this morning... Adjustable Slide for Amps now available.
 
Although the negative FIT is shown in the app, Amber doesn't actually pass it on when they bill you so effectively there's a floor of zero at the moment.
oooh didnt know that, this just started happening last couple of weeks so im not up to my next billing cycle yet. good to know. Either way, i'm now manually charging the excess into my car as planned to minimize export, looking forward to being able to automate it. only manual thing i'll need to do then is physically plug the car in.

Edit: just did a quick decompile the parameter looks to be named "chargingAmps". I dont have the update yet so can't check
is this also where you said it's not from a v4 decompile? I just tried chargingAmps via Postman and I'm getting a 404 error, which could possibly just mean the car doesnt understand the command yet (cos nobody's on 2021.36 yet), or it means the endpoint/params are wrong. If you got that off a v4 app decompile then that should be accurate. Seems plausible tho since the URL is literally set_charging_amps so "chargingAmps" would make sense as the param. Anyway we can test this once 2021.36 is here. *rubs hands together*.
 
is this also where you said it's not from a v4 decompile? I just tried chargingAmps via Postman and I'm getting a 404 error, which could possibly just mean the car doesnt understand the command yet (cos nobody's on 2021.36 yet), or it means the endpoint/params are wrong. If you got that off a v4 app decompile then that should be accurate. Seems plausible tho since the URL is literally set_charging_amps so "chargingAmps" would make sense as the param. Anyway we can test this once 2021.36 is here. *rubs hands together*.
that was from the v4 decompile but yeh I was not able to test it as my car hasn't got the 2021.36 update yet
 
2021.36 finally turned up for my car. Running update now! I'll hopefully know right afterwards whether the API will work :)

Update: Woohoo! Works!! returns true if successful, otherwise returns error on vehicle id etc! This might keep me busy this coming weekend.. hehehe
It’s not fair that the parameter to pass to the `CHARGING_AMPS` endpoint is… `charging_amps` 😭

If only it was that easy to extract the historical PW2 battery charge percentages!!!
 
  • Funny
Reactions: lonertic
Does anyone know if TWCManager can retrieve the current state of charge of attached vehicles?
Yes, but it uses the Tesla API, so you need some data connection, car to Tesla, Wifi or Cellular.
See TWCManager : TeslaAPI.py : def update_charge :
self.chargeLimit = response["charge_limit_soc"]
self.batteryLevel = response["battery_level"]

If so, can you stop charging without sending the api call? (I.e just stop charging from the charger itself)
You can always stop the charging by commanding the charger.
But the car may refuse to restart charging and require manual unplug/plug.

TWCManager does not communicate with the car via the charger.
It would take serious effort and more hardware to access the SWCAN (charger to car via proximity pin) comms.
 
  • Informative
Reactions: moa999
I’d be impressed if you guess the right parameter name in a few minutes. I’ve had no luck “guessing” the parameter name to retrieve historical battery percent charged values from the `calendar_history` endpoint. The known `kind`s for this endpoint are:
Code:
/api/1/energy_sites/{site_id}/calendar_history?kind=power
/api/1/energy_sites/{site_id}/calendar_history?kind=energy
/api/1/energy_sites/{site_id}/calendar_history?kind=self_consumption
/api/1/energy_sites/{site_id}/calendar_history?kind=time_of_use_energy
/api/1/energy_sites/{site_id}/calendar_history?kind=savings
I‘ve tried kind=battery_percent, kind=battery_charge, kind=percentage_charged etc none work so far. You quickly realise that there so many possible names they could have called this that it’s throwing darts in the dark to guess the right parameter name. The odds are close to zero!


Yeah I’ve tried that too. The Tesla App uses SSL Certificate Pinning to verify it is talking to owner-api.teslamotors.com and not some intermediate server pretending to be owner-api.teslamotors.com, so it’s not possible as far as I know to sniff the commands it sends. Otherwise this would be trivial to solve.


Having vehicle-PW2 integration has been on Tesla’s ‘to do’ list for a couple of years. It’s within the realms of possibility that 2021.36 will pave the way for Tesla to build charging from excess solar into their App (saving you the need to roll your own 😄). There’s no need for v3 HPWCs either, Tesla talks directly to the PW2 and vehicle to work out what to do.


You’re in Sydney, who’s giving you negative FITs? You still potentially have an issue with this if your PW2 is full and your car is full and your house is using what it can. You’d need an additional script to turn your inverter off in that situation, and turn it back on again when you can use the power.
I dug it out of the decompiled Android app: kind=soe
 
  • Love
Reactions: Vostok
I dug it out of the decompiled Android app: kind=soe
Woo hoo… it’s working! The historical percentage charged data is there all the way back to when my PW2 was first installed.

It’s recorded only every 15 minutes (whereas power is recorded every 5 minutes) and it’s rounded to the nearest percent, but it’s there!

I’ve set up a separate script to log the charge state every 5 minutes from now on, and record it to 2 decimal places. But I now have the historical data to go with it.

Happy days!
 
  • Like
Reactions: mjhwa
I'm so stoked to hear charging rate appears to be showing up in the API. I just ordered a Model Y a couple of weeks ago. Delivery is currently Mar'22. :(

But....that hasn't stopped me from thinking about an automated charging solution that coordinates charging with solar panel output.

I have an Eagle-200 from Rainforest Automation. It connects to the utility's smart meter. I can now pull into python how much power is going through the meter at any given time. The thought of having a Raspberry Pi in the house running a script that starts/stop charging - along with adjusting charging rate - based on solar panel output......seems way way cool.
 
Last edited:
I have an Eagle-200 from Rainforest Automation. It connects to the utility's smart meter. I can now pull into python how much power is going through the meter at any given time. The thought of having a Raspberry Pi in the house running a script that starts/stop charging - along with adjusting charging rate - based on solar panel output......seems way way cool.
Yes, there are quite a lot of people doing this sort of thing and it feels REALLY good as well as being good!

I use an Onion Omega 2+ on the house system along with an OpenEVSE. Works very nicely and in my case no need for the Tesla API but using that is indeed another way to do this.
 
Yes, there are quite a lot of people doing this sort of thing and it feels REALLY good as well as being good!
I disagree that it's "being good" in the sense of producing an unambiguously overall positive outcome.

What matters for the 'greater good' is the overall level of demand being served by solar (or really, RE / low-carbon generation). Turning your car charger on and off based on your local solar production isn't actually changing the level of solar production, unless you're export constrained, so it's net neutral.

If you are export-constrained, then what you really want to do is charge at a rate that ensures your export limit isn't hit for as much of the day as possible (which might mean charging at a level lower than your solar production at a given moment, in order to shift some of the charging load to a later time when you still expect to be export constrained - noting that a 'later time' might well be the following day, depending on when and how much you expect to use your vehicle next).

Other than that, the most important thing for overall RE in the grid is to shift your demand to times when scheduled RE generation is being curtailed due to low levels of operational demand. Depending on your region and weather this could even be the middle of the night.
 
cafz, I'm in general agreement with what you say. However, us plebs trying to solve the energy equation for Australia is a little daunting. Overall strategies and policies have been lagging for a long time and Australians have done something about it in their own way one of which is with rooftop solar. So now, one of the issues can be oversupply during the day, throttling solar production (particularly in farms- though there are also other issues). As well as "doing the right thing", we are also motivated by things such as money (FIT, demand charging and lots of other things). Indeed, I think the electricity "retailers" are only motivated by money. In my case, I have reduced my household consumption from 30kwhrs/day to an average of about 1-2kwhrs and spread it pretty uniformly through the day/night. This has been through the use of two LFP battery banks, two EVs, home-built vacuum-tube HWS, improvements in a whole lot of electrical areas et al. In terms of "being good", yes I could feed my excess solar to the neighbourhood rather than slurp it into an EV or one of my batteries. I do feed to the neighbourhood sometimes, but always around middle of the day, but the electrical suppliers motivate me financially to do the opposite. Life gets even more complicated when I look at EV charging efficiencies and for small amounts of excess solar, it is much more efficient to go charger->batteries->inverter->load rather than charge an EV. Perhaps I should have just put on solar and done nothing else.....I have also been motivated by the satisfaction of the systems I've designed, built and utilised. So a further complicating factor being human mental health!

I guess in summary, I agree in principle with what you say and indeed it is difficult to be absolute about a lot of these things because of the complexities. For instance, my daughter lives off-grid out in the country. Her system is limited much of most days except in crap weather. She could spend 150K+ for grid connection and feel good that she is feeding electricity to the neighbours plus it being therefore a better overall use of resources but the cost-benefit equation would be ridiculous.
 
  • Like
Reactions: Hungry Mile