Giter VIP home page Giter VIP logo

teslamate's Introduction

TeslaMate

A data logger for your Tesla.

  • Written in Elixir
  • Data is stored in PostgreSQL
  • Visualization and data analysis with Grafana
  • Current vehicle data is published to a local MQTT Broker (optional)

Features

Dashboards

  • Lifetime driving map
  • Drive and charging reports
  • Driving efficiency report
  • Consumption (net / gross)
  • Vampire drain
  • Projected 100% range (battery degradation)
  • SOC charging stats
  • Visited addresses
  • History of installed updates

General

  • Little to no additional vampire drain: the car will fall asleep after a certain idle time
  • Built-in API to manually suspend / resume sending requests to the Tesla API
  • Automatic address lookup
  • Locally enriches positions with elevation data
  • Geo-fencing feature to create custom locations
  • Supports multiple vehicles per Tesla Account

Screenshots

Drive Details Drives Efficiency States Charge Details Charges Vampire Drain

Table of contents


Installation

Docker (recommended)

The recommended way to install and run TeslaMate is to use Docker. Create a docker-compose.yml file and replace the necessary environment variables:

version: '3'
services:
  teslamate:
    image: teslamate/teslamate:latest
    restart: unless-stopped
    environment:
      - DATABASE_USER=teslamate
      - DATABASE_PASS=secret
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=db
      - MQTT_HOST=mosquitto
      - VIRTUAL_HOST=localhost # if you're going to access the UI from another  machine replace
                               # "localhost" with the hostname / IP address of the docker host.
      - TZ=Europe/Berlin       # (optional) replace to use local time in debug logs. See "Configuration".
    ports:
      - 4000:4000
    cap_drop:
      - all

  db:
    image: postgres:11
    environment:
      - POSTGRES_USER=teslamate
      - POSTGRES_PASSWORD=secret
    volumes:
      - teslamate-db:/var/lib/postgresql/data

  grafana:
    image: teslamate/grafana:latest
    environment:
      - DATABASE_USER=teslamate
      - DATABASE_PASS=secret
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=db
    ports:
      - 3000:3000
    volumes:
      - teslamate-grafana-data:/var/lib/grafana

  mosquitto:
    image: eclipse-mosquitto:1.6
    ports:
      - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

volumes:
    teslamate-db:
    teslamate-grafana-data:
    mosquitto-conf:
    mosquitto-data:

Afterwards start everything with docker-compose up.

Open the web interface at http://ip-of-your-machine:4000 and sign in with your Tesla Account.

To access Grafana go to http://ip-of-your-machine:3000.

Optional: To switch to imperial measurements open the web interface and navigate to Settings.

For a more advanced setup check out the wiki: Advanved Setup (SSL, FQDN, pw protected)

Manual Installation (advanced)

To run TeslaMate without Docker follow this guide: Manual Installation

Configuration

TeslaMate uses environment variables for runtime configuration.

Environment Variables

Variable Name Description Default Value
DATABASE_USER Username (required) /
DATABASE_PASS User password (required) /
DATABASE_NAME The database to connect to (required) /
DATABASE_HOST Hostname of the database server (required) /
DATABASE_PORT Port of the database server 5432
DATABASE_POOL_SIZE Size of the database connection pool 5
VIRTUAL_HOST Host part used for generating URLs throughout the app localhost
PORT Port where the web interface is exposed 4000
DISABLE_MQTT Disables the MQTT feature if true false
MQTT_HOST Hostname of the broker (required unless DISABLE_MQTT is true) /
MQTT_USERNAME Username (optional) /
MQTT_PASSWORD Password (optional) /
MQTT_TLS Enables TLS if true (optional) false
MQTT_TLS_ACCEPT_INVALID_CERTS Accepts invalid certificates if true (optional) false
LOCALE The default locale for the web interface and addresses. Currently available: en (default) and de en
TZ Used to establish the local time zone. See List of tz database time zones. /

Upgrading

Check the Changelog before upgrading!

Docker

Run docker-compose pull and restart with docker-compose up.

Manually

See Manual Installation

Web Interface

There is a basic real-time web interface. Once the application is running locally, you can access it at localhost:4000.

Web Interface

MQTT

Unless the MQTT feature is disabled data is published to the following topics ($car_id usually starts at 1):

teslamate/cars/$car_id/display_name
teslamate/cars/$car_id/state
teslamate/cars/$car_id/battery_level
teslamate/cars/$car_id/ideal_battery_range_km
teslamate/cars/$car_id/est_battery_range_km
teslamate/cars/$car_id/rated_battery_range_km
teslamate/cars/$car_id/charge_energy_added
teslamate/cars/$car_id/charger_power
teslamate/cars/$car_id/plugged_in
teslamate/cars/$car_id/scheduled_charging_start_time
teslamate/cars/$car_id/charge_limit_soc
teslamate/cars/$car_id/speed
teslamate/cars/$car_id/outside_temp
teslamate/cars/$car_id/inside_temp
teslamate/cars/$car_id/locked
teslamate/cars/$car_id/sentry_mode

