Skip to content

A slightly convoluted way of getting your vehicle data from TeslaMate to A Better Route Planner.

License

Notifications You must be signed in to change notification settings

SirSheik/teslamate-abrp

 
 

Repository files navigation

TeslaMate: MQTT to ABRP

amd64+arm64 build GitHub license

A slightly convoluted way of getting your vehicle data from TeslaMate to ABRP.

Setup and Usage

1. Use as Docker container

1.1 Requirements

For this to work, you need a working instance of TeslaMate with MQTT enabled. See the official TeslaMate doc as a reference on how this might look like.

1.2 Getting a USER TOKEN from ABRP

Inside the ABRP (web)app, navigate to your car settings and use the "generic" card (last one at the very bottom) to generate your user token. Make a note of that token and keep it to yourself.

1.3 Adding the service to docker-compose.yml

In your TeslaMate docker-compose.yml, add the teslamate-abrp service by adding the following lines in the "services:" section:

ABRP:
  container_name: TeslaMate_ABRP
  image: fetzu/teslamate-abrp:latest #NOTE: you can replace ":latest" with ":beta" to use the bleeding edge version, without any guarantees.
  restart: always
  # privileged: true
  # NOTE: un-comment the previous line to run the container in privilege mode (necessary on RaspberryPi)
  environment:
    - MQTT_SERVER=mosquitto
    - USER_TOKEN=y0ur-4p1-k3y
    - CAR_NUMBER=1
    - CAR_MODEL=s100d #NOTE: This is optional, see below

Make sure to adapt the following environment variables:

  • The first value MQTT_SERVER corresponds to the name of your MQTT service name ("mosquitto" in the doc).
  • The second values (USER_TOKEN) correspond to the value provided by ABRP.
  • The third value corresponds to your car number (1 if you only have a single car).
  • The last value corresponds to your car model. When this value is not set, the script will try to determine your car model automatically (this should work for Models S, X, 3 and Y with standard configs). The detection is very bare-bones and will not take into account factors such as wheel type, heat pump, LFP battery. It is recommended you take a moment to find your car model on https://api.iternio.com/1/tlm/get_carmodels_list and use the corresponding key as a value for CAR_MODEL (e.g. "tesla:m3:20:bt37:heatpump" for a 2021 Model 3 LR).
  • Additionally, MQTT_PASSWORD and/or MQTT_USERNAME can be set to use authentication on the MQTT server.

Then from the command line, navigate to the folder where your docker-compose.yml is located and run:

docker-compose pull ABRP
docker-compose up -d ABRP

If all goes well, your car should be shown as online in ABRP after a minute. The logs should show "Connected with result code 0".

2. Use as python script

The script can also be run directly on a machine with Python 3.x. Please note that the machine needs to have access to your MQTT server on port 1883.

2.1 Installing requirements

To install the requirements, run

pip install -r requirements.txt

2.2 Running

To run, you can either use the CLI. Please note that USER_TOKEN, CAR_NUMBER, CAR_MODEL and MQTT_SERVER are required arguments.

If you are using a MQTT server with username or authentication, pass the -l (to use MQTT_USERNAME only) or -a (for authentication with MQTT_USERNAME and MQTT_PASSWORD) options.

Usage: 
    teslamate_mqtt2abrp.py [-hlap] [USER_TOKEN] [CAR_NUMBER] [MQTT_SERVER] [MQTT_USERNAME] [MQTT_PASSWORD] [--model CAR_MODEL]

Arguments:
    USER_TOKEN          User token generated by ABRP.
    CAR_NUMBER          Car number from TeslaMate (usually 1).
    MQTT_SERVER         MQTT server address (e.g. "192.168.1.1").
    MQTT_USERNAME       MQTT username (e.g. "teslamate") - use with -l or -a.
    MQTT_PASSWORD       MQTT password (e.g. "etamalset") - use with -a.

Options:
    -h                  Show this screen.
    -l                  Use username to connect to MQTT server.
    -a                  Use authentification (user and password) to connect to MQTT server.
    --model CAR_MODEL   Car model according to https://api.iternio.com/1/tlm/get_CARMODELs_list

Note:
    All arguments can also be passed as corresponding OS environment variables.

Note: All arguments can also be passed as corresponding OS environment variables. Arguments passed through the CLI will always supersede OS environment variables.

Credits

Based on/forked from letienne's original code, with improvement by various contributors (see commit history).

License

Licensed under the MIT license.

About

A slightly convoluted way of getting your vehicle data from TeslaMate to A Better Route Planner.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.1%
  • Dockerfile 1.9%