Skip to content

scottrobertson/tesla-precondition

Repository files navigation

Tesla Precondition

An API endpoint to preheat your Tesla. You can create a shortcut on your mobile device (such as iOS Shortcuts, or Tasker) to call this endpoint to precondition/preheat your car.

You have 2 options to use this:

  • Use our hosted endpoint
  • Host it yourself (Cloudflare Workers)

See the options below.

Hosted

I have a Cloudflare Workers endpoint that anyone can use with their car. No data or access tokens are stored, and it cannot perform actions to your card on it's own. You pass in your access token to every request, and it expires after a few hours.

To use this, simply use the API endpoint: https://tesla.scottrobertson.workers.dev and follow the "Usage" steps below.

Self Hosted

This is designed to work with Cloudflare Workers, but I am sure it could work elsewhere with some modifications. Feel free to submit a PR.

Deploy to Cloudflare Workers

You can host this endpoint super easily on Cloudflare Workers.

  • Install wrangler CLI:
npm install -g @cloudflare/wrangler
  • Copy the example config:
cp wrangler.toml.example wrangler.toml
  • Head over to Cloudflare and click on Workers
  • Add your account_id from Cloudflare Workers into wrangler.toml
  • Publish to Cloudflare:
wrangler publish

Make note of the URL it gives you at the end of this. You will need it later.

By default, the script will wake up your Tesla and turn climate on. You can also specify the temperature (in Celsius) and turn on the seat heaters using headers (see below).

The page may take a while to load, as it waits for your Tesla to wake up.

Usage

To use this endpoint, you need to generate a Tesla Access Token. You can do this using one of the following apps:

  • iOS: Auth for Tesla
  • Android: Tesla Tokens

One you have one of the token, you can pass it to the API endpoint using query params below.

Headers

To control the API endpoint, you can use the following headers

name required? description
X-Tesla-vin yes The VIN of the car you want to control
X-Tesla-access_token yes Your Tesla Access Token
X-Tesla-temp no Desired temperature in Celsius
X-Tesla-seats no Comma-separated heat levels (0-3) for each seat. See below

Seat Numbers

0 Driver
1 Passenger
2 Rear left
3 NOT USED
4 Rear center
5 Rear right

An example to turn on all seats to max: X-Tesla-seats=3,3,3,0,3,3

Example iOS Shortcut

  • Install and Setup "Auth for Tesla" app.
  • Open Shortcuts
  • Add a Shortcut
  • Add an action of "Get Access Token" provided by the Auth for Tesla app.
  • Add an action of "Get Contents Of URL"
    • Add your URL from above
    • Add the required + optional headers from above.
    • For the X-Tesla-access_token header, you can tell it to use the "token" variable from the "Get Access Token" step above.
  • Optional: Add an action of "Get Dictionary From" and use the "Contents of URL" as the value
  • Optional: Add an action of "Show notification" and use the response from the dictonary step as the body

image

About

An API endpoint to preheat your Tesla.

Resources

Stars

Watchers

Forks

Packages

No packages published