If like me you don’t have a spare monitor and you had forgotten to order the micro HDMI to HDMI lead (or just don’t want to use your TV) you can still install TeslaMate remotely using SSH into your Raspberry Pi.
What you will need
Raspberry Pi 3 B+, Pi 4 (2gb) or Pi 4 (4gb – currently on offer on Amazon – £52) – I learnt the hard way that the Pi 0 W isn’t compatible 🙂
Raspberry Pi power cable (for v3 for v4)
Micro SD card (32gb, 64gb, 128gb)
Case (for v3 for v4) – I’ve recommended a heatsink case, it’s what I’m using for my Homebridge Pi too, rather than a noisy fan case – My Pi 4 seems to sit between 40-41c
Relevant adaptor to access your micro SD (USB-C adaptor, SD to Micro SD, USB to micro SD)
Getting the Pi image onto the microSD
*this guide assumes you are starting from scratch – please skip ahead if you already have a working Pi that you can SSH into*
Once all your goodies arrive, we need to get an image onto the SD card. There are several ways of doing this (Etcher, Apple Pi Baker etc..) but a really simple way is to use the Raspberry Pi image imager.
Once downloaded, you put your card into your machine using the relevant adaptor, choose the relevant OS using the CHOOSE OS (I went for Rasbian Lite as I don’t need the desktop – feel free to use the normal Rasbian OS), locate your card using the CHOOSE SD CARD option, then click WRITE
Enabling SSH and setting up WiFi
Once you’ve burnt the image onto your micro SD card, remove and reinsert.
You should now see a drive called boot within Explorer / Finder.
Within boot, we need to create an empty file with no content or file extension called SSH. On my Mac I used my preferred text editor (BBEdit – previously TextWrangler) to create the file and save it on boot with no extension. It’s been a while since I’ve had to use a Windows machine, but from memory you just have the option of right clicking and making a new file which is a bit simpler!
Next we need to setup WiFi on the Pi so it’s available to connect remotely. To do this, we need to create another file within boot called wpa_supplicant.conf
The contents of this file need to be as follows;
country=UK ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 network={ ssid="REPLACE_WITH_YOUR_WIFI_SSID" scan_ssid=1 psk="REPLACE_WITH_YOUR_WIFI_PASSWORD" key_mgmt=WPA-PSK }
Double check you’ve got the details right, then save the file. Stick the microSD into the Pi, power it on and wait for up to a minute and a half for the Pi to complete it’s boot up.
Connecting to the Pi via SSH
Using your SSH application of choice (I’m using Terminal on my Mac, PuTTY appears to be a popular choice on Windows) it’s time to connect to the Raspberry Pi so we can get Docker installed and then TeslaMate.
First thing to do is locate the name or IP address of your Raspberry Pi on the network. If it’s the only Pi (that’s still called Raspberry Pi) you can SSH to raspberrypi.local, if you have more than one on your home network it’ll be raspberrypi-NUMBERVALUE.local – depending on how many you’ve got.
You can also find the device’s name and IP either using your router’s admin page and navigating to a page that shows connected devices, if you have something like a Mesh WiFi system it will show as a connected device (I have BT WholeHome and found it this way).
Once you’ve established the name, you connect using ssh pi@raspberrypi.local
(or pi@whateverthehostnameoripis.local) the default password is raspberry
You may then be prompted if you are sure you want to connect, type yes and hit enter
Once logged in, reset your password by typing passwd and follow the instructions (existing password, new password, confirm password)
Installing Docker
Having never installed Docker before, I followed this guide: https://dev.to/rohansawant/installing-docker-and-docker-compose-on-the-raspberry-pi-in-5-simple-steps-3mgl
For ease of use with this guide, these are the steps you need to follow
Installing Docker: curl -sSL https://get.docker.com | sh
Set the Pi user permissions to run Docker:sudo usermod -aG docker pi
newgrp docker
Test the Docker installation has worked: docker run hello-world
Install dependencies:sudo apt-get install -y libffi-dev libssl-dev
sudo apt-get install -y python3 python3-pip
sudo apt-get remove python-configparser
Install Docker Compose: sudo pip3 install docker-compose
Installing and starting TeslaMate
These instructions came direct from the TeslaMate guide, but for ease of use, I’ve replicated it here.
Within your SSH window, create a file called docker-compose.yml (I used the command nano docker-compose.yml
) which takes you straight into the file editor).
Into that file, paste the following:
version: "3" services: teslamate: image: teslamate/teslamate:latest restart: always environment: - DATABASE_USER=teslamate - DATABASE_PASS=secret - DATABASE_NAME=teslamate - DATABASE_HOST=database - MQTT_HOST=mosquitto ports: - 4000:4000 volumes: - ./import:/opt/app/import cap_drop: - all database: image: postgres:12 restart: always environment: - POSTGRES_USER=teslamate - POSTGRES_PASSWORD=secret - POSTGRES_DB=teslamate volumes: - teslamate-db:/var/lib/postgresql/data grafana: image: teslamate/grafana:latest restart: always environment: - DATABASE_USER=teslamate - DATABASE_PASS=secret - DATABASE_NAME=teslamate - DATABASE_HOST=database ports: - 3000:3000 volumes: - teslamate-grafana-data:/var/lib/grafana mosquitto: image: eclipse-mosquitto:1.6 restart: always ports: - 1883:1883 volumes: - mosquitto-conf:/mosquitto/config - mosquitto-data:/mosquitto/data volumes: teslamate-db: teslamate-grafana-data: mosquitto-conf: mosquitto-data:
Ctrl X to exit (saving and insuring the file name is correct)
You can now start up Docker and TeslaMate: docker-compose up -d
Accessing and setup up TeslaMate
Open up http://your-ip-address:4000 / http://yourpisname:4000 in your browser
Sign in with your Tesla details
You can now view dashboard data via http://your-ip-address:3000 / http://yourpisname:3000
Credentials to customise / build your own dashboards
At the bottom left of the screen, you will see the following icon
Click this to get to the sign in screen, the default username and password are both admin, you’ll be prompted for a new password on first sign in.
Backup your data!
Now you’ve got all this lovely data, lets get it safe. I’ve created a guide that lets you backup your TeslaMate data to Google Drive using rclone
Other considerations
- The above is a guide to getting things up and running if you are starting from scratch, you could also run this on a Pi that is already running something else. In my instance, I put this on the same Pi that is running Homebridge, and just started from the installing Docker stage. Check what ports other systems use, you can adjust the ports (3000 + 4000) in the docker-compose.yml that we pasted in above.
- This also doesn’t have to be installed locally, you could run this in AWS / GCP and have this available outside of your home network
- You could also expose your Pi to the internet to be able to access your data outside of the local network (guides available on the TeslaMate site)
- If you are considering any of the above, you do so considering the risks involved in having your Tesla credentials stored outside of a local device. I’m not saying one is more secure than the other, but you need to consider the risks.
- Backup your data! You can do this manually for now, I’ll try and get a guide put together on how to automate this (as soon as I figure it out).
Bulk import charging locations
Now you’ve got TeslaMate up and running, you can now bulk import Supercharger and destination charger locations by following the below guides:
How to bulk import Supercharger locations into TeslaMate
How to bulk import destination charger locations into TeslaMate