All Projects → tobiasehlert → teslamateapi

tobiasehlert / teslamateapi

Licence: MIT license
TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON

Programming Languages

go
31211 projects - #10 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to teslamateapi

TeslaMateAgile
Integration to automatically fill in prices for charge data captured by TeslaMate for smart energy providers
Stars: ✭ 40 (-14.89%)
Mutual labels:  tesla, teslamate
XCloud
Official Code for Paper <XCloud: Design and Implementation of AI Cloud Platform with RESTful API Service> (arXiv1912.10344)
Stars: ✭ 58 (+23.4%)
Mutual labels:  restful-api
dashy
🚀 A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Stars: ✭ 7,103 (+15012.77%)
Mutual labels:  self-hosted
buzzyblog
React + WordPress REST API, a new endeavor to provide a better experience to content creators, web masters and digital marketers, etc
Stars: ✭ 50 (+6.38%)
Mutual labels:  restful-api
Shopixl
Open-source, self-hosted, Buycraft alternative
Stars: ✭ 17 (-63.83%)
Mutual labels:  self-hosted
http4s-good-practices
Collection of what I consider good practices in Http4s (WIP)
Stars: ✭ 74 (+57.45%)
Mutual labels:  restful-api
LazyWaimai-Api
基于Yii2框架的LazyWaimai Api端,REST API架构风格的,使用Oauth2进行身份认证
Stars: ✭ 42 (-10.64%)
Mutual labels:  restful-api
MusicDatabase-API
This project is able to manage your songs, artists, albums and more by RESTful API. Developed with ASP.NET Core 2.0 & EF Core and used PostgreSQL Database Provider. Implemented Swagger to project.
Stars: ✭ 18 (-61.7%)
Mutual labels:  restful-api
mCaptcha
A no-nonsense CAPTCHA system with seamless UX | Backend component
Stars: ✭ 473 (+906.38%)
Mutual labels:  self-hosted
ethibox
Open-source web apps hoster
Stars: ✭ 130 (+176.6%)
Mutual labels:  self-hosted
react-nodejs-mongodb-crud
👨‍💻 Fullstack web app built with MongoDB, NodeJs, React and Redux. Features: Protected routes client/server side, MaterialUI layout
Stars: ✭ 91 (+93.62%)
Mutual labels:  restful-api
self-hosted-services
A core set of privacy-preserving services that can be easily self-hosted via Docker Compose.
Stars: ✭ 123 (+161.7%)
Mutual labels:  self-hosted
server
AuthzForce Server (Community Edition)
Stars: ✭ 48 (+2.13%)
Mutual labels:  restful-api
nestjs-rest-sample
NestJS RESTful APIs Sample
Stars: ✭ 204 (+334.04%)
Mutual labels:  restful-api
jmal-cloud-view
JmalCloud 是一款私有云存储网盘项目,能够简单安全管理您的云端文件
Stars: ✭ 148 (+214.89%)
Mutual labels:  self-hosted
Liquid-Application-Framework
Liquid Application Framework documentation, useful links and sample project
Stars: ✭ 467 (+893.62%)
Mutual labels:  restful-api
traefik-docker-ansible
🐳 🐹  This is an Ansible playbook to install multiple Web applications on a single Ubuntu server with Docker and Traefik.
Stars: ✭ 75 (+59.57%)
Mutual labels:  self-hosted
seal
django-base-templates 主要为 django 开发DEMO, 支持 非前后端分离 和 前后端分离模式 。
Stars: ✭ 118 (+151.06%)
Mutual labels:  restful-api
docker-node-express-boilerplate
Boilerplate for quickly bootstrapping production-ready RESTful APIs / microservices
Stars: ✭ 113 (+140.43%)
Mutual labels:  restful-api
docker-ttrss
Tiny Tiny RSS feed reader as a Docker image.
Stars: ✭ 55 (+17.02%)
Mutual labels:  self-hosted

