Deploying TeslaMate
Introduction
TeslaMate is a powerful, self-hosted data logger for Tesla vehicles. It connects to the Tesla API to collect and store detailed information about your vehicle, including location history, charging sessions, driving statistics, battery degradation, and energy consumption. The collected data is visualized through beautiful Grafana dashboards that provide insights into your Tesla ownership experience.
Key features of TeslaMate include:
- Comprehensive Data Logging: Records location, speed, battery level, climate settings, and more
- Driving Statistics: Track efficiency, distance traveled, and driving patterns
- Charging History: Monitor charging sessions, costs, and energy consumption
- Battery Health: Analyze battery degradation over time
- Grafana Dashboards: Beautiful, pre-built visualizations for all collected data
- Privacy-Focused: Self-hosted solution keeps your data under your control
- Geofencing: Define custom locations and track time spent at each
- MQTT Integration: Publish data to MQTT brokers for home automation
- REST API: Access your data programmatically
This guide walks you through deploying TeslaMate on Klutch.sh, setting up the PostgreSQL database, configuring Grafana dashboards, and connecting to your Tesla account.
Why Deploy TeslaMate on Klutch.sh
Deploying TeslaMate on Klutch.sh provides significant benefits:
Always-On Logging: Cloud deployment ensures continuous data collection without depending on home network availability or local hardware.
Simplified Deployment: Klutch.sh handles container orchestration, letting you focus on analyzing your Tesla data rather than managing infrastructure.
Persistent Storage: Reliable storage for your PostgreSQL database ensures years of historical data are preserved safely.
HTTPS by Default: Secure access to your TeslaMate web interface and Grafana dashboards from anywhere.
Scalable Resources: Allocate appropriate resources based on how many vehicles you’re tracking and data retention requirements.
GitHub Integration: Version control your configuration and enable automatic redeployments when you update settings.
Prerequisites
Before deploying TeslaMate on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your TeslaMate configuration
- A Tesla account with at least one vehicle
- Tesla API refresh token (obtained through the TeslaMate setup process)
- Basic familiarity with Docker and PostgreSQL
Understanding TeslaMate Architecture
TeslaMate consists of several components:
TeslaMate Core: The Elixir application that connects to the Tesla API, collects data, and stores it in PostgreSQL.
PostgreSQL Database: Stores all collected vehicle data, geofences, and application settings.
Grafana: Provides visualization dashboards for exploring your Tesla data.
MQTT Broker (Optional): Publishes real-time data for home automation integration.
Preparing Your Repository
Create a GitHub repository with the following structure:
teslamate-deploy/├── Dockerfile├── .dockerignore└── grafana/ └── dashboards/Creating the Dockerfile
FROM teslamate/teslamate:latest
# Environment variables for database connectionENV DATABASE_HOST=${DATABASE_HOST}ENV DATABASE_NAME=${DATABASE_NAME:-teslamate}ENV DATABASE_USER=${DATABASE_USER:-teslamate}ENV DATABASE_PASS=${DATABASE_PASS}
# TeslaMate configurationENV ENCRYPTION_KEY=${ENCRYPTION_KEY}ENV DISABLE_MQTT=${DISABLE_MQTT:-true}
# Timezone configurationENV TZ=${TZ:-UTC}
# Virtual host for URL generationENV CHECK_ORIGIN=${CHECK_ORIGIN:-true}ENV VIRTUAL_HOST=${VIRTUAL_HOST}
# Expose the web interface portEXPOSE 4000
# The base image includes the default entrypointEnvironment Variables Reference
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_HOST | Yes | - | PostgreSQL database hostname |
DATABASE_NAME | No | teslamate | PostgreSQL database name |
DATABASE_USER | No | teslamate | PostgreSQL username |
DATABASE_PASS | Yes | - | PostgreSQL password |
ENCRYPTION_KEY | Yes | - | Secret key for encrypting tokens (generate with openssl rand -base64 32) |
TZ | No | UTC | Timezone for timestamps |
VIRTUAL_HOST | No | - | External URL of your TeslaMate instance |
DISABLE_MQTT | No | true | Disable MQTT publishing |
MQTT_HOST | No | - | MQTT broker hostname (if enabled) |
Deploying on Klutch.sh
Set Up PostgreSQL Database
TeslaMate requires a PostgreSQL database. You can deploy PostgreSQL as a separate app on Klutch.sh or use a managed database service.
Create a PostgreSQL deployment with persistent storage:
| Mount Path | Size | Purpose |
|---|---|---|
/var/lib/postgresql/data | 10 GB | Database storage |
Generate Encryption Key
Generate a secure encryption key for storing Tesla API tokens:
openssl rand -base64 32Save this key securely; you’ll need it for the environment variables.
Push Your Repository to GitHub
Commit and push your Dockerfile to your GitHub repository.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project named “teslamate”.
Create the TeslaMate App
Within your project, create a new app and connect your GitHub repository.
Configure HTTP Traffic
Set the traffic type to HTTP with the internal port set to 4000.
Set Environment Variables
Configure the required environment variables:
| Variable | Value |
|---|---|
DATABASE_HOST | Your PostgreSQL host |
DATABASE_NAME | teslamate |
DATABASE_USER | teslamate |
DATABASE_PASS | Your secure database password |
ENCRYPTION_KEY | Your generated encryption key |
TZ | Your timezone (e.g., America/New_York) |
VIRTUAL_HOST | https://your-app-name.klutch.sh |
Deploy Your Application
Click Deploy to build and launch TeslaMate. Klutch.sh will provision HTTPS automatically.
Complete Initial Setup
Access your TeslaMate instance and sign in with your Tesla account to generate API tokens.
Setting Up Grafana Dashboards
TeslaMate’s power lies in its Grafana dashboards. Deploy Grafana alongside TeslaMate:
Grafana Dockerfile
FROM grafana/grafana:latest
# Install TeslaMate dashboardsENV GF_INSTALL_PLUGINS=pr0ps-trackmap-panel,natel-plotly-panel
# Database connection for GrafanaENV DATABASE_HOST=${DATABASE_HOST}ENV DATABASE_NAME=${DATABASE_NAME:-teslamate}ENV DATABASE_USER=${DATABASE_USER:-teslamate}ENV DATABASE_PASS=${DATABASE_PASS}
EXPOSE 3000Configure Grafana with the same database credentials to access TeslaMate data.
Initial Configuration
Connecting Your Tesla Account
- Access your TeslaMate instance at
https://your-app-name.klutch.sh - Click “Sign in with Tesla”
- Complete the Tesla authentication flow
- TeslaMate will begin collecting data from your vehicle
Setting Up Geofences
Define important locations for tracking:
- Navigate to Settings > Geofences
- Add locations like Home, Work, and frequent charging stations
- Configure cost settings for home charging calculations
Configuring Charging Costs
Accurate cost tracking requires configuration:
- Set your electricity rate in Settings
- Configure time-of-use rates if applicable
- Set Supercharger cost estimates
Understanding the Dashboards
TeslaMate includes numerous pre-built Grafana dashboards:
Overview: High-level statistics and current vehicle state
Drives: Detailed information about each trip
Charging Stats: Comprehensive charging history and costs
Battery Health: Track battery degradation over time
Efficiency: Analyze energy consumption patterns
Locations: Time spent at different geofenced locations
Vampire Drain: Monitor phantom battery loss
Production Best Practices
Security Recommendations
- Strong Encryption Key: Use a cryptographically secure key for token encryption
- Database Security: Secure your PostgreSQL instance with strong passwords
- Access Control: Consider adding authentication proxy for public access
- Regular Backups: Back up your PostgreSQL database regularly
Performance Optimization
- Database Indexing: TeslaMate automatically manages indexes for common queries
- Data Retention: Consider archiving old data if storage becomes a concern
- Resource Allocation: Allocate adequate memory for PostgreSQL with large datasets
Backup Strategy
Protect your years of Tesla data:
- Regular PostgreSQL backups using
pg_dump - Export Grafana dashboard configurations
- Store encryption key securely (losing it means losing access to tokens)
Troubleshooting
Vehicle Not Appearing
- Verify Tesla account credentials are correct
- Check that API access is not blocked by Tesla
- Review container logs for authentication errors
Data Gaps in Charts
- TeslaMate requires consistent connectivity to Tesla API
- Vehicle may be asleep during gaps (expected behavior)
- Check for API rate limiting if data is sparse
Grafana Dashboards Not Loading
- Verify database connection settings in Grafana
- Ensure Grafana can reach the PostgreSQL instance
- Check that TeslaMate plugins are installed
High Battery Drain Reported
- Frequent API polling can keep the vehicle awake
- Configure sleep settings in TeslaMate preferences
- Use suspend mode when vehicle is at home
Additional Resources
- TeslaMate Documentation
- TeslaMate GitHub Repository
- Grafana Documentation
- TeslaMate Community Discussions
- Klutch.sh Persistent Volumes
- Klutch.sh Deployments
Conclusion
Deploying TeslaMate on Klutch.sh gives you a powerful, always-on data logging solution for your Tesla. With comprehensive dashboards, detailed statistics, and complete data ownership, you’ll gain deep insights into your vehicle’s performance, charging habits, and efficiency. The combination of TeslaMate’s rich feature set and Klutch.sh’s reliable infrastructure ensures your Tesla data is collected continuously and accessible from anywhere.