SkillAgentSearch skills...

Teslams

Tesla node.js apps and javascript libraries using Tesla's HTTP interfaces

Install / Use

/learn @hjespers/Teslams
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Tesla REST API

An implementation in Node.js of the client side interface to the Tesla API documented at:

https://tesla-api.timdorr.com/

This is unofficial documentation of the Tesla REST API used by the iOS and Android apps. It features functionality to monitor and control the remotely. Documentation is provided on the Apiary.io site linked above.

These programs and documentation do not come from Tesla Motors Inc.

Be careful when using these programs as they can lock and unlock your car as well as control various functions relating to the charging system, sun roof, lights, horn, and other subsystems of the car.

Be careful not to send your login and password to anyone other than Tesla or you are giving away the authentication details required to control your car.

Also ensure that you don't overwhelm the Tesla servers with requests. Calling REST APIs at very high frequency can put substantial load on the Tesla servers and might get your IP blocked by Tesla.

Disclaimer

Use these programs at your own risk. The authors do not guaranteed the proper functioning of these applications. This code attempts to use the same interfaces used by the official Tesla phone apps. However, it is possible that use of this code may cause unexpected damage for which nobody but you are responsible. Use of these functions can change the settings on your car and may have negative consequences such as (but not limited to) unlocking the doors, opening the sun roof, or reducing the available charge in the battery.

Contributors

Installation

