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.
That was the plan :) Try to get the commands working! That would be awesome!

Yes, your code is a great start! Just what I was looking for to augment my existing web app LogMySC.com with some automation of grabbing the current mileage and temperature and energy usage instead of the user having to input it manually.

I'll also translate it to English while I'm at it. All the SQL works unchanged, it's just the mysqli_ calls and return values that needed to be changed.

The only problem I had was figuring out the VEHICLE_ID variable. When you list out the vehicle info, there are two IDS: "id" and "vechicle_id". Turns out for the subsequent API calls, you need to specify the "id" value in the URL, and NOT the "vehicle_id" value. Somewhat confusing when the API calls for "vehicle_id".
 
When you list out the vehicle info, there are two IDS: "id" and "vechicle_id". Turns out for the subsequent API calls, you need to specify the "id" value in the URL, and NOT the "vehicle_id" value. Somewhat confusing when the API calls for "vehicle_id".

Interesting find! I already thought that this has to be the error I made for issuing commands to the car. But I already was using the longer "id" instead of the shorter "vehicle_id". Actually the shorter "vehicle_id" also works, at least for all request type calls.

If you get the php or jscript code to issue commands working, let me know! I was not able to get that to return anything other than "404".
 
Two API questions.

1. It seems like about 50% of the time, the climate state returns null for outside and inside temps, while charge_state returns are pretty stable. Is this normal?

2. From the available API values returned in charge_state, how can I estimate how many kWh are left in the battery? I think it currently reports %SOC, but for my app, I want to measure the energy used between two readings. I could take the 85kWh rating of the battery and multiple by the %SOC, but is that accurate? What are other people using? It also looks like there's a constant multiplier of about 2.488 between %SOC and the rated range remaining.
 
Two API questions.

1. It seems like about 50% of the time, the climate state returns null for outside and inside temps, while charge_state returns are pretty stable. Is this normal?

2. From the available API values returned in charge_state, how can I estimate how many kWh are left in the battery? I think it currently reports %SOC, but for my app, I want to measure the energy used between two readings. I could take the 85kWh rating of the battery and multiple by the %SOC, but is that accurate? What are other people using? It also looks like there's a constant multiplier of about 2.488 between %SOC and the rated range remaining.

You want the delta-kWh between two charge state readings? Could you calculate the delta between `battery_level`s , then convert from battery_level % to kWh depending on the battery size? (5% drop in battery level is a lot more on larger battery packs)
 
You want the delta-kWh between two charge state readings? Could you calculate the delta between `battery_level`s , then convert from battery_level % to kWh depending on the battery size? (5% drop in battery level is a lot more on larger battery packs)

Yes, thats what I want to do and was asking if that's the best way to do it. Is it? How to accurately convert bsttery_level to kWh... Is it just size(85)*%soc?
 
Can anyone else access the Tesla API today? Nothing I do gets a response. Can't even request a new token.

It worked great yesterday, but today, it suddenly stopped working. The Tesla mobile app still works sometimes, but Remote S does not.

It stopped working for me early this morning. I've been getting "502 Bad Gateway".

The official Tesla app reports no errors, but seems to be displaying stale information. Edit: Actually, the app seems to be working. So maybe I missed some change to the API? Did the server change at some point?
 
It just took me four tries to get the climate turned on in my car through the Tesla app (internal temp was 109!).

Ok, that lends credence to the the theory that it's all on Tesla's end. Every once in a while, a request goes through, I guess. My script had been working on and off starting at 4:00 AM PDT, but it hasn't been working at all since 8:45 AM. It runs every 5 minutes.