The following provides an example of how to use webCoRE to access the Tesla API.
The first piston (Updated 3/3/21 for compatibility with Tesla API v3) uses a Refresh Token that you provide to obtain and refresh (as needed) an access token used by the two example pistons that follow to access the API.
To use this piston, you will first have to obtain a Refresh Token from Tesla. I used a python script available here . I 'm sure there are other options I’m not familiar with. .
This piston, while functional, employs a somewhat clumsy workaround for a webCoRE bug that creates problems for pistons containing multiple POST statements, so a new global variable (type: Boolean) @tokenSwitch is needed.
See the instructions within the piston itself to get started.
If you have multiple vehicles, some modification of the first piston will be required to ensure the proper Vehicle IDs are stored. I’ll try to address that in the next iteration.
Please note: if you are using TeslaFi or another third-party service that maintains the access token, do not use this piston. You will have to manually update the value of @accessToken each time those services refresh your access token. (That should occur approximately every 45 days).
The second piston will run successfully via the TEST button ONLY AFTER the first piston has been run successfully and your credentials have been stored in the global variables you created. The piston provides examples of the methodology for accessing the API and parsing the responses.
Whatever trigger you use to activate the pistons you develop from this information, remember that waking the car uses the battery. The usage is small, but waking the car too often could impact your range.
Here’s a simple climate control piston. (Again, click TEST to execute)
Of course these are only examples. More data and more commands are available for those interested in developing their own pistons. For more information on the Tesla API see: https://www.teslaapi.io/ or https://tesla-api.timdorr.com/
Let me know if you find this useful. Good luck!
Edited 12/14/18: Updated original text and piston to focus exclusively on how to access the API and the proper method of parsing the JSON response.
Edited 4/18/20: Updated example pistons to work with multiple vehicles on a single Tesla account.
Edited 4/21/20: Added example of a simple climate control piston.
Edited 3/3/21: Updated First Piston for Compatibility with Tesla API v3 Authentication
Edited 3/4/21: Tweaked First Piston