TeslaMate User Guide

✍🏼 Written on Sep 6, 2023    💡 Updated on Sep 8, 2023
🖥  Note:Some issues encountered during the installation and use of TeslaMate.

💡This guide requires a minimal understanding of programming, including familiarity with terminals and command lines.

💡This tutorial uses Docker to install TeslaMate. If you're working in a soft router environment, additional steps like port forwarding may be needed for browser access. Since my Mac computer stays on indefinitely, I installed it on Docker for Mac.

💡One minor drawback is that TeslaMate cannot retrieve historical vehicle data. As a result, you can only view driving data recorded after installing TeslaMate, and the TeslaMate service must remain running to continue logging driving information.

Introduction

“TeslaMate,” loosely translated as “Tesla Companion,” is an open-source software that retrieves data reported by your vehicle to Tesla’s servers and displays it using Grafana, a web-based data visualization dashboard tool.

TeslaMate repository:

GitHub - adriankumpf/teslamate: A self-hosted data logger for your Tesla 🚘 A self-hosted data logger for your Tesla 🚘. Contribute to adriankumpf/teslamate development by creating an account on GitHub. https://github.com/adriankumpf/teslamate#teslamate

TeslaMate documentation:

Docker install | TeslaMate This document provides the necessary steps for installation of TeslaMate on any system that runs Docker. For a walkthrough that provides the necessary steps for manual installation, see Manual Install. https://docs.teslamate.org/docs/installation/docker


Tesla engineers collect this data for large-scale vehicle analytics, software optimization, battery charging improvements, and more. As individual owners, accessing this information allows us to better understand our vehicles’ detailed metrics, such as trip history, daily mileage, energy consumption, and charging efficiency.

The reason for this blog post is that TeslaMate’s documentation only covers installation (which is straightforward) but doesn’t explain how to configure the dashboard after installation to display the desired data. Meanwhile, many SEO-driven content farms simply copy-paste official documentation, making it difficult to find useful information. Currently, I haven’t found any comprehensive guide covering installation to final setup—so this article will walk through the entire process.

Here’s a preview of the final result (users can customize the dashboard):

TeslaMate 成果图

1. Installing Docker

As mentioned earlier, I’m using Docker for installation. TeslaMate’s documentation requires Docker and Docker Compose (don’t worry about what they are—just install them). By installing Docker Desktop, both are included. Download Docker Desktop here:

Docker Desktop: The #1 Containerization Tool for Developers | Docker Docker Desktop is collaborative containerization software for developers. Get started and download Docker Desktop today on Mac, Windows, or Linux. https://www.docker.com/products/docker-desktop/

After installation, launch Docker Desktop. Then, choose a directory (all TeslaMate files will reside here—do not delete it) and place the official docker-compose.yml file inside. In my case, I placed it under ~/Developer/Docker/TeslaMate. The docker-compose.yml content is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
version: '3'

services:
teslamate:
image: teslamate/teslamate:latest
restart: always
environment:
- ENCRYPTION_KEY= #设置 TeslaMate API 加密密码,注意等号后面不要有空格
- DATABASE_USER=teslamate
- DATABASE_PASS= #设置安全数据库密码,注意等号后面不要有空格
- 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= #设置数据库密码,注意等号后面不要有空格
- POSTGRES_DB=teslamate
volumes:
- teslamate-db:/var/lib/postgresql/data

