In this tutorial, we will show you how to run TeslaMate on your Raspberry Pi.
TeslaMate is a data logger that allows you to track numerous details about a Tesla car. It achieves this by polling the Tesla API and logging the data it returns to a PostgreSQL database running on your Raspberry Pi.
This software is excellent for those who own a Tesla and are interested in keeping track of data returned by it. You can even integrate this data with software like Home Automation to automate various features of your car.
The Raspberry Pi makes a perfect companion with TeslaMate as it is a low-powered device that isn’t expensive to run 24/7.
To make the process of running Teslamate on your Raspberry Pi significantly simpler, we will be running it through a Docker container. This saves us from having to install and configure several different pieces of software.
Below is a list of the equipment we used when setting up our Raspberry Pi to run TeslaMate.
Preparing the Raspberry Pi to Run TeslaMate
Before we can install and run TeslaMate on our Raspberry Pi, we need to go through some initial set-up steps.
Over the next few steps, we will update the Raspberry Pi and ensure that you have Docker compose installed.
1. Before continuing any further, we should update the available list of packages and upgrade any out-of-date packages.
We can perform both tasks by using the following command within the terminal.
sudo apt update sudo apt upgrade
2. Next, we must ensure that Docker Compose installed on your Raspberry Pi by running the command below.
Docker will make running TeslaMate on your Raspberry Pi significantly more straightforward.
sudo apt install docker-compose
3. For our current user to interact with Docker, we must add it to the “
docker” group using the command below.
Add this user to the group by running the following command. This line uses the usermod command to modify your user’s properties.
sudo usermod -aG docker $USER
4. For changes to your current user to take effect, you must log out of your system and then log back in.
You can log out from the terminal by using the command below.
After logging out, you can immediately log back into your account.
Installing TeslaMate to your Raspberry Pi
Now that we are prepared, it is safe to install TeslaMate to your Raspberry Pi.
For these steps, we will be creating a “docker-compose” script that will set up all the services we require to run TeslaMate.
5. Before installing TeslaMate to our Raspberry Pi, we need to create a directory within our home directory called “
You can use the mkdir command to create this folder by running the command below.
6. Now that we have created our new directory, we need to use the cd command to move change to it.
7. We can begin writing our “
docker-compose” file by using the following command within the terminal.
This compose file will set up four different services on our Raspberry Pi.
- The first app it sets up is TeslaMate itself.
- Next is the database service that TeslaMate needs to store its data. In this case, it will be PostgreSQL.
- Additionally, Grafana will be set up within a Docker container as well. Grafana is how you will view all the data that TeslaMate gathers on your Raspberry Pi.
- The final Docker container that will be installed to the system is the Mosquitto broker. This broker is what allows other services like HomeAssistant to interact with TeslaMate.
8. Within this file, you will want to enter the following lines into the file.
While entering these configuration files into the file, you must replace the following two elements.
[REPLACEWITHENCRYPTKEY]– This key is essential as it is used to encrypt the Tesla API keys while they sit on your Raspberry Pi.
Ensure you set a long random key for this key.
[REPLACEWITHDBPASSWORD]– Next, you must specify a password for the PostgreSQL database. There are three occurrences of this within the file.
This database is where TeslaMate will store all of its data while it runs on your Raspberry Pi.
version: "3" services: teslamate: image: teslamate/teslamate:latest restart: always environment: - ENCRYPTION_KEY=[REPLACEWITHENCRYPTKEY] - DATABASE_USER=teslamate - DATABASE_PASS=[REPLACEWITHDBPASSWORD] - DATABASE_NAME=teslamate - DATABASE_HOST=database - MQTT_HOST=mosquitto ports: - 4000:4000 volumes: - ./import:/opt/app/import cap_drop: - all database: image: postgres:14 restart: always environment: - POSTGRES_USER=teslamate - POSTGRES_PASSWORD=[REPLACEWITHDBPASSWORD] - POSTGRES_DB=teslamate volumes: - teslamate-db:/var/lib/postgresql/data grafana: image: teslamate/grafana:latest restart: always environment: - DATABASE_USER=teslamate - DATABASE_PASS=[REPLACEWITHDBPASSWORD] - 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:
9. With this done, you can save and quit by pressing CTRL + X, followed by Y, and then the ENTER key.
10. At this point, we can finally start TeslaMate on your Raspberry Pi by using the command within the terminal.
During the first start-up, Docker will download the latest version of the TeslaMate container alongside other software such as Grafana, Postgres and Mosquitto.
docker-compose up -d
Setting the API for TeslaMate
11. To be able to use TeslaMate, you will need to retrieve the API keys for your Tesla account.
This is probably the most complicated part of the whole process, as Tesla does not make these easy to get.
Below you can find the three options recommended by the TeslaMate team. You will need the “
Access Token” and the “
Refresh Token” these tools provide.
- Windows/Linux/macOS: Tesla Auth by Adriankumpf
- Android: Tesla Tokens by Denouche Company
- iOS/macOS: Auth app for Tesla by Kim Hansen
12. You will now want to go to the following address in your favourite web browser.
Ensure that you replace “
YOURIPADDRESS” with the IP of your Raspberry Pi.
13. Before TeslaMate can start working on your Raspberry Pi, you must specify some details.
First, specify the “
Access Token” (1.). The access token gives TeslaMate access to the API.
Next, you need the “
Refresh Token” (2.). This token allows TeslaMate to update the access token when needed automatically.
Once you have both of these tokens, you must click the “
Sign in” button (3.) to proceed. TeslaMate requires these tokens to be able to interact with the Tesla API.
14. You now have access to TeslaMate running on your Raspberry Pi. It will immediately grab information through the Tesla API and log it to its database.
As TeslaMate can’t grab historical data, it will take a little while before its database becomes filled with meaningful data.
Viewing the TeslaMate Grafana Dashboard on the Raspberry Pi
15. Now that you have TeslaMate running on your Raspberry Pi, you can view the data it is logging by accessing its Grafana dashboards.
As you may have noticed earlier, we included Grafana within our Docker compose file. You can access this web interface by going to the following address.
Make that you replace “
YOURIPADDRESS” with the IP of your Raspberry Pi.
16. When you first open Grafana you will be required to log in to its web interface.
The default username and password is “
Once you have entered the default username and password, click the “
Log in” button (2.).
17. Next, you will be asked to set a new, more secure password for Grafana. Type in a new password in the provided boxes (1.).
When you are happy with the new password you are setting, click the “
Submit” button (2.).
18. As we now have Grafana opened on your device, we can now browse a list of the dashboards.
First, click the table icon in the left sidebar, as shown in the screenshot below (1.).
This will bring up a submenu. You must click the “
Browse” button to continue (2.).
19. You can now see a list of the TeslaMate dashboards available to you on your Raspberry Pi.
To open this list, click the “
TeslaMate” heading (1.).
Next, find the dashboard for which you want to view the data and click it to proceed (2.). For our example, we will open the “
Charging Stats” dashboard.
20. Below, you can find all the charging stats that TeslaMate has gathered while running on your Raspberry Pi.
It will continue to process this data as long as your Raspberry Pi is running and has a connection to your car.
At this point, you should hopefully now have TeslaMate up and running on your Raspberry Pi.
TeslaMate is a data logger that gathers data on your Tesla by polling its API. This data is saved into a PostgreSQL database and presented through a Grafana database.
Please comment below if you have had any issues getting TeslaMate running on your device.
If you found this tutorial helpful, be sure to check out our many other Raspberry Pi projects.