Simple Python class to access the Tesla JSON API
Project description
teslajson
Simple Python class to access the Tesla JSON API.
Written by Greg Glockner
Description
This is a simple Python interface to the Tesla JSON API. With this, you can query your vehicle, control charge settings, turn on the air conditioning, and more. You can also embed this into other programs to automate these controls.
The class is designed to be simple. You initialize a Connection object, retrieve the list of Vehicle objects, then perform get/set methods on a Vehicle. There is a single get method [Vehicle.data_request()] and a single set method [Vehicle.command()] so that the class does not require changes when there are minor updates to the underlying JSON API.
This has been tested with Python 3.7 and requires the Requests-OAuthlib library.
Installation
Use any of these methods to download and install the teslajson module:
- Easiest method: use pip via the command :
pip install teslajson
- Download the source code from https://github.com/gglockner/teslajson, then run:
python setup.py install
- Download the source code, install requests-oauthlib and its dependencies, then add the file teslajson/teslajson.py to your Python project
Public API
Connection(email, password, **kwargs)
:
Initialize the connection to the Tesla Motors website.
Required parameters:
- email: your login for teslamotors.com
- password: your password for teslamotors.com
Optional parameters:
- mfa: your multi-factor authentication code, if enabled on your account
- mfa_id: if you have multiple MFA devices, the UUID for the MFA device you want to use
- **kwargs: arguments passed to the Requests objects
Connection.vehicles
: A list of Vehicle objects, corresponding to the
vehicles associated with your account on teslamotors.com.
Vehicle
: The vehicle class is a subclass of a Python dictionary
(dict). A Vehicle object contains fields that identify your
vehicle, such as the Vehicle Identification Number (Vehicle['vin']).
All standard dictionary methods are supported.
Vehicle.wake_up()
: Wake the vehicle.
Vehicle.data_request(name)
: Retrieve data values specified by name, such
as charge_state, climate_state, vehicle_state. Returns a
dictionary (dict). For a full list of name values, see the GET
commands in the Tesla JSON API.
Vehicle.command(name)
: Execute the command specified by name, such
as charge_port_door_open, charge_max_range. Returns a
dictionary (dict). For a full list of name values, see the POST commands
in the Tesla JSON API.
Example
import teslajson
c = teslajson.Connection('youremail', 'yourpassword')
v = c.vehicles[0]
v.wake_up()
v.data_request('charge_state')
v.command('charge_start')
Credits
Many thanks to Tim Dorr for documenting the Tesla JSON API. This would not be possible without his work.
Disclaimer
This software is provided as-is. This software is not supported by or endorsed by Tesla. It was developed via reverse-engineering of an unpublished JSON API. Tesla does not publicly support the underlying JSON API, so this software may stop working at any time. The author makes no guarantee to release an updated version to fix any incompatibilities.
Changelog
Version 2.0
- Rewritten with Requests library, in order to support the latest Tesla authentication protocol
- Packaged via PyPI (pip)
Version 1.3
- Removed API and baseurl from constructor; added proxy support
Version 1.2
- Refactored to keep sessions persistent and refresh according to the values returned by the server
Version 1.1
- Remove hard-coded client_id and client_secret; read them from pastebin instead
Version 1.0
- Initial release
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file teslajson-2.0.0.tar.gz
.
File metadata
- Download URL: teslajson-2.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c9be5e6eadb5386a5c5dcf094d22327233d0aeaf079d1e3fb00798567345d42 |
|
MD5 | 24d01842be56e743d4bbcf739f4839bb |
|
BLAKE2b-256 | c49a62b2ecac348ecd34c6629b1c71c3e6c97dbef1e7d82bdc2e5efa20588796 |
File details
Details for the file teslajson-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: teslajson-2.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62ca8b124c1f16b654eee2fadf7eb9a8305dc0d9aa03a41ddf2657e43c7e00aa |
|
MD5 | 114a9e3e12c4992831690b2bd1aced9d |
|
BLAKE2b-256 | ec0d4c3725ef630213a13a821ba1e6a9c1de00cab9d6052623b850eb96ada597 |