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.
init.php is not meant to be run on the command line, it's included into the other programs.
Thanks for the tip, I'm the guy who is helping Premiercolby with the task.
The problem is that only token.php and vehicle.php run OK from the code.
The rest return NULL.
For example, when I look at vehicle_state.php
#!/usr/bin/php -q
<?php
// Copyright (C) 2017, Ward Mundy & Associates LLC with MIT license
include("init.php");
init();
$response =queryTeslaAPI($TOKEN, "api/1/vehicles/".$ID."/data_request/vehicle_state");
var_export($response);
?>
Where the variable $ID comes from?
I want to fill $TOKEN and $ID manually and run it.
Thank you in advance,
Alex
 
If your technical friend knows Python then have him check out some of the existing code that works like this teslajson/teslajson.py at master · gglockner/teslajson · GitHub or some of the other Tesla related stuff on Github
Hi
sorry to say this, but I immediately getting key error when trying to run python
Traceback (most recent call last): File "", line 7, in &lt;module&gt; TESLA_EMAIL = os.environ['] File "/usr/local/lib/python2.7/", line 40, i>yakov@yakov-Satellite-C675D:/tesla-python/teslajson-master$ sudo python tesla.py
Traceback (most recent call last):
File "tesla.py", line 7, in <module>
TESLA_EMAIL = os.environ['[email protected]']
File "/usr/local/lib/python2.7/UserDict.py", line 40, in __getitem__
raise KeyError(key)
KeyError: '[email protected]'
 
In the new phone app version, the app correctly shows me my car model (70D) how does it figure this out? From my looking into VIN decoding and option codes, I can't find a code that represents cars that have a higher cap battery but it is software limited. Would like to know the logic behind how the phone app figures out which car the user has.
 
Quick question on app etiquette. So I have built my own Tesla app that meets my needs, I may release it to the world but that wasn't my point. I just wanted something specific for me and wanted to learn more about the API set.

The question is refreshing data. Currently I have it set to refresh every 30seconds and not to refresh in the background. Downside to not refreshing in background is I can't use notifications effectively.

But my reason for doing the 30second and no refresh in background was to allow the car to sleep when it needs to and not to put additional requests into the tesla server and car beyond reasonable.

So how are other app owners handling refresh frequency and letting the car sleep, etc. ????
 
In the new phone app version, the app correctly shows me my car model (70D) how does it figure this out? From my looking into VIN decoding and option codes, I can't find a code that represents cars that have a higher cap battery but it is software limited. Would like to know the logic behind how the phone app figures out which car the user has.

Is your car a software limited 60D or a real 70D? What are the option codes on your car?
 
You can check to see if the car is awake first and only wake it up during certain conditions (such as when your app starts up or is in focus).
Yep I use that command to wake the car when I want data. I guess battery data and car security (ie.locked or not) would be useful to get more often but I don't want to keep waking the car. just thinking what should I get in the background and how often.

I am suspecting the new Tesla app is waking the car a lot with the new Today extension. Maybe having the car awake always is not an issue anymore ???
 
am I reading this right, does
api/1/vehicles/{vehicle_id}/data

get all the data that in the past I had to use the 3-4 /data_request/ commands for ??
ie. I don't need
api.teslamotors.com/api/1/vehicles/vehicle_id/data_request/vehicle_state
api.teslamotors.com/api/1/vehicles/vehicle_id/data_request/drive_state
api.teslamotors.com/api/1/vehicles/vehicle_id/data_request/charge_state
api.teslamotors.com/api/1/vehicles/vehicle_id/data_request/climate_state

I can just use /data instead ??
 
@NicB72 , actually it does far more. It also includes the vehicle summary and the vehicle config calls as well.

Here is a sample return of the '/data' call:

Code:
{
    "response": {
        "id": 1107332679114299,
        "user_id": 159346,
        "vehicle_id": 1076679163,
        "vin": "5YJSA1E22GF152993",
        "display_name": "Cordette",
        "option_codes": "MDLS,RENA,AF02,AU00,BC0B,BP00,BR03,BS00,BX60,CDM0,CH05,PBSB,CW00,DA01,DCF0,DRLH,DSH7,DV4W,FG02,HP00,IDBA,IX01,LP01,ME02,MI01,PA00,PF00,PI01,PK00,PS01,PX00,QPBT,RFP2,SC01,SP00,SR01,ST01,SU00,TM00,TP03,TR00,UTAB,WTAS,WTX1,X001,X003,X007,X011,X014,X021,X025,X027,X028,X031,X037,X040,X044,YFFC,BTX5,COUS",
        "color": null,
        "tokens": [
            "0a61fbe132f55106",
            "583f3f3f905c7480"
        ],
        "state": "online",
        "in_service": false,
        "id_s": "1107332679114299",
        "remote_start_enabled": true,
        "calendar_enabled": true,
        "notifications_enabled": true,
        "backseat_token": null,
        "backseat_token_updated_at": null,
        "gui_settings": {
            "gui_distance_units": "mi/hr",
            "gui_temperature_units": "F",
            "gui_charge_rate_units": "mi/hr",
            "gui_24_hour_time": false,
            "gui_range_display": "Rated",
            "timestamp": 1486939660003
        },
        "vehicle_config": {
            "car_special_type": "base",
            "car_type": "s2",
            "eu_vehicle": false,
            "exterior_color": "Black",
            "has_ludicrous_mode": false,
            "motorized_charge_port": true,
            "perf_config": "P3",
            "rear_seat_heaters": 0,
            "rear_seat_type": 0,
            "rhd": false,
            "roof_color": "None",
            "seat_type": 0,
            "spoiler_type": "None",
            "sun_roof_installed": 2,
            "third_row_seats": "None",
            "timestamp": 1486939660948,
            "trim_badging": "60d",
            "wheel_type": "AeroTurbine19"
        },
        "climate_state": {
            "inside_temp": null,
            "outside_temp": null,
            "driver_temp_setting": 18.9,
            "passenger_temp_setting": 18.9,
            "left_temp_direction": null,
            "right_temp_direction": null,
            "is_auto_conditioning_on": null,
            "is_front_defroster_on": null,
            "is_rear_defroster_on": false,
            "fan_status": 0,
            "is_climate_on": false,
            "min_avail_temp": 15,
            "max_avail_temp": 28,
            "seat_heater_left": 0,
            "seat_heater_right": 0,
            "seat_heater_rear_left": 0,
            "seat_heater_rear_right": 0,
            "seat_heater_rear_center": 0,
            "seat_heater_rear_right_back": 0,
            "seat_heater_rear_left_back": 0,
            "smart_preconditioning": false,
            "timestamp": 1486939660947
        },
        "vehicle_state": {
            "api_version": 3,
            "autopark_state": "unavailable",
            "autopark_state_v2": "unavailable",
            "calendar_supported": true,
            "car_type": "s2",
            "car_version": "17.4.14",
            "center_display_state": 0,
            "dark_rims": false,
            "df": 0,
            "dr": 0,
            "exterior_color": "Black",
            "ft": 0,
            "has_spoiler": false,
            "locked": true,
            "notifications_supported": true,
            "odometer": 4795.992359,
            "parsed_calendar_supported": true,
            "perf_config": "P3",
            "pf": 0,
            "pr": 0,
            "rear_seat_heaters": 0,
            "rear_seat_type": 0,
            "remote_start": false,
            "remote_start_supported": true,
            "rhd": false,
            "roof_color": "None",
            "rt": 0,
            "seat_type": 0,
            "spoiler_type": "None",
            "sun_roof_installed": 2,
            "sun_roof_percent_open": 0,
            "sun_roof_state": "unknown",
            "third_row_seats": "None",
            "timestamp": 1486939660948,
            "valet_mode": false,
            "vehicle_name": "Cordette",
            "wheel_type": "AeroTurbine19"
        },
        "drive_state": {
            "shift_state": null,
            "speed": null,
            "power": 0,
            "latitude": 57.653424,
            "longitude": -127.276158,
            "heading": 268,
            "gps_as_of": 1486939659,
            "timestamp": 1486939660949
        },
        "charge_state": {
            "charging_state": "Complete",
            "charge_limit_soc": 100,
            "charge_limit_soc_std": 90,
            "charge_limit_soc_min": 50,
            "charge_limit_soc_max": 100,
            "charge_to_max_range": true,
            "battery_heater_on": null,
            "not_enough_power_to_heat": false,
            "max_range_charge_counter": 1,
            "fast_charger_present": false,
            "fast_charger_type": "<invalid>",
            "battery_range": 215.28,
            "est_battery_range": 156.58,
            "ideal_battery_range": 268.86,
            "battery_level": 100,
            "usable_battery_level": 99,
            "battery_current": 0,
            "charge_energy_added": 12.24,
            "charge_miles_added_rated": 43,
            "charge_miles_added_ideal": 53.5,
            "charger_voltage": 0,
            "charger_pilot_current": null,
            "charger_actual_current": 0,
            "charger_power": 0,
            "time_to_full_charge": 0,
            "trip_charging": null,
            "charge_rate": 0,
            "charge_port_door_open": true,
            "scheduled_charging_start_time": 1486980000,
            "scheduled_charging_pending": false,
            "user_charge_enable_request": true,
            "charge_enable_request": true,
            "charger_phases": null,
            "charge_port_latch": "Engaged",
            "charge_current_request": 28,
            "charge_current_request_max": 40,
            "charge_port_led_color": "Green",
            "managed_charging_active": false,
            "managed_charging_user_canceled": false,
            "managed_charging_start_time": null,
            "motorized_charge_port": true,
            "eu_vehicle": false,
            "timestamp": 1486939660952
        }
    }
}

if you only need specific data every time you need an update, probably best to stick with specific calls.
 
  • Like
Reactions: NicB72
For the last couple of days, I am seeing that my car is not going into the sleep mode. I am using python library and my code delays the poll interval up to 30 minutes (exponential back off) when my car is not moving. It always checks the "status" from vehicles object and make sure it is "online" before it requests data from all four states. Yesterday, I even turned off my service for 2 hours but the car was still not going into sleep. When I first ran my code on Sunday, I noticed it was going into sleep fine.

Does anyone have the same lately? Thanks.