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.
Looking at the code I'd be interested as well which parts you've replaced @dirkvm - and if/how this plays out in the long run.

Currently running into the below, although I still get some data through. I do note that the APP also isn't responding well last couple of days.
Code:
11 Mar 20:17:08 - Unexpected problem with request:
    Response status code = 502  Error code = null
 Polling again in 10 seconds...
11 Mar 20:17:18 - Bad timestamp (<html>)
11 Mar 20:17:18 - Unexpected problem with request:
    Response status code = 502  Error code = null
 Polling again in 10 seconds...


I've been running VisibleTesla for three years with very little hicups and it does record trip information on a daily basis, I would expect via the streaming API (I haven't checked). These recordings stopped completely also on March 7th. Last trip recorded on March 6th!!! Coincidence? Let me know if this starts working again for you.

Since then connecting with VisibleTesla just to get status or even via Tesla standard app has been horrible! Can't preheat the car, nothing!
Never had this in 3 years...
 
I've been running VisibleTesla for three years with very little hicups and it does record trip information on a daily basis, I would expect via the streaming API (I haven't checked). These recordings stopped completely also on March 7th. Last trip recorded on March 6th!!! Coincidence? Let me know if this starts working again for you.

Since then connecting with VisibleTesla just to get status or even via Tesla standard app has been horrible! Can't preheat the car, nothing!
Never had this in 3 years...
Unfortunately, with what @dirkvm did above I’m not getting any streaming data either. Not sure if it’s because of my installation, the fact I live in US or what. I have a 2017 model S so I thought I’d be safe but the 6th of March was my demise as well.
 
Unfortunately, with what @dirkvm did above I’m not getting any streaming data either. Not sure if it’s because of my installation, the fact I live in US or what. I have a 2017 model S so I thought I’d be safe but the 6th of March was my demise as well.