To use these programs you must download and install node (eg from http://nodejs.org). Once node is installed, use the included npm utility to download and install the teslams tools and all its dependent modules.

npm install -g teslams

or if you are not logged in as root (administrator) use:

sudo npm install -g teslams

Alternatively, to run from github sources, clone teslams, go to the main folder and run

npm install

Authentication

All example programs require credentials to authenticate with the Tesla API. You can specify a config.json, format specified below, with $TSLA_CONFIG_FILE. This default location for the config file is ~/.teslams/config.json if not specified. It's highly recommended to use the token approach with a secure file location, see the next section for details.

{
	"username": "Your teslamotors.com username/email",
	"password": "Your teslamotors.com password"
}

Alternatively, the token can be passed via --token in order to reuse a pre-existing authentication token (and avoid using login and password). A 90 day token can be generated using teslacmd -u username -p password --print_token and you can store it for reuse in ~/.teslams/config.json in place of username and password in the following format:

{
	"token": "abc123abc123abc123abc123abc123abc123abc123"
}

Another alternative, username and password can be passed on the cli with -u and -p. Take care that no other users can access the system, as this will expose credentials in your history and process table ps -ax. The username and password can be passed as $TSLA_USERNAME and $TSLA_PASSWORD environment variables. These environment variable allow the execution of these apps in Heroku or other Platform-as-a-Service providers.

teslams.js - The main library (for javascript programmers)

Contains a library of functions and constants which allow the uses the TESLA "REST" API to get and set values on the Tesla. All functions take an optional callback that will be passed the javascript object returned from the TESLA API.

Function quick reference:

get_vid(opt, cb)               - get the "id" of the vehicle by logging into the Tesla portal
vehicles(opt, cb)              - login to portal and get vehicles list and options data
all(opt, cb)                   - get array of all vehicles (if more than one, we salute you!)
mobile_enabled(vid, cb)        - check is remote/mobile control is on or off
get_charge_state(vid, cb)      - get the full set of charge state information
get_climate_state(vid, cb)     - get the full set of climate state information
get_drive_state(vid, cb)       - get the full set of drive state information
get_vehicle_state(vid, cb)     - get the full set of vehicle state information
get_gui_settings(vid, cb)      - get the GUI setting
wake_up(vid, cb)               - wake up the communication with the car (if dormant)
open_charge_port(vid, cb)      - open the charge port door
charge_state({id, charge}, cb) - set the charging state
charge_range({id, range, percent}, cb) - set the range mode. See RANGE constants.
flash(vid, cb)                 - flash the headlights
honk(vid, cb)                  - honk the horn
door_lock({id, lock}, cb) .    - boolean toggle door locks
set_temperature({id, dtemp, ptemp}, vb) - set the driver and passenger temp
auto_conditioning({id, climate}, cb) - turn on/off the HVAC system. See CLIMATE constants
sun_roof({id, roof, percent}, cb) - control the sun roof. See roof constants
stream(opt, cb)                - low-level interface to streaming service
set_token(token)               - set the bearer token for authenticating using a previously generated token

Constants include:

CHARGE_OFF   - turns the charger off
CHARGE_ON    - turns the charger on
RANGE_STD    - set the charge mode to standard range
RANGE_MAX    - set the charge mode to maximum range
LOCK_OFF     - turns the door locks off (unlock)
LOCK_ON      - turns the door locks on (locked)
TEMP_HI      - highest temperature setting on climate control (32C/90F)
TEMP_LO      - the lowest temperature setting on climate control (17C/63F)
CLIMATE_OFF  - turns climate control off
CLIMATE_ON   - turns climate control on
ROOF_CLOSE   - closes the roof
ROOF_VENT    - puts the roof in vent position
ROOF_COMFORT - puts the roof in the 80% open position (for reduced noice)
ROOF_OPEN    - puts the roof in the 100% open position

teslacmd.js - Command Line Interface for all functions supported in the REST API

A sample command line application which uses the teslams.js library and takes command line arguments that allow all know REST API functions to be used.

To execute run:

teslacmd -u <username> -p <password>

For help run:

teslacmd --help

Usage: teslacmd.js -u <username> -p <password> OR --id <id_string> --token <bearer_token>
                   -acdDFgHimMPtvVwXZ
                   -A [on|off] -C [start|stop] -L [lock|unlock] -O <offset>
                   -R [std|max|50-90|100] -S [close|vent|comfort|open|0-100] -T <temp>
Options:
  -u, --username  Teslamotors.com login                                                       [required]
  -p, --password  Teslamotors.com password                                                    [required]
      --id        Vehicle id for the car you want to control                                  [required]
      --token     Teslamotors.com Bearer token (use --print_token to get a new token)         [required]
  -a, --all       Print info for all vehicle on the users account                             [boolean]
  -c              Display the charge state                                                    [boolean]
  -d, --drive     Display the drive state                                                     [boolean]
  -D, --debug     Display debug information                                                   [boolean]
  -F, --flash     Flash the car headlights                                                    [boolean]
  -g, --gui       Display the GUI settings                                                    [boolean]
  -H, --honk      Honk the car horn                                                           [boolean]
  -i, --info      Print vehicle info                                                          [boolean]
  -m, --mobile    Display the mobile state                                                    [boolean]
  -M, --metric    Convert measurements in metric unit                                         [boolean]
  -P, --port      Open charge port door                                                       [boolean]
  -t              Display the climate/temp state                                              [boolean]
  -v              Display the vehicle state                                                   [boolean]
  -V, --version   Print version of teslams software                                           [boolean]
  -w, --wake      Wake up the car telemetry                                                   [boolean]
  -X, --isplugged Check if car is plugged in and continue only if connected to a charger      [boolean]
  -Z, --isawake   Check if car is asleep and continue only if awake                           [boolean]
  -A, --climate   Turn the air conditioning and heating on/off
  -C, --charge    Turn the charging on/off
  -L, --lock      Lock/Unlock the car doors
  -O, --vehicle   Vehicle offset (i.e. 0 or 1) for accounts with multiple vehicles
  -R, --range     Charging range mode: "std" or "max" or any percent from 50-90 or 100
  -S, --roof      Move the car sunroof to: "close", "vent", "comfort", "open" or a

Related Skills

View on GitHub
GitHub Stars419
CategoryDevelopment
Updated1mo ago
Forks104

Languages

JavaScript

Security Score

95/100

Audited on Feb 4, 2026

No findings