Deploy TeslaMate

Data logger for Tesla cars, with Grafana dashboards

Deploy TeslaMate

Just deployed

/var/lib/postgresql/data

Just deployed

/var/lib/grafana

Just deployed

/mosquitto/data

Just deployed

/opt/app/import

Deploy and Host TeslaMate on Railway

TeslaMate is an open source data logger for Tesla vehicles. It polls the Tesla API for your car, records every drive, charge, software update and sleep period into PostgreSQL, and turns that history into Grafana dashboards covering efficiency, battery degradation, charging cost and vampire drain. Owners use it to prove range loss under warranty, split home and public charging costs, and own their data rather than rent it.

Self-host TeslaMate on Railway and what normally takes an evening of Docker Compose is already wired together: teslamate runs the app, Postgres stores the history, grafana serves the bundled dashboards against that database, mosquitto publishes live vehicle state over MQTT, and teslamate-proxy puts a password in front of the web interface. That last piece matters — TeslaMate has no login of its own, so running it without a gateway would leave your car's location on the open internet.

TeslaMate, Grafana, Mosquitto and Postgres services on Railway

Getting Started with TeslaMate on Railway

Deploy the template, then open the public URL of the teslamate-proxy service. The browser asks for a username and password — the PROXY_USERNAME and PROXY_PASSWORD values on that service, not your Tesla credentials. Behind it is TeslaMate's sign-in page, which wants a Tesla API access token and refresh token. TeslaMate never sees your Tesla password: generate the pair with a token app such as tesla_auth, then paste both in. The vehicle appears within a minute and logging starts the next time you drive.

Open Settings next and check the two URL fields, which link TeslaMate and Grafana in both directions; change them only for a custom domain. Then open the grafana service's own URL and sign in with GF_SECURITY_ADMIN_USER and GF_SECURITY_ADMIN_PASSWORD. Twenty-three dashboards are already provisioned — start with Overview, and use Database Information to confirm the datasource works before any driving data exists. Finally add geo-fences for home and work, so charges and trips are labelled by place rather than coordinates.

TeslaMate settings for range, units and dashboard URLs TeslaMate geo-fence list with a saved home location Grafana dashboard reporting TeslaMate table and index sizes

About Hosting TeslaMate

TeslaMate is an Elixir application that adapts its polling rate to what the car is doing — seconds apart while driving or charging, nothing once the car sleeps, so it adds no measurable vampire drain. Everything it records is yours, in your own database, with no retention limit.

  • High-resolution drive and charge logging, with GPS traces and per-session energy
  • Battery health and projected-range tracking over the life of the car
  • Charging cost tracking, with per-geo-fence pricing rules
  • Geo-fencing, so home, work and favourite superchargers are named rather than plotted
  • MQTT publishing for Home Assistant, Node-RED and other automation tools
  • Import from TeslaFi and tesla-apiscraper

TeslaMate writes to Postgres over Railway's private network, Grafana reads that same database and never talks to the app, and the gateway terminates the password prompt so only authenticated traffic reaches the app.

Why Deploy TeslaMate on Railway

A logger that must never miss a drive is what a managed platform is for.

  • Always-on hosting without a Raspberry Pi that dies mid-road-trip
  • Managed PostgreSQL with backups, not a database on an SD card
  • Private networking between app, database and broker out of the box
  • HTTPS, a public hostname and a password gate from the first deploy

Common Use Cases

  • Warranty and resale evidence — a year of battery-degradation data beats a dashboard estimate when arguing range loss.
  • Charging cost accounting — a per-kWh rate on a home geo-fence and another for public chargers gives a real cost per mile.
  • Business mileage logs — export drives for expense claims, addresses resolved automatically.
  • Home automation — trigger the garage or a charge schedule from live car state over MQTT.

Dependencies for TeslaMate

  • teslamate/teslamate:latest — the app and web interface, from teslamate-org/teslamate
  • ghcr.io/railwayapp-templates/postgres-ssl:18 — holds every drive, charge and position. The migrations need the cube and earthdistance extensions, both on this image.
  • teslamate/grafana:latest — Grafana 13 with the dashboards and Postgres datasource already provisioned
  • eclipse-mosquitto:2 — the MQTT broker, built with a password file and a TLS listener
  • caddy:2-alpine — the authentication gateway in front of the app

Environment Variables Reference