TeslaMateApi

GitHub CI GitHub go.mod version Docker version Docker size GitHub license Docker pulls

TeslaMateApi is a RESTful API to get data collected by self-hosted data logger TeslaMate in JSON.

  • Written in Golang
  • Data is collected from TeslaMate Postgres database and local MQTT Broker
  • Endpoints return data in JSON format
  • Send commands to your Tesla through the TeslaMateApi

Table of Contents

How to use

You can either use it in a Docker container or go download the code and deploy it yourself on any server.

Docker-compose

If you run the simple Docker deployment of TeslaMate, then adding this will do the trick. You'll have TeslaMateApi exposed at port 8080 locally then.

services:
  teslamateapi:
    image: tobiasehlert/teslamateapi:latest
    restart: always
    depends_on:
      - database
    environment:
      - ENCRYPTION_KEY=MySuperSecretEncryptionKey
      - DATABASE_USER=teslamate
      - DATABASE_PASS=secret
      - DATABASE_NAME=teslamate
      - DATABASE_HOST=database
      - MQTT_HOST=mosquitto
      - TZ=Europe/Berlin
    ports:
      - 8080:8080

If you are using TeslaMate Traefik setup in Docker with environment variables file (.env), then you can simply add this section to the services: section of the docker-compose.yml file:

services:
  teslamateapi:
    image: tobiasehlert/teslamateapi:latest
    restart: always
    depends_on:
      - database
    environment:
      - ENCRYPTION_KEY=${TM_ENCRYPTION_KEY}
      - DATABASE_USER=${TM_DB_USER}
      - DATABASE_PASS=${TM_DB_PASS}
      - DATABASE_NAME=${TM_DB_NAME}
      - DATABASE_HOST=database
      - MQTT_HOST=mosquitto
      - TZ=${TM_TZ}
    labels:
      - "traefik.enable=true"
      - "traefik.port=8080"
      - "traefik.http.middlewares.redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.teslamateapi-auth.basicauth.realm=teslamateapi"
      - "traefik.http.middlewares.teslamateapi-auth.basicauth.usersfile=/auth/.htpasswd"
      - "traefik.http.routers.teslamateapi-insecure.rule=Host(`${FQDN_TM}`)"
      - "traefik.http.routers.teslamateapi-insecure.middlewares=redirect"
      - "traefik.http.routers.teslamateapi.rule=Host(`${FQDN_TM}`) && (Path(`/api`) || PathPrefix(`/api/`))"
      - "traefik.http.routers.teslamateapi.entrypoints=websecure"
      - "traefik.http.routers.teslamateapi.middlewares=teslamateapi-auth"
      - "traefik.http.routers.teslamateapi.tls.certresolver=tmhttpchallenge"

In this case, the TeslaMateApi would be accessible at teslamate.example.com/api/

Environment variables

Basically the same environment variables for the database, mqqt and timezone need to be set for TeslaMateApi as you have for TeslaMate.

Required environment variables (even if there are some default values available)

Variable Type Default
DATABASE_USER string teslamate
DATABASE_PASS string secret
DATABASE_NAME string teslamate
DATABASE_HOST string database
ENCRYPTION_KEY string
MQTT_HOST string mosquitto
TZ string Europe/Berlin

Optional environment variables

Variable Type Default
TESLAMATE_SSL boolean false
TESLAMATE_HOST string teslamate
TESLAMATE_PORT string 4000
API_TOKEN string
API_TOKEN_DISABLE string false
DATABASE_PORT integer 5432
DATABASE_TIMEOUT integer 60000
DATABASE_SSL boolean true
DEBUG_MODE boolean false
DISABLE_MQTT boolean false
MQTT_TLS boolean false
MQTT_PORT integer 1883 (if TLS is true: 8883)
MQTT_USERNAME string
MQTT_PASSWORD string
MQTT_NAMESPACE string

