Python bindings for the Model S API

Python bindings for the Model S API


For those inclined to programming I posted python bindings to the Model S REST API:
It makes it possible to schedule charging time and monitor various stats (battery, driving locations, etc). I'm sure new usage scenarios will emerge with these kind of tools available to developers & users.

prash.saka | 09. Februar 2013

Nice. Thanks.

Hills | 09. Februar 2013
Does one need programming expertise to understand and take advantage of your link?

jat | 09. Februar 2013

@Hills - yes, you would need to be able to write a program in python to be able to use it.

joepruitt | 09. Februar 2013

I have a set of PowerShell functions as well if anyone is interested. I'll put them up on Github if anyone wants them.


aa012a | 09. Februar 2013

I'm finishing a php class for it. If anyone is interested, you can email me to my user at

Brian H | 10. Februar 2013

Scheduling! Stick a GUI on it any you've got a boatload of customers.

Brian H | 10. Februar 2013

typo: "on it and you've ..."

jat | 10. Februar 2013

@BrianH - scheduling is a bit harder for most people, since the car doesn't have a timer yet and therefore the client using these APIs has to initiate charging at the right time. That means the machine telling the car to start charging has to be on, so for people that turn off their computer when it isn't being used they need some place else for it to run.

I'm working on a web app that will run on Google App Engine and provide that functionality, though it may not be done before 4.3 is released which looks like it will have a simple charging timer.

dtaubert | 10. Februar 2013

Very cool. Thanks for sharing this!

xenogeek | 10. Februar 2013

Very cool! Thanks for sharing.

Brian H | 10. Februar 2013

?? The car must have a clock! The OS' time function, if nothing else.

sergiyz | 10. Februar 2013

It does have a clock alright...
It should have cron too, but it's not clear if any of this is exposed via API, and it's not clear what effect the sleep mode has on all of that.
External trigger looks like a better idea to me provided that something is still handling external connections (wake on network activity) while the car is sleeping.

dbullard | 10. Februar 2013

Anyone work on a Java version yet? I was thinking of basing one off of the Python bindings and making a front-end for it.

prash.saka | 10. Februar 2013

@dbullard ... Java version would be great.

But, why do you need the Python bindings. Can't you use the REST APY's directly? More information is available at I got this URL from dlaprise's README file

jat | 10. Februar 2013

@dbullard - yes, I am working on a Java library that can be used on the server, Android, and compiled with GWT.

@prash.saka - sure, you can directly make the calls, but it is nicer to have more structure about it and somebody else to worry about keeping them up to date when the APIs change :).

dbullard | 10. Februar 2013

Actually, I'd missed - that will save me a lot of time!

I typically like to look at other folks implementation, even in other languages, as it gives me ideas I might not have thought of.

"Steal from the best, and write the rest!" is my motto.

joe | 04. April 2013

@jat: Is your Java library published somewhere? Now that I have my Model S I'm ready to start playing with the APIs. I was poking around looking for a Java library and I ran across this thread.

jat | 04. April 2013

@joe - not yet, a number of things came up so I haven't finished it yet. It probably won't happen until after taxes are filed.

joe | 06. April 2013

@jat: Good luck with your taxes. I'll check back periodically and look for an update.

Prasad B | 02. Mai 2013 - any luck with the java code? I can login successfully, but I get only one cookie "_s_portal_session", not the second one "user_credentials", without which I am unable to use subsequent REST API

Prasad B | 02. Mai 2013

Ok, I was able to get the Java login working - the rest should be easy. The key piece that needed to be done was to set the FollowRedirects to false (HttpsURLConnection.setInstanceFollowRedirects(false)) otherwise the "user_credentials" was not being sent for subsequent calls.

teichsta | 03. September 2013

> Ok, I was able to get the Java login working - the rest should be easy.

Are you going to share your (Java) code? Would be great to integrate the Model S with HomeAutomation Systems like openHAB … using the TTS-Engine or the Philipps Hue to inform about the current load factor, using Location Data to activate certain "coming home processes", etc..


Thomas E.-E.

sranta | 01. Dezember 2014

Trying to set temperatures using "set_temps" method but pretty much every value sets the temperature to 17C or the equivalent to "LO" on the app.

sranta | 01. Dezember 2014

I found the issue in "" in the "set_temps" method. The method had:

def set_temps(self, driver, passenger):
p = self._command('set_temps', driver_degC = driver, pasenger_temp = passenger)
return p['result']

This should be changed to:

def set_temps(self, driver, passenger):
p = self._command('set_temps', driver_temp = driver, passenger_temp = passenger)
return p['result']

As downloaded, the temps always get set to 17C when using set_temps for any value since the request to set the temp is not made properly (17C is the default set temp if the request is incorrect to Tesla).