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.
I'm struggling a bit with my approach here, and soliciting input from those who get what I am looking to do... .

At 10pm I wake up my car to see if it is plugged in. If so, done. Easy.

If not, I want to start querying every 60 seconds to know with a minute that it was plugged in (because I need to stop some other tasks once I actually plug it in). If I poll the car every minute to see if it is plugged in, will that prevent it from sleeping? On the other hand If I wait until the vehicle endpoint shows offline, I don't have confidence that it wasn't plugged in between my 10pm check and the time it took to go back to sleep... I do know that if the car is asleep AND not plugged in that I could monitor the vehicles endpoint every minute and it would HAVE to be woken in order to be plugged in.... I just don't know how to handle between checking at 10pm and the car going to sleep....
Suggestions?
 
The keepalive timer is set to 10 minutes. So pulling data with a frequency of every 10 minutes or less will keep the car awake.
SO, if I wake the car at 10pm and it is not plugged in and then I check if the car is awake in 11 minutes, if it is asleep, I have no way of knowing if it got plugged in during the 11 minute wait.... But if I check the car itself within the 11 minutes I will keep it awake.....
 
Can't get the streaming api to work either on Model 3 (2018.21.9 75bdbc11)

Looking through the APK, I found a "new" streaming endpoint:
Code:
StreamingServerEndpoints={LOCATION_STREAMING:"streaming/",AUTOPARK_SUMMON:"connect/"}

but I am unable to connect, server seems to not be able to connect to the car.

Code:
{"msg_type":"data:error","tag":"${vehicle_id}","value":"disconnected","error_type":"vehicle_disconnected"}

If anyone wants to try the new endpoint on their Model S or X I can send some sample code over

I can confirm another Model 3 that returns the same result and also a Model S that doesn't work with the old streaming endpoint is also receiving the vehicle_disconnected message!

Surely these would still have the location working in the Android app which uses this data stream, so there must be something we are missing.
 
  • Helpful
Reactions: apacheguy
I can confirm another Model 3 that returns the same result and also a Model S that doesn't work with the old streaming endpoint is also receiving the vehicle_disconnected message!

Surely these would still have the location working in the Android app which uses this data stream, so there must be something we are missing.

It can still get location and speed from the vehicle state endpoint. This is what the iPhone app seems to do with mine since it only updates once every 5 s.
 
Doh, turns out the new Speed Limit mode's property, current_limit_mph, and the Set Limit's property, limit_mph, are both actually double data types.

Makes sense though, those using the metric system would have an imprecise limit if rounding off to integer MPH.
 
Last edited:
I'm unable to play with any of the speed limit stuff for some reason.

Works using the mobile app, but directly hitting the API myself following @SG57 's guide, i keep getting this response from the server:
Code:
{"response":{"reason":"invalid_limit","result":false}}

Can anyone shed some light?

ps this is my request body:
Code:
{"limit_mph":80}

as far as i can tell, my API request is upto spec.

EDIT:

Ok this is really getting weird. I set the PIN via the app, but didn't clear it. Tried to activate speed limit mode via the API myself, and it said incorrect pin. I'm 100% sure the PIN is right. No matter what I input it doesn't want to work.
 
Last edited:
@dpskipper , limit_mph must be a double. Try the following:
Code:
{"limit_mph":80.0}
To your second issue, Speed limit mode is different than how valet mode does it. You must supply a new pin or the correct pin when enabling the mode, disabling the mode, or clearing the pin.

The only command that doesn't require a pin is the speed limit set limit command, however this command requires speed limit mode to be disabled.
 
@dpskipper , limit_mph must be a double. Try the following:
Code:
{"limit_mph":80.0}
To your second issue, Speed limit mode is different than how valet mode does it. You must supply a new pin or the correct pin when enabling the mode, disabling the mode, or clearing the pin.

The only command that doesn't require a pin is the speed limit set limit command, however this command requires speed limit mode to be disabled.
Still getting invalid limit.

Even when I set the pin myself using the mobile app, when I try to revoke it using my script, it still says invalid PIN.

Very strange indeed.

EDIT:

I've verified that speed limit mode works via the Android App. Using a script, dosent matter what I send: activate, deactivate set limit, or clear pin they all return an error. I'm scratching my head as to what the problem is.

I can't even activate the mode, it says PIN code not set. I'm supplying the PIN in the body.
When I set the PIN via the Android app and repeat, it says invalid PIN.

Very strange.
 
Last edited:
Yes I actually managed to figure this out myself in the end.
It works fine for me. Model S 2018.21.9

Can you provide a plaintext example of this subscribe request? I'm unable to get my new Model S on version 2018.26 3bbd9fd to connect with the old stream API. I'm trying to use the new stream API and I'm sending a request like:
Code:
{'msg_type': 'data:subscribe', 'tag': '<vehicle ID>', 'token': '<base64 encoded email:token>', 'value': 'speed,odometer,soc,elevation,est_heading,est_lat,est_lng,est_corrected_lat,est_corrected_lng,native_latitude,native_longitude,native_heading,native_type,native_location_supported,power,shift_state'}

When I try to send that with wsta I get:
Code:
Disconnected!
VERB 1: Error: NoDataAvailable
 
Can you provide a plaintext example of this subscribe request? I'm unable to get my new Model S on version 2018.26 3bbd9fd to connect with the old stream API. I'm trying to use the new stream API and I'm sending a request like:
Code:
{'msg_type': 'data:subscribe', 'tag': '<vehicle ID>', 'token': '<base64 encoded email:token>', 'value': 'speed,odometer,soc,elevation,est_heading,est_lat,est_lng,est_corrected_lat,est_corrected_lng,native_latitude,native_longitude,native_heading,native_type,native_location_supported,power,shift_state'}

When I try to send that with wsta I get:
Code:
Disconnected!
VERB 1: Error: NoDataAvailable

Your request looks fine, the same as what I am sending.
New cars seem to return the Disconnected error, i've had this confirmed by a few owners of newer Model S, X and 3, however my 2017 Model S connects and works fine.