VariableDescriptionRequired
ENCRYPTION_KEYEncrypts stored Tesla tokens; changing it invalidates themYes
SECRET_KEY_BASESession signing key, must stay stable across deploysYes
PROXY_PASSWORDPassword for the web interface, checked by the gatewayYes
PROXY_USERNAMEUsername for that prompt, admin by defaultNo
GF_SECURITY_ADMIN_PASSWORDGrafana admin passwordYes
MQTT_PASSWORDBroker password, shared with any external subscriberYes
TZLocal time zone, e.g. Europe/BerlinNo
DISABLE_MQTTSet true to drop the broker entirelyNo

Deployment Dependencies

Hardware Requirements for Self-Hosting TeslaMate

ResourceMinimumRecommended
CPU1 vCPU2 vCPU
RAM1 GB across all services2 GB
Storage5 GB for Postgres10 GB after a few years of driving
RuntimeErlang/OTP 29, PostgreSQL 17+from the images

The app idles at roughly 300 MB; storage is what grows, at a few megabytes per thousand miles.

Self-Hosting TeslaMate

Outside Railway TeslaMate is a Docker Compose stack. The minimum is the app and a database:

docker run -d --name teslamate -p 4000:4000 \
  -e ENCRYPTION_KEY=change-me -e DISABLE_MQTT=true \
  -e DATABASE_HOST=database -e DATABASE_NAME=teslamate \
  -e DATABASE_USER=teslamate -e DATABASE_PASS=change-me \
  teslamate/teslamate:latest

Add Grafana and the broker for the full experience:

services:
  database:
    image: postgres:18-trixie
    environment: [POSTGRES_USER=teslamate, POSTGRES_PASSWORD=change-me, POSTGRES_DB=teslamate]
    volumes: ["teslamate-db:/var/lib/postgresql"]
  grafana:
    image: teslamate/grafana:latest
    environment: [DATABASE_USER=teslamate, DATABASE_PASS=change-me, DATABASE_HOST=database]
    ports: ["3000:3000"]
  mosquitto:
    image: eclipse-mosquitto:2

Upstream is explicit that this belongs on a home network: exposed to the internet it has no authentication at all, which is why the password gateway is part of this template rather than an optional extra.

How Much Does TeslaMate Cost to Self-Host?

TeslaMate is free and open source under AGPL-3.0, with no paid tier, no account and no telemetry. On Railway you pay only for the infrastructure the five services use, which for a single vehicle is a small always-on workload. The alternatives are subscriptions with usage caps — TeslaFi around $8 a month, Tessie and Teslascope comparable — and none let you keep the raw data. Pick TeslaMate for unlimited history you own, a hosted service if you would rather have a phone app than a database.

FAQ

What is TeslaMate? An open source, self-hosted data logger for Tesla vehicles. It records drives, charges, battery health and sleep behaviour into PostgreSQL and visualises them in Grafana.

What does this Railway template deploy? Five services: TeslaMate, a managed PostgreSQL database, Grafana with the bundled dashboards, an MQTT broker, and a Caddy gateway that password-protects the web interface.

Why does the template include a password gateway? TeslaMate ships no authentication — every page including Settings is open to whoever loads it, and those pages show your car's location. Upstream's own hardening guide answers this with a reverse proxy doing HTTP Basic Auth, and so does this template.

Do I need to give TeslaMate my Tesla password? No. You generate an access and refresh token pair with a separate token app and paste those in. They are encrypted at rest with your ENCRYPTION_KEY.

Why is PostgreSQL a separate service instead of SQLite? TeslaMate is built around PostgreSQL and needs the cube and earthdistance extensions for distance queries. Grafana reads that same database directly, which removes any export step.

Can I connect TeslaMate to Home Assistant? Yes. The broker is reachable over TLS from outside Railway: point Home Assistant's MQTT integration at its public host and port with the credentials the app uses, and set MQTT_HOME_ASSISTANT_DISCOVERY=true. Vehicles polled by one deployment all publish there, so a multi-car Tesla account needs no second instance.


Template Content

More templates in this category

View Template
Typesense vs Meilisearch
self-hosted Typesense vs Meilisearch

onepush
0
View Template
Betterlytics
Betterlytics is a cookieless analytics platform GDPR-compliant.

OpenSource Templates
27
View Template
Finance Tracker
Private multi-user household finance ledger with budgets and CSV import.

wotonews
0