TeslaMate

Dmitry Shnayder
4 min readDec 10, 2023

--

A while ago I started home automation project. It runs on a Linux box,

For the last few month I own a premium brand self-propelled smartphone with some people-moving capabilities — Tesla Model Y. From hardware point of view its a mixed bag, but software-wise it has a lot of capabilities. As any modern software product it has APIs. They are not documented, but well known for the community. The APIs can be used to track location, charge state, speed, power and many other parameters.

There is an open-source project TeslaMate, that uses Tesla APIs to collect driving and charding stats, and present them via nice Grafana dashboards.

I already has a dedicated Linux box, that runs my home wireless network controller and HomeBridge. The box still has a lot of available resorces, so lets connect it with my vehicle.

As usual with docker compose, everything starts with creating docker-compose.yml file. Content of the file is copied from the documentation page. Just replaced key and password with some hard-to-guess strings:

version: “3”

services:
teslamate:
image: teslamate/teslamate:latest
restart: always
environment:
— ENCRYPTION_KEY=secretkey #replace with a secure key to encrypt your Tesla API tokens
— DATABASE_USER=teslamate
— DATABASE_PASS=password #insert your secure database password!
— DATABASE_NAME=teslamate
— DATABASE_HOST=database
— MQTT_HOST=mosquitto
ports:
— 4000:4000
volumes:
— ./import:/opt/app/import
cap_drop:
— all

database:
image: postgres:15
restart: always
environment:
— POSTGRES_USER=teslamate
— POSTGRES_PASSWORD=password #insert your secure database password!
— POSTGRES_DB=teslamate
volumes:
— teslamate-db:/var/lib/postgresql/data

grafana:
image: teslamate/grafana:latest
restart: always
environment:
— DATABASE_USER=teslamate
— DATABASE_PASS=password #insert your secure database password!
— DATABASE_NAME=teslamate
— DATABASE_HOST=database
ports:
— 3000:3000
volumes:
— teslamate-grafana-data:/var/lib/grafana

mosquitto:
image: eclipse-mosquitto:2
restart: always
command: mosquitto -c /mosquitto-no-auth.conf
# ports:
# — 1883:1883
volumes:
— mosquitto-conf:/mosquitto/config
— mosquitto-data:/mosquitto/data

volumes:
teslamate-db:
teslamate-grafana-data:
mosquitto-conf:
mosquitto-data:

Then started the application:

docker compose up -d

The command automatically create disk volumes, pull the code from the internet and start the containers:

Creating volume “teslamate_teslamate-db” with default driver
Creating volume “teslamate_teslamate-grafana-data” with default driver
Creating volume “teslamate_mosquitto-conf” with default driver
Creating volume “teslamate_mosquitto-data” with default driver
Creating teslamate_database_1 … done
Creating teslamate_grafana_1 … done
Creating teslamate_mosquitto_1 … done
Creating teslamate_teslamate_1 … done

A GUI page is available on port 4000 on the Linux box, for example: http://192.168.8.6:4000

Next step is to give the application access to the car. TeslaMate requires access and refresh tokens.

There are many ways to generate the tokens. I choose a simple one — install an application on the phone:

The application lets me login to my Tesla account, including 2FA, and gives the required tokens:

Obviously its better to open TeslaMate page on the same phone as the authentication application, so tokens can be copy/pasted.

When tokens are entered to TeslaMate, it starts polling the car and collect the stats. ALthough not required, it can be confirmed by checking logs of the main TeslaMate container:

docker logs teslamate_teslamate_1

The car notifies when the data is polled, so this icon (a phone with locetion arrow) is displayed on the car’s screen once in a while:

I didn’t try myself, but most likely functionality of TeslaMate will be limited if location sharing is disabled. I keep it enabled.

A status screen is provided on port 4000:

But most interesting information is provided by Grafana deshboards on port 3000. TeslaMate bundles a lot of useful and less-than-useful dashboards.

One of most useful is Drive Stats:

Interesting to see how efficient the drives, depending on factors like temperature or speed. The most useless to me is Battery Health:

In almost 23,000 km the battery lost 4.4% of capacity, and most of the drop happened around 13,000 km. Why it happen nobody knows, better to close this dashboard and not at it ever again.

Why do I need TeslaMate? Hard to say, mostly for fun. In 21st century data is the new oil, never know what may be useful tomorrow.

--

--