FAQ

Sometimes the first few minutes of a drive are not recorded even though the car was online. Why?

TeslaMate polls the car every few seconds while driving or charging. After that, it keeps polling for about 15 minutes (to catch the following drive if you stopped for a drink, for example). After this period, TeslaMate will stop polling the car for about 21 minutes to let it go to sleep. This is repeated until the car is asleep or starts to drive/charge again. Once sleeping, TeslaMate will never wake the wake the car. It is only checked twice a minute to see if it is still sleeping.

This approach may sometimes lead to small data gaps: if the car starts driving during the 21 minute period where TeslaMate is not polling, nothing can be logged.

Solution

To get around this you can use your smartphone to inform TeslaMate when to start polling again. In short, create a workflow with Tasker (Android) or Shortcuts (iOS) that listens for connected Bluetooth devices. If a connection to your Tesla is established send an HTTP PUT resume request to your publicly exposed TeslaMate instance. See the available commands below.

Alternatively / additionally, you can experiment with the sleep settings. Some cars, especially Model 3, seem to handle a Time to Try Sleeping value of 12 min just fine. Doing so reduces the likelihood of potential data gaps. Just keep an eye on your car afterwards to see if it still goes into sleep mode.

Available Commands
PUT https://teslamate.your-domain.com/api/car/$car_id/logging/resume
PUT https://teslamate.your-domain.com/api/car/$car_id/logging/suspend

โš ๏ธ I strongly recommend to use a reverse-proxy with HTTPS and basic access authentication when exposing TeslaMate to the public internet. Additionally only permit access to /api/car/$car_id/logging/resume and/or /api/car/$car_id/logging/suspend. See Advanved Setup (SSL, FQDN, pw protected).

My car is not sleeping!

Please follow the steps applicable to TeslaMate mentioned in this article.

Most importantly, if you have a Model S or X built prior to March 2018 make sure 'Always Connected' is turned off and 'Energy Savings' is turned on in the vehicle.

What is the geo-fence feature for?

At the moment geo-fences are a way to create custom locations like ๐Ÿก Home or ๐Ÿ› ๏ธ Work That may be particularly useful if the addresses (which are provided by OSM) in your region are inaccurate or if you street-park at locations where the exact address may vary.

Contributing

All contributions are welcome and greatly appreciated!

Initial Setup

To run the TeslaMate test suite you need PostgreSQL 10+ running locally with a database named teslamate_test. Follow these steps to create the database and run all migrations:

# download dependencies
mix deps.get

# create the dev database and run migrations
mix ecto.setup

# create the test database
MIX_ENV=test mix ecto.setup

# download JavaScript dependencies
npm install --prefix ./assets

A local MQTT broker like mosquitto is not required but recommend.

Development

Start an iex session in another terminal window:

iex -S mix phx.server

Then sign in with a Tesla account.

Hot reloading

To immediately apply your local changes open or reload http://localhost:4000. You can also reload specific modules via iex, for example:

iex> r TeslaMate.Vehicles.Vehicle

To only compile the changes:

mix compile

Code formatting

mix format

Testing

To ensure a commit passes CI you should run mix ci locally, which executes the following commands:

  • Check formatting (mix format --check-formatted)
  • Run all tests (mix test)

Making Changes to Grafana Dashboards

To update dashboards you need Grafana running locally. Create the following docker-compose.yml:

version: '3'
services:
  grafana:
    image: teslamate-grafana:latest
    environment:
      - DATABASE_USER=postgres
      - DATABASE_PASS=postgres
      - DATABASE_NAME=teslamate_dev
      - DATABASE_HOST=host.docker.internal
    ports:
      - 3000:3000
    volumes:
      - grafana-data:/var/lib/grafana

volumes:
    grafana-data:

Then build the image with make grafana and run the container via docker-compose up grafana.

Access the Grafana at http://localhost:3000 and sign in with the default user admin and password admin.

Then edit the respective dashboard(s) locally. To export a dashboard hit the 'Save' button and select Save JSON to file. The final JSON file belongs in the directory ./grafana/dashboards/. To apply the changes rebuild the image and start the container.

Donations

Maintaining this project isn't effortless, or free. If you would like to kick in and help me cover those costs, that would be awesome. If you don't, no problem; just share your love and show your support.

Donate with PayPal

Disclaimer

Please note that the use of the Tesla API in general and this software in particular is not endorsed by Tesla. Use at your own risk.

Credits

TeslaLogger was a big inspiration especially during early development. Thanks!

teslamate's People

Contributors

adriankumpf avatar mvaal avatar dependabot-preview[bot] avatar chromox avatar olexs avatar siomiz avatar virtualm2000 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.