grafana:
image: teslamate/grafana:latest
restart: always
environment:
- DATABASE_USER=teslamate
- DATABASE_PASS= #设置 grafana 的数据库密码,注意等号后面不要有空格
- 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:
```

Note that some services require matching passwords, so I recommend setting all passwords above to the same value for simplicity. Also, pay special attention to ensure `=` has no trailing spaces. Next, open a terminal and execute the following (copy each line and press Enter):

```bash
# 假设你放上述文件的目录为 ~/Developer/Docker/TeslaMate
cd ~/Developer/Docker/TeslaMate
docker compose up -d
```

Once completed, Docker Desktop should look like this:

{% render_caption caption="安装完成后截图" img="https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/cd39c66f-60b7-4d3d-81bd-f5ac50260d28.webp" %}
![安装完成后截图](https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/cd39c66f-60b7-4d3d-81bd-f5ac50260d28.webp)
{% endrender_caption %}

## 2. Logging in and Authorizing Your Tesla Account

After ensuring no errors in the previous step and confirming all services are in the "Running" state (you can check logs by clicking each service name in the screenshot above for any errors), open `localhost:4000` in your browser. You’ll be prompted to enter an API Token and Refresh Token. The official documentation explains how to obtain these here:

{% render_bookmark url="https://docs.teslamate.org/docs/faq/#how-to-generate-your-own-tokens" title="Frequently Asked Questions | TeslaMate" img="" yid="" bid="" %}
How to generate your own tokens
{% endrender_bookmark %}

Here, I’ll use the third method: "Tesla Auth (macOS, Linux, Windows)." Click the link below to find the version for your system and download the corresponding file (an executable):

{% render_bookmark url="https://github.com/adriankumpf/tesla_auth#download" title="GitHub - adriankumpf/tesla_auth: Securely generate API tokens for third-party access to your Tesla." img="https://opengraph.githubassets.com/14ed85d2b3ddb9d5945d743bce95d70195e338a20492ab583d95d8c0d4f14ebd/adriankumpf/tesla_auth" yid="" bid="" %}
Securely generate API tokens for third-party access to your Tesla. - GitHub - adriankumpf/tesla_auth: Securely generate API tokens for third-party access to your Tesla.
{% endrender_bookmark %}

If you directly double-click to open (or open via terminal), macOS may warn you that the executable file could be dangerous. Go to `系统设置-隐私与安全性` and click "Open Anyway". After opening, a window will pop up prompting you to log in to your Tesla account. Once logged in, the page will display your Tesla API Token and Refresh Token (I won't include screenshots here). Copy these to the corresponding fields on the `localhost:4000` page to successfully log in. The interface after successful login looks like this:

{% render_caption caption="TeslaMate 授权成功界面" img="https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/8d41bc35-475f-499d-b2d3-c4812e9a72e9.webp" %}
![TeslaMate 授权成功界面](https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/8d41bc35-475f-499d-b2d3-c4812e9a72e9.webp)
{% endrender_caption %}

At this point, authentication is complete. Next, configure Grafana.

## 3. Basic Concepts of Grafana

Grafana is a powerful web-based data visualization dashboard tool, which is relatively complex to use. I haven't explored how to localize it into Chinese. Fortunately, Tesla's data fields are simple enough that localization isn't necessary. Here’s a brief introduction to the relevant concepts for easier customization later.

### Dashboard and Panel

A Dashboard is an interface that displays various data, showing different Panels. A Panel is a module that queries the database for data and visualizes it. Each red box in the image below represents a Panel:

{% render_caption caption="N Panel 组成了一个 Dashboard" img="https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/6b5bfe32-8214-4994-a6ce-9b3a1874e11e.webp" %}
![N Panel 组成了一个 Dashboard](https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/6b5bfe32-8214-4994-a6ce-9b3a1874e11e.webp)
{% endrender_caption %}

Panels can be copied between different Dashboards as shown below:

{% render_caption caption="Panel 复制" img="https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/2522b63e-34e9-44e2-a0ba-2d74901ea53b.webp" %}
![Panel 复制](https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/2522b63e-34e9-44e2-a0ba-2d74901ea53b.webp)
{% endrender_caption %}

After clicking "Copy," you can paste it into another Dashboard. Click the "Add Panel" button in the upper right corner of the Dashboard (or when creating a new Dashboard for the first time). If you didn’t click "Copy" in the previous step, the fourth option, "Paste from Clipboard," won’t appear. The new Panel creation interface will look like this:

{% render_caption caption="粘贴刚刚复制的 Panel" img="https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/37d13b9a-d6b0-4e19-9bd9-b41712ea5e05.webp" %}
![粘贴刚刚复制的 Panel](https://static.xheldon.cn/img/in-post/2023/the-use-of-teslamate/37d13b9a-d6b0-4e19-9bd9-b41712ea5e05.webp)
{% endrender_caption %}

### Variable and JSON Model

**Variable**

Each Dashboard can set Variables for Panels to use. How do Panels use Variables? Panel data is retrieved via SQL queries, and part of the SQL syntax uses Grafana's SQL template syntax. Below is the SQL query for altitude data:

```sql
SELECT
$__time(date),
ROUND(convert_m(elevation, '$alternative_length_unit')) AS elevation_[[alternative_length_unit]]
FROM
positions
WHERE
car_id = $car_id AND
$__timeFilter(date)
ORDER BY
date ASC

