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

Model S REST API

This site may earn commission on affiliate links.
Lullaby, and good night, you are daddy's delight
I'll protect you from harm, and you'll wake in my driveway

Go to sleep, little car, think of AC and DC.
Go to sleep, little car, think of supercharging fast.
Go to sleep, little car, think of free solar energy.
Hush, darling one, sleep through the night
Sleep through the night
Sleep through the night
little?
 
Okay, I'm guessing my car was doing something earlier tonight that was keeping it online while I was polling - for all I know there might be an update there... It looks like it goes to sleep somewhere around 10-15 minutes:

Fri Aug 30 00:06:11 CDT 2013
"state": "online",
Fri Aug 30 00:11:12 CDT 2013
"state": "online",
Fri Aug 30 00:16:13 CDT 2013
"state": "asleep",

...I woke it back up...

Fri Aug 30 00:21:14 CDT 2013
"state": "online",
Fri Aug 30 00:26:15 CDT 2013
"state": "online",
Fri Aug 30 00:31:15 CDT 2013
"state": "asleep",

So it looks like you can call /vehicles and get the state without affecting it. Any command that involves a specific vehicle (e.g., vehicles/001/command/charge_state) appears to wake it up. This means the streaming code will likely have to change a bit:

Periodically call /vehicles:
* If car is asleep, leave it alone. (Don't wake up a sleeping baby!)
* If car is online, and our last poll was "asleep" or "waking", call charge_state to see if we're charging, set up streaming.
* If car is online, and our last poll was "online", and last charge_state poll showed we were charging, call charge_state again (also renews tokens)
* If car is online, and our last poll was "online", and last charge_state poll showed charge complete, don't call charge_state for at least <x> minutes (20? 30? ...basically, allow the car to fall sleep) -- this also provides backwards-compatibility with 4.5
* If car is online, and our tokens have expired, and we have registered a speed, or we registered a location change since our last renewal, renew tokens
* Otherwise, leave it alone.

This has a hole that I'm not sure how we can address... If the car came online (say, from an interior temp check on the app), then the tokens expired, and *then* you get in the car and leave before the app sleeps, the script will not have acquired tokens and won't get streaming data. We won't know, until charge_state is called and new tokens are acquired, that the car is moving, which could be upwards of 30 minutes or so.

Seem right?
 
Last edited:
Assuming, of course, you don't want it to "block" sleep and track vampire load.

True, although I'm guessing few people would still want to do this (mostly for your own tracking of vampire load in always-on mode). You can still track "sleep mode" vampire load when the car wakes up, because you'll see it transition to online and will then call charge_state to track it.

The car appears to stay "online" while charging, and transitions to "online" when you open the charging door and plug in the charging cord, so you won't lose anything. When the car wakes up every 24 hours or so to top off, you'll get a recording of vampire loss through "charge_state" because the /vehicles polling will see it wake up.
 
Last edited:
BTW, I am adding in support for multi-car Tesla accounts, but I have no way to test that it works.
Anyone who has more than one model S on a single tesla account can PM me if they are willing to test.

Can't help you there until the Model X production starts, but if you're willing to hack up changes to streaming.js based on the observations and my ruleset above, I'll give it a run. I know little about .js scripting, and I don't have time right now to learn - job, wife, 4 sons, and 4 college courses not to mention my numerous other projects. :)
 
Can't help you there until the Model X production starts, but if you're willing to hack up changes to streaming.js based on the observations and my ruleset above, I'll give it a run. I know little about .js scripting, and I don't have time right now to learn - job, wife, 4 sons, and 4 college courses not to mention my numerous other projects. :)

Several people are already working on adding support for the FZsleep algorithm in streaming.js.
 
One more data point: I tried running /vehicles in a setInterval once a minute after I drove to work this morning and parked - It stayed in "online" for about 40 minutes and then went to "asleep". This was without plugging in.

Much additional experimentation will be needed.
 
I ran the same experiment coming back from lunch, this time a little more controlled. This time it took only 8 minutes after leaving the car after a drive to go asleep (and less than 1 minute to wake up when I first got to the car.)
 
I ran the same experiment coming back from lunch, this time a little more controlled. This time it took only 8 minutes after leaving the car after a drive to go asleep (and less than 1 minute to wake up when I first got to the car.)

Sorry for diverging from the subject here, but how did you receive 5.0? Seeing as your car was delivered in May and 5.0 hadn't even surfaced back then and there have been no reports of OTA updates aside from betas, I'm just curious.

Also, 1 minute to wake up!? I thought is was on the order of several seconds.
 
I just received my S60 a few weeks ago and would like to use the REST data. Could someone please post a step by step instruction to do that for a non-programmer? I tried reading through this thread but there are 62 pages and it didn't appear there were any obvious instructions.
 
Last edited:
I'm just received my S60 a few weeks ago and would like to use the REST data. Could someone please post a step by step instruction to do that for a non-programmer? I tried reading through this thread but there are 62 pages and it didn't appear there were any obvious instructions.
hans - Do you want to start a Wiki page on TMC for this?
 
Perhaps but first I would have to get myself motivated to address "REST for non-programmers". I'm not 100% convinced that it's possible to usefully explain REST to non-programmers. Isn't it better to point non-programmers to tools like VisableTesla?
Sorry, let me rephrase the suggestion.

I think it's worth starting a wiki to consolidate the "current state" of things, like your post on the languages started to do.

If you think there's a worthwhile section (such as "non-programmers should look here first") then add the section and leave it empty save a comment like "<This section needs attention by a volunteer.>". Crowd-sourcing from there will hopefully address that. :)