This is what I get with this websocket test, copy to examples/streamws.js simple test
(id's and location data removed or edited, only vehicle_id and tokens[0] are used)
Code:
{ ...
  vehicle_id: NNNNNNNNN,
  tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
  state: 'asleep',
  in_service: false,
  calendar_enabled: true,
  api_version: 6,
  backseat_token: null,
  backseat_token_updated_at: null }
16 Mar 08:44:50 - {"msg_type":"control:hello","connection_timeout":0}
16 Mar 08:44:50 - {"msg_type":"data:error","tag":"NNNNNNNNN","value":"disconnected","error_type":"vehicle_disconnected"}

Car is 'asleep', returns a "data:error" message but stays connected.

{ ...
  vehicle_id: NNNNNNNNN,
  tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
  state: 'online',
  ... }
16 Mar 09:08:07 - {"msg_type":"control:hello","connection_timeout":0}
16 Mar 09:08:08 - {"msg_type":"data:update","tag":"NNNNNNNNN","value":"1552723693203,,..."}

After waking up the car, it goes to the 'waking' state then stays in an
'unknown' state for some time and finally goes to the 'online' state.
Even if the car doesn't move, it still returns some "data:update" messages.
Once the car starts moving, the frequency of these messages rises to
about 4 per second.
 
This is what I get with this websocket test, copy to examples/streamws.js simple test
(id's and location data removed or edited, only vehicle_id and tokens[0] are used)
Code:
{ ...
  vehicle_id: NNNNNNNNN,
  tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
  state: 'asleep',
  in_service: false,
  calendar_enabled: true,
  api_version: 6,
  backseat_token: null,
  backseat_token_updated_at: null }
16 Mar 08:44:50 - {"msg_type":"control:hello","connection_timeout":0}
16 Mar 08:44:50 - {"msg_type":"data:error","tag":"NNNNNNNNN","value":"disconnected","error_type":"vehicle_disconnected"}

Car is 'asleep', returns a "data:error" message but stays connected.

{ ...
  vehicle_id: NNNNNNNNN,
  tokens: [ 'XXXXXXXXXXXXXX', 'YYYYYYYYYYY' ],
  state: 'online',
  ... }
16 Mar 09:08:07 - {"msg_type":"control:hello","connection_timeout":0}
16 Mar 09:08:08 - {"msg_type":"data:update","tag":"NNNNNNNNN","value":"1552723693203,,..."}

After waking up the car, it goes to the 'waking' state then stays in an
'unknown' state for some time and finally goes to the 'online' state.
Even if the car doesn't move, it still returns some "data:update" messages.
Once the car starts moving, the frequency of these messages rises to
about 4 per second.
yeah, it appears the test works but dirkvm/teslams did not for me. It just seems to hang without spitting out any data except for the characteristics of the car then empty darkness.
 
Last edited:
yeah, it appears the test works but dirkvm/teslams did not for me. It just seems to hang without spitting out any data except for the characteristics of the car then empty darkness.

Note that logging of the messages to the console is disabled. Remove the // from line 290 in your copy of dirkvm/teslams
if you want the messages listed. Otherwise use "examples/streamws.js -z --file" to list them to the file "streaming.out".
 
Note that logging of the messages to the console is disabled. Remove the // from line 290 in your copy of dirkvm/teslams
if you want the messages listed. Otherwise use "examples/streamws.js -z --file" to list them to the file "streaming.out".
No I've tried having the data be placed in a flat file. I'll sometimes get one row of CSV and that's it. That is despite leaving it running throughout the day. On the console it does appear to be getting rest data but that's it. I'm not able to get any streaming data to a flat file or to Mongo.
 
No I've tried having the data be placed in a flat file. I'll sometimes get one row of CSV and that's it. That is despite leaving it running throughout the day. On the console it does appear to be getting rest data but that's it. I'm not able to get any streaming data to a flat file or to Mongo.
Note that logging of the messages to the console is disabled. Remove the // from line 290 in your copy of dirkvm/teslams
if you want the messages listed. Otherwise use "examples/streamws.js -z --file" to list them to the file "streaming.out".
It looks like once I uncommented that line it's working. Not sure why that would be. Thanks.
 
Is there a way to keep the stream going beyond the password timeout? Like a script to auto-reload token? I have this all set up in a Paw document (to get the updated tokens, etc) but it is still manual at this point.

As far as I can tell, you only need the token and vehicle_id to authenticate a new websocket connection. Streaming remains active until the connection is closed due to an error or because it's closed by the client app.
 
Ive seen a couple of instances (3 x M3 and 1x MS) where I can get the

Code:
"charger_power":0,
"charger_voltage":1,
"charging_state":"Stopped",
"conn_charge_cable":"IEC"

on a data request but if I then follow it up with charge_start I just get:

Code:
{"reason":"charging","result":false}
and the car doesnt start charging (it's not asleep)

Has anyone else seen this and had any workarounds?
 
Unfortunately no. My car hasn't gotten the sentry mode update yet. When I send a request with a blank body I get a 500 internal server error with this response:
Code:
{
    "error": "system",
    "error_description": "An unknown error has occurred."
}

I've been getting 500 internal server errors for the last few days when calling auto_conditioning_start. Using Postman it seems I get this for all POSTs (set charge limit, set temperatures.) My GETs work and the wake_up POST also works fine.

Has something changed with respect to required headers, body etc? These should be simple calls and were working for months.
 
I've been getting 500 internal server errors for the last few days when calling auto_conditioning_start. Using Postman it seems I get this for all POSTs (set charge limit, set temperatures.) My GETs work and the wake_up POST also works fine.

Has something changed with respect to required headers, body etc? These should be simple calls and were working for months.

I had been setting the Content-type header. Although they accepted it for quite a while (maybe even required it at one time?) it seems to break things now. With only the Authorization header it works as expected.
 
I'm connecting to the WebSocket
wss://streaming.vn.teslamotors.com/connect/{Tesla_vehicle_id}
With Header:
"Authorization" = "Basic " + Base64String of Emailadress : Streamingtoken

After the connection, I send:
{"msg_type": "data:subscribe", "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"]}

What I need is the elevation, but what I get is:

{"heading":266.722578,"latitude":xx.188278,"longitude":xx.901098,"msg_type":"vehicle_data:location","shift_state":"D","speed":25.041258}

What am I doing wrong?
 
Hello... New Tesla owner... Got the API working, can pull down vehicle data, so I've got all that working.

I know there are websites such as TeslaFi that get more detailed data than I'm seeing from the API. Is there an endpoint to get, for example, data from my last charge? watt-hours added, etc. Or does TeslaFi get this by querying the API at regular intervals and computing it?

Thanks!
 
Hello... New Tesla owner... Got the API working, can pull down vehicle data, so I've got all that working.

I know there are websites such as TeslaFi that get more detailed data than I'm seeing from the API. Is there an endpoint to get, for example, data from my last charge? watt-hours added, etc. Or does TeslaFi get this by querying the API at regular intervals and computing it?

Thanks!
No mate. What you see is what you get. If Tesla exposes more info people will add it into their projects quick smart.
 
The problem is that I removed all "nap" code from streaming.js because I synchronize my local state with TeslaFi. If TeslaFi says the car is sleeping or is trying to sleep, then I close the websocket and stop asking for new tokens.

To me, TeslaFi is perfect as an archive solution but I wanted realtime tracking via MQTT and MongoDB without handing out any account info ;)

@twall-e I replaced tesla_poll with this: Handle Tesla realtime streaming data

So far so good, longest drive I made was +100km and it didn't disconnect during that time. If I can get the streaming token from TeslaFi then I don't need any teslams api call.

i'm also using teslams streaming and adapted the nap code because it wasn't working for me (i guess tesla changes often how they send back data and hjespers didnt update the code anymore).
have been using it for over a year without any issues.

when I recognize the car is about to go to sleep, I exit tsla_poll() and continue calling initstream() with a larger interval.

Calling only initstream will not poke the car with getAux() which prevents the car from sleeping.

you can call teslams.all as many times as you want, the car doesnt wake up. This is useful to check the car status 'online' vs 'asleep' and thus decide if the streaming should start.



Now i just need to refactor the code to use websockets , since the old GET requests are not supported anymore...
 
Last edited:
  • Like
Reactions: DavidB
Note that logging of the messages to the console is disabled. Remove the // from line 290 in your copy of dirkvm/teslams
if you want the messages listed. Otherwise use "examples/streamws.js -z --file" to list them to the file "streaming.out".

Hey @dirkvm , I'm using your streamws.js to pull streaming data from my model 3 and constantly getting `data:error vehicle_disconnected` Any ideas why that's happening?