Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/scottrobertson/tesla-precondition

An API endpoint to preheat your Tesla.
https://github.com/scottrobertson/tesla-precondition

Last synced: about 1 month ago
JSON representation

An API endpoint to preheat your Tesla.

Awesome Lists containing this project

README

        

# 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:

```bash
npm install -g @cloudflare/wrangler
```

- Copy the example config:

```bash
cp wrangler.toml.example wrangler.toml
```

- Head over to [Cloudflare](https://dash.cloudflare.com/) and click on Workers
- Add your `account_id` from Cloudflare Workers into `wrangler.toml`
- Publish to Cloudflare:

```bash
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](https://user-images.githubusercontent.com/68361/140664905-83b004b0-2a08-4359-9220-2bed8b751e86.png)