The terms enclosed in $ symbols are predefined Variables. Some are built-in, like $__timeFilter, while others are custom, like $alternative_length_unit. Custom Variables are configured in the Dashboard. Dashboard Variables are configured in the Dashboard Settings, accessible via the upper-right corner:

Variable 配置

JSON Model

Sometimes, after copying a Panel from one Dashboard and pasting it into a new Dashboard, the Panel may not display data correctly. This happens because the Variables used by the source Panel weren’t copied from the source Dashboard to the new one, causing SQL syntax errors and preventing data retrieval. If a Dashboard has many Variables, copying them one by one can be tedious. How to solve this? The JSON Model can help.

The JSON Model is essentially the Dashboard configuration in JSON format. You can copy the corresponding fields from one Dashboard’s JSON Model to another. Variables correspond to the templating field in the JSON Model. Copy the relevant items from the list field in the source Dashboard’s JSON Model to the list field under the templating field in the target Dashboard’s JSON Model. (Remember to click “Save Changes” and then “Save dashboard”):

直接复制对应 JSON

Grafana has many other advanced features, but for Tesla data visualization, understanding these basics is sufficient.

4. Configuring Grafana

After accessing localhost:3000, you’ll need to log in. The default username and password for the first login are both admin. After the first successful login, you’ll be prompted to set a new password. Once set, the interface will look like this:

Grafana 默认 Dashboard

Here, TeslaMate has already configured various dashboards for us. Click on this area on the left to open the folder and view the dashboards listed in the directory:

查看 TeslaMate 预设的 Dashboard

各种 Dashboard

Feel free to open any one, such as Drive Stats, to see the various panels in the corresponding dashboard:

Drive Stats Dashboard

However, we likely want to aggregate panels from multiple preset dashboards into a new dashboard tailored to our needs. This requires using the operations mentioned in the previous step “Grafana Concepts”—copying panels, copying variables (copying JSON models). You can configure a dashboard that suits your requirements.

5. Other Notes

Here are some additional usage tips for Grafana, briefly outlined.

Configuring Panel Titles:

Click “Edit” at the top of the panel, then modify the title on the right side:

修改 Panel 标题

Map Not Displaying: No further explanation—requires a VPN environment.

Setting Your Dashboard as Default:

As shown here:

配置默认的 Dashboard

How to Synchronize Data Display Across Panels When Hovering Over One Panel in a Dashboard?

A common use case is hovering over a line chart panel to view driving speed while simultaneously seeing the corresponding location on a map panel. This can be resolved by adjusting the dashboard settings. Set it to the second option (default is the first):

Security? TeslaMate is open-source software from abroad, and its security is reliable.

How to Migrate Data When Switching Machines? Refer to TeslaMate’s documentation for detailed instructions.

How to Access Grafana Over the Public Internet? This requires DDNS—figure it out on your own.

Ultimate Reminder: Remember to click “Save” in the top-right corner after modifying a panel.

How to Set Up Timed Dashboard Refreshes: The refresh interval can be set in the top-right corner of the dashboard. This is typically used for displaying real-time data changes on a large screen throughout the day.

- EOF -
Originally published at: TeslaMate User Guide - Xheldon Blog