Skip to content

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 connection
ENV DATABASE_HOST=${DATABASE_HOST}
ENV DATABASE_NAME=${DATABASE_NAME:-teslamate}
ENV DATABASE_USER=${DATABASE_USER:-teslamate}
ENV DATABASE_PASS=${DATABASE_PASS}
# TeslaMate configuration
ENV ENCRYPTION_KEY=${ENCRYPTION_KEY}
ENV DISABLE_MQTT=${DISABLE_MQTT:-true}
# Timezone configuration
ENV TZ=${TZ:-UTC}
# Virtual host for URL generation
ENV CHECK_ORIGIN=${CHECK_ORIGIN:-true}
ENV VIRTUAL_HOST=${VIRTUAL_HOST}
# Expose the web interface port
EXPOSE 4000
# The base image includes the default entrypoint

Environment Variables Reference

VariableRequiredDefaultDescription
DATABASE_HOSTYes-PostgreSQL database hostname
DATABASE_NAMENoteslamatePostgreSQL database name
DATABASE_USERNoteslamatePostgreSQL username
DATABASE_PASSYes-PostgreSQL password
ENCRYPTION_KEYYes-Secret key for encrypting tokens (generate with openssl rand -base64 32)
TZNoUTCTimezone for timestamps
VIRTUAL_HOSTNo-External URL of your TeslaMate instance
DISABLE_MQTTNotrueDisable MQTT publishing
MQTT_HOSTNo-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 PathSizePurpose
    /var/lib/postgresql/data10 GBDatabase storage

    Generate Encryption Key

    Generate a secure encryption key for storing Tesla API tokens:

    Terminal window
    openssl rand -base64 32

    Save 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:

    VariableValue
    DATABASE_HOSTYour PostgreSQL host
    DATABASE_NAMEteslamate
    DATABASE_USERteslamate
    DATABASE_PASSYour secure database password
    ENCRYPTION_KEYYour generated encryption key
    TZYour timezone (e.g., America/New_York)
    VIRTUAL_HOSThttps://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 dashboards
ENV GF_INSTALL_PLUGINS=pr0ps-trackmap-panel,natel-plotly-panel
# Database connection for Grafana
ENV DATABASE_HOST=${DATABASE_HOST}
ENV DATABASE_NAME=${DATABASE_NAME:-teslamate}
ENV DATABASE_USER=${DATABASE_USER:-teslamate}
ENV DATABASE_PASS=${DATABASE_PASS}
EXPOSE 3000

Configure Grafana with the same database credentials to access TeslaMate data.

Initial Configuration

Connecting Your Tesla Account

  1. Access your TeslaMate instance at https://your-app-name.klutch.sh
  2. Click “Sign in with Tesla”
  3. Complete the Tesla authentication flow
  4. TeslaMate will begin collecting data from your vehicle

Setting Up Geofences

Define important locations for tracking:

  1. Navigate to Settings > Geofences
  2. Add locations like Home, Work, and frequent charging stations
  3. Configure cost settings for home charging calculations

Configuring Charging Costs

Accurate cost tracking requires configuration:

  1. Set your electricity rate in Settings
  2. Configure time-of-use rates if applicable
  3. 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:

  1. Regular PostgreSQL backups using pg_dump
  2. Export Grafana dashboard configurations
  3. 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

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.