Using Microsoft Power Automate to Connect to Tesla Vehicles

A topic that comes up more often than you expect at Regroove is Tesla! Sean, Regroove’s Chief Troublemaker, is…obsessed. Not without reason – Tesla produces some objectively cool cars that are helping to reduce greenhouse gas emissions.

The Regroove team made Sean’s Tesla even cooler by using Microsoft 365 processes to automate temperature control based on Outlook calendar appointments. In this article, we’ll tell you how!

What the Automation Does  

Simply put, the automation works to ensure that Sean’s Tesla is set to the perfect temperature when he’s getting ready to drive. Instead of using energy to keep the car consistently at his desired temperature, Sean’s car “reads” his Outlook calendar to look for an appointment titled “Comfy Car”. When “Comfy Car” is picked up in Outlook, a Microsoft Flow enables the car to adjust to the desired temperature. What a time to be alive.

We use Power Automate to interact with Tesla’s API

The Original Automation  

Originally, Sean wrote an article outlining how the automation worked, and how you too could implement it using Flow to talk to the Tesla API. To compare it to a hotel, the API functioned when you provided your name and an access code. In return you’d get a hotel key. If your session hadn’t expired, you could bypass the lobby and use your key to get into your hotel room.

Tesla decided that this type of security wasn’t optimal. For example, a bot could go up to the front desk and rattle off unlimited combinations of names and codes until it got a key (brute force) or take up all of the front desk’s time by inputting names and codes until no one else can request their own keys (denial-of-service).

Thus, Tesla modified their API and in turn, the automation our team had set up was out of date. Not to worry! Our talented team got the automation working again.

The New Automation  

Tesla updated their authentication process so instead of sending an email and password to the API in exchange for a token, the process emulates logging in. Tesla provided their “front desk” with better training to help spot bots and ensure the safety of security of their vehicles.

Our team took the Tesla API authentication process and made it work with Microsoft Power Automate. Power Automate doesn’t offer a Tesla connector out of the box, so to talk to the API you send a series of HTTP requests using the Tesla API. You can find those details in the unofficial documentation for the Tesla API.

You’ll need premium actions in Power Automate to make this work, which means you can’t accomplish this with a standard Microsoft 365 license or Power Automate Desktop. You’ll need a higher tier of licensing for the account that will process the automation.

You’ll begin the flow with an action you’d like to trigger the event, and by initializing all of your variables. These will be your access tokens, car ID, and anything relating to what you want to automate (car temperature, latitude and longitude, etc.).  

In cases where you need to take outputs from the API to use for something else, you can set up a condition to ensure the HTTP output is good and has the “if yes” branch to continue to flow. We also found the “if no” branch to be useful for setting email notifications that are sent to the car owner if an automation fails for any reason.

After that, you can parse the outputs into JSON using the Parse JSON connector, then set the results of the parsing as your token using the “Set Variable”. Choose the name of the variable you initialized previously and input the Parse JSON results (under “Dynamic Content”) as the value.

Once you’ve sent a GET request for the sign-in page, you need an Excel connection in order to plug in those outputs, which enable you to interact with Tesla’s hidden form data and the code from the redirects.

A Gotcha  

One very big “gotcha” we ran into – you can set Power Apps as a flow trigger and add premium connectors to your flow, run the flow from within Power Apps (in edit mode) and in Power Automate and have it function as expected. However, you won’t be able to publish the app and run it from there if you don’t have the correct licensing; it’s at this point Microsoft will implement its licensing rules.

Conclusion  

Our team at Regroove loves creating unique and useful automations, and we couldn’t resist plugging into the Tesla API and seeing how we could interact with the car via Microsoft 365. We’re nerds like that 🤓

Are you interested in implementing automations for your business or for your life? Get in touch with Regroove to see how we can help!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.