2017 © Pedro Peláez
 

library tesla-php-client

A PHP Client for the Tesla API

image

stephangroen/tesla-php-client

A PHP Client for the Tesla API

  • Tuesday, May 30, 2017
  • by stephangroen
  • Repository
  • 2 Watchers
  • 4 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 13 % Grown

The README.md

tesla-php-client

A PHP client for easy integration of the Tesla API, (*1)

This client is very basic, so most changes to the Tesla API will automatically be accomodated for. You can find the docs of the API at https://tesla-api.timdorr.com/, (*2)

Installation

This project can easily be installed through Composer., (*3)

composer require stephangroen/tesla-php-client

One-time authentication process

Before you can start, you will first need to get an access token. This is a one-time process. Fortunatly the client makes this very simple. Get the client_id and client_secret here: http://pastebin.com/fX6ejAHd. You need to add them to you environment via a .env file in your existing project or use the functions supplied by the client. You need your email address and password you use for My Tesla. With these credentials you can get the access token., (*4)

$tesla = new StephanGroen\Tesla\Tesla();
$tesla->setClientId('client_id_here');
$tesla->setClientSecret('client_secret_here');
$accessToken = $tesla->getAccessToken('your_username', 'your_password');

The access token is the only authentication token you need after this one-time process., (*5)

Use the client

Next time you'd like to use the client, initiate it with the access token:, (*6)

$tesla = new StephanGroen\Tesla\Tesla('your_access_token');

Get and set your vehicle id

In order to execute vehicle specific calls, you need your vehicle id. Retrieve this by requesting all vehicles for your account:, (*7)

$tesla = new StephanGroen\Tesla\Tesla();
$tesla->vehicles();

This will return an array with information about your vehicles. Extract the id from the respone, not the vehicle_id which is used for Tesla internal purposes. You might want to store this id locally for future use. When you have the id, let the client know as follows:, (*8)

$tesla = new StephanGroen\Tesla\Tesla();
$tesla->setVehicleId(123);

Example call

Calls are very simple, read the source code and API docs to find out all available calls. For example, set the charge limit to 90 percent:, (*9)

$tesla = new StephanGroen\Tesla\Tesla('87dsfg76sdfg765sdfg765dsfg76fgds76');
$tesla->setVehicleId(123);
$tesla->setChargeLimit(90);

So, for every use you initiate the client and set the vehicle id to execute calls for., (*10)

Client response

All calls just return an array with the data as described in the API docs mentioned above., (*11)

408 responses

You might get some 408 responses when your vehicle still needs to wake up. Wait for a moment and try again., (*12)

The Versions

30/05 2017

dev-master

9999999-dev http://github.com/stephangroen/testla-php-client

A PHP Client for the Tesla API

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

api php tesla

30/05 2017

v0.2.1

0.2.1.0 http://github.com/stephangroen/testla-php-client

A PHP Client for the Tesla API

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

api php tesla

26/05 2017

v0.2.0

0.2.0.0 http://github.com/stephangroen/testla-php-client

A PHP Client for the Tesla API

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

api php tesla

22/12 2016

v0.1.0

0.1.0.0 http://github.com/stephangroen/testla-php-client

A PHP Client for the Tesla API

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

api php tesla