Skip to main content

Tesla

The Tesla fleet API is an officially supported API for accessing vehicle data and sending commands to the vehicle.

Register the app with Tesla developer

Setup an account at https://developer.tesla.com with the credentials from your Tesla vehicle. Submit an access request for using the API. In the request you can identify the scope, for example only read vehicle data or also send commands. You also need to specify the URI from which the API can be called. This is the domain of where the server is hosted. After the application has been approved you can obtain the CLIENT_ID and CLIENT_SECRET codes. For more information see this blog.

Installation

To run the service in Docker:

docker run --rm -p 80:80 -v /persist:/persist spacetimehub/tesla

To run the service in Kubernetes:

helm install tesla spacetime/tesla

Once the service is running register your credentials. For region select eu (Europe), na (North America), or cn (China). The service should point to the public URL accessible to Tesla, for example https://tesla.mydomain.com.

curl -X POST -k -H 'Content-Type: application/json' -i 'https://tesla.<YOURDOMAIN>/register' --data '{"clientId": <CLIENT_ID>,  "clientSecret": <CLIENT_SECRET>,  "region":<REGION>, "service":<URL>}'

The response is an authentication URL. Paste this URL in web browser and login to your tesla account to authorize the service to access your vehicle.

Datasource

Create a new datasource with the following information:

namevalue
typewebservice
servicehttps://tesla.YOURDOMAIN

Connector

In the connector specify the secret that contains the Tesla data source. Add an object mapping for each device. The object ID is the VIN (Vehicle Identification Number) of the car. There is a custom field charging which is not supplied by the input data but is set to 0 or 1 depending on the charging power. This field will be used to start or stop the charging process. The field charge_level_soc, which indicates the user selected charging level, is renamed to charge_level. Furthermore, the odometer field has a conversion factor from miles to kilometers.

The exporter contains an entry for setting the charge_level and for starting and stopping the charging process via the key charging, and climate to turn on the climate system. For security reasons some commands like opening the doors and starting the car are not enabled in the API but these can be added if necessary.

Form

To control the Tesla create a form with three pages and open the item tesla.model_s. The first page has some overall information but does not include any controls.

Tesla

Speed
<speed
[000 kmh]

Power
<power
[000 kW]

Odometer
<odometer
[000000]

Drive
<shift_state

Battery level
<battery_level
[0|10:red,11|20:orange,21|100:green]

Battery range
<battery_range
[0|50:red,50|100:orange,100|600:green 000]

The second and third pages include controls for the climate and charging. To modify any of the parameters open the item tesla.model_s and click on the edit button. After making changes click on save to execute the changes.

-->
Climate
[powerbutton]
|6

Defrost
<is_preconditioning
[powerbutton]
|6

Thermostat driver
[15|25]

Thermostat passenger
[15|25]

seat_heater_left
[0|3]

seat_heater_right
[0|3]

seat_heater_rear_left
[0|3]
|4

seat_heater_rear_center
[0|3]
|4

seat_heater_rear_right
[0|3]
|4

Outside temp
<exterior_temperature
[0|10:purple,11|17:blue,18|21:green,22|25:red]

Inside temp
<interior_temperature
[0|10:purple,11|17:blue,18|21:green,22|25:red]

-->

Battery level
<battery_level
[0|10:red,11|20:orange,21|100:green]

Battery range
<battery_range
[0|50:red,50|100:orange,100|600:green 000]

Charge limit
[50|100]
|12

Charge amps
[0|20]
|12

Power
<charger_power
[000 kWh]
|4

Voltage
<charger_voltage
[000 V]
|4

Current
<charger_current
[00.0 A]
|4

Charging state
<charging_state
|6

Charging
[powerbutton]
|6