Tesla automation

Last updated 24-Dec-2021

The options for automating the control of your Tesla including the timing of Tesla charging are relatively limited. There are a number of reasons why owners may want to control their charging beyond simply setting the charge limit and wanting to wake the following morning to find the car at the required charge level. These include, but aren't limited to:

The Tesla API provides the ability to stop and start charging manually however owners typicaly want to automate these features rather than wake up at 2am to manually start a charge and stop the cahrge at 6am.

How to use the Tesla API for automation

The Tesla API has been reasonably well documented for a number of years, however the use is not totally straight forward as Tesla have introduced various restrictions making Token generation difficult and the commands themselves can not simply be sent to the car as the car needs to be "awake" first.

Our way around these problems is to provide a simple tool to generate a token and vehicle IDs, and a simple API which will wake the car before executing a command. You hold your details and only provide them to us for the purposes of the request. We only keep a record that the request was made to spot abuse or hacking attempts, and out token generation approach uses Tesla's servers to generate a temporary code we can work from that avoids us needing your email address or password.

Token generation

We have created a utility to generate a Tesla token. This utility uses a Tesla feature so we do not need your Tesla user name and password, and will return the Tesla token and the vehicle ID for each car on your account. We also supply the refresh token for those that want to use the tokens on a 3rd party application but wish to use an independant website to generate the token.

The only way to expire a refresh token is to change your password on MyTesla.

For the purposes of the examples below we will use [token] to represent the use of the API token, and [refresh] the use of the refresh token.

Examples of the commands

We have created a fairly simple API which in practice just looks like a web page URL. The format for the API is as follows, which will work on the first car on your Tesla account (for most people this will be their only car on the account).


An example of a command to lock the first car on your account is:


The response to a successful command looks similar to this

{"car":"MyTeslaCarName", "status":"success", "cause":"Command door_lock succeeded", "token":"qts-abcdefghijklmnopqrstuvwxyz"}

If a paramter is required then this is added by using an extra parameter as follows which sets the charge limit to 70%:


If you have more than one car on your account you can also specify the car Id (we list these when we generate tokens)


API Tokens expire, Tesla use them because of this as anyone having an API token only have a limited time before it will stop working. They can also be invalidated without changing the password. While this is a good thing for security, it can be frustrating as you need to update these links on a regular basis if you use it. As an alternative you can use the refresh token which will not expire:


The refresh token is very long! An example of a request is:

https://tesla-info.com/api/control_v2.php?refresh=eyJhbGciOiJSUzI1N.. ..ZiMnNuRi04YmdVUS&request=lock

You can also use the approach to retrieve information such as the charge state or climate


An example of the response is:

{"car":"MyTeslaCarName", "response":{"battery_heater":false, "battery_heater_no_power":null, "climate_keeper_mode":"off", "defrost_mode":0, "driver_temp_setting":20.0, "fan_status":0, "inside_temp":8.7, "is_auto_conditioning_on":false, "is_climate_on":false, "is_front_defroster_on":false, "is_preconditioning":false, "is_rear_defroster_on":false, "left_temp_direction":906, "max_avail_temp":28.0, "min_avail_temp":15.0, "outside_temp":5.5, "passenger_temp_setting":20.0, "remote_heater_control_enabled":false, "right_temp_direction":897, "seat_heater_left":0, "seat_heater_rear_center":0, "seat_heater_rear_left":0, "seat_heater_rear_right":0, "seat_heater_right":0, "side_mirror_heaters":false, "timestamp":1637933181574, "wiper_blade_heater":false}, "token":"qts-abcdefghijklmnopqrstuvwxyz"}

These types of commands can be relatively easily integrated into IFTTT type programming for those that like to do more sophisticated automation. The response from the API is in JSON format which is fairly easy to understand with basic technical skills, but can also be used in a programming context to capture the success or otherwise of the request for those wanting to embed them in a more sophisticated set up. IFTTT is likely to be required as part of controlling charging if it is linked to solar power availability.

The links can also be saved as web pages in a web browser and you can simply select the web page and the command will execute. Alternatively the links can be put into a fairly simple Apple Shortcut which can take advantage of those capabilities and even Siri or the equivalent on Android phones.

Note, not all commands are supported by all cars.

Range of requests

The request choices are:

The requests which require a parameter are: The requests which get information are:

Because the request may need to wake the car first, they can take up to 30 seconds to run.

Example to start and stop charge

One of the complaints of Tesla is the ability to control charging. You can controkl the start, or the stop, but not both. For owners on off peak charging windows they may only want to charge for a defined time window over night and a start and stop is required.

The start request is:


or when using the refresh token that does not expire:


And the stop charge requests are:


or when using the refresh token that does not expire:

https://tesla-info.com/api/control_v2.php?refresh=abcdefghijklmn.... ....opqrstuvwxyz&request=stopcharge

When scheduling the start or stop we advise scheduling each twice, a few minutes apart eg 01:00 and 01:02 for the start charge request. Tesla can be sluggish to respond and we have seen server errors which cause requests to fail even when using the Tesla app, so requesting the start or stop more than once helps reduce the risk of it failing altogether.

Tesla tokens do expire and we have chosen not to be able to automatically renew it for you for your own security. We recommend updating the token every month.

If at any time you feel your phone or security has been compromised, visit tesla.com and change your Tesla password.

By using our site, you acknowledge that you have read and understand our Privacy and Cookie Policy. Your use of the tesla-info website is subject to these policies and terms. All data is provided on a reasonable endeavours basis but errors and omissions may exist. No data should be relied upon as being accurate and additional checks should be made if the information is material to any purchase or use of the car. We provide product listings on Amazon for which we will receive a small commission if you chose to buy.