Commands environment variables

Variable Type Default
ENABLE_COMMANDS boolean false
COMMANDS_ALL boolean false
COMMANDS_ALLOWLIST string allow_list.json
COMMANDS_LOGGING boolean false
COMMANDS_WAKE boolean false
COMMANDS_ALERT boolean false
COMMANDS_REMOTESTART boolean false
COMMANDS_HOMELINK boolean false
COMMANDS_SPEEDLIMIT boolean false
COMMANDS_VALET boolean false
COMMANDS_SENTRYMODE boolean false
COMMANDS_DOORS boolean false
COMMANDS_TRUNK boolean false
COMMANDS_WINDOWS boolean false
COMMANDS_SUNROOF boolean false
COMMANDS_CHARGING boolean false
COMMANDS_CLIMATE boolean false
COMMANDS_MEDIA boolean false
COMMANDS_SHARING boolean false
COMMANDS_SOFTWAREUPDATE boolean false
COMMANDS_UNKNOWN boolean false

API documentation

More detailed documentation of every endpoint will come..

Available endpoints

  • GET /api
  • GET /api/v1
  • GET /api/v1/cars
  • GET /api/v1/cars/:CarID
  • GET /api/v1/cars/:CarID/charges
  • GET /api/v1/cars/:CarID/charges/:ChargeID
  • GET /api/v1/cars/:CarID/command
  • POST /api/v1/cars/:CarID/command/:Command
  • GET /api/v1/cars/:CarID/drives
  • GET /api/v1/cars/:CarID/drives/:DriveID
  • PUT /api/v1/cars/:CarID/logging/:Command
  • GET /api/v1/cars/:CarID/logging
  • GET /api/v1/cars/:CarID/status
  • GET /api/v1/cars/:CarID/updates
  • POST /api/v1/cars/:CarID/wake_up
  • GET /api/v1/globalsettings
  • GET /api/ping

Authentication

If you want to use command or logging endpoints such as /api/v1/cars/:CarID/command/:Command, /api/v1/cars/:CarID/wake_up, or /api/v1/cars/:CarID/logging/:Command you need to add authentication to your request.

You need to specify a token yourself (called API_TOKEN) in the environment variables file, to set it. The token has the requirement to be a minimum of 32 characters long.

There are two options available for authentication to be done.

  1. Adding extra header Authorization: Bearer <token> to your request. (recommended option)

  2. Adding URI parameter ?token=<token> to the endpoint you try to reach. (not a good option)

* Note: If you use the second option and your logs get compromised, your token will be leaked.

Commands

Commands are not enabled by default.

You need to enable them in your environment variables (with ENABLE_COMMANDS=true) and you need to specify which commands you want to use as well.

There are 3 ways of using Commands:

  1. Specific groups of commands can be enabled for example COMMANDS_ALERT=true will enable the alert commands group.

  2. If you need a granular set of commands enabled COMMANDS_ALLOWLIST=/path/to/allow_list.json can be used to specify a JSON formatted list of commands to enable.

  3. The most coarse option COMMANDS_ALL=true will enable all commands (specific groups and allow_list will be ignored).

* Note: if COMMANDS_ALL or any specific group of commands has been enabled COMMANDS_ALLOWLIST is ignored.

A list of possible commands can be found under environment variables.

Regarding what fields you need to provide in the commands, we will referr to the timdorr/tesla-api documentation.

Security information

There is no possibility to get access to your Tesla account tokens by this API and we'll keep it this way!

The data that is accessible is data like the cars, charges, drives, current status, updates and global settings.

Also, apply some authentication on your webserver in front of the container, so your data is not unprotected and too exposed. In the example above, we use the same .htpasswd file as used by TeslaMate.

If you have applied a level of authentication in front of the container API_TOKEN_DISABLE=true will allow commands without requiring the header or uri token value. But even then it's always rekommended to use an apikey.

Credits

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].