# Tesla Automation Thread



## eXntrc (Jan 14, 2019)

I would like to use this thread as a place to collect valuable apps, scripts and tools we've found to automate our Teslas. Whenever a post gathers a lot of interest it will get linked to here at the top. That way the most popular automations will be easy to find, no matter how long the thread gets.

There are many different ways to automate our Teslas and each option requires a varying degree of effort. For simplicity, I've chosen to group automations into one the following categories:

*Built-In*

These automations are built-in and are easy to find. There are very few options in this category, but the ones that are included are still quite valuable. In this category I include things like:


Precondition the vehicle using the Tesla app, even when we're not in the car.

*Prebuilt*

These automations are easy to use but you need to know where to find them. You'll find more options in this category, and they too are valuable, but we're still limited to the capabilities that each developer chooses to provide in their app. In this category I include things like:


Using TeslaFi to remotely set a charge level
Using My Tesla to ask how far we can drive
Using Wear for Tesla or Commands for Tesla to unlock the car or honk the horn from a watch

*Some Code Required*

This is where we start to see of the most unique and often most valuable automations. While extra effort is required, the learning curve tends to not be as bad as it initially seems and the rewards usually outweigh the challenges. Examples in this category include:


iOS Shortcuts* - *An scripting system that can control many things, Tesla being one of them. There's already an extensive thread on this tool here in the forums.
Auto HVAC - Automatically heat or cool the car based on the temperature outside.
Drive Mode - Automatically start Spotify, Waze and voice texting simply by getting in the vehicle. Shut them down when you leave too.
Auto Navigate - Synchronize Tesla navigation with Waze on the phone. Navigate to destinations automatically based on the time of day.

I will post sample scripts shortly for the automations I've listed above. In the meantime, what tools do you use to automate your Tesla?


----------



## eXntrc (Jan 14, 2019)

*Auto HVAC*

About






This automation uses Tasker to automatically heat or cool the vehicle based on the current temperature outside.

For this to automation to work you'll need:

Tasker
Tesla Plugin for Tasker
Weather ACE
Weather ACE Plugin for Tasker
To make it easier to understand and maintain, this script was split into 3 parts which you can download here:

Tesla - HVAC Cool
Tesla - HVAC Heat
Tesla - HVAC Auto
*IMPORTANT 1*: Install Tasker on your phone first, then click those links above on your phone to automatically import the scripts into Tasker.
*IMPORTANT 2*: The scripts above use a variable called %TeslaName to know the name of your vehicle. You must create this variable and set it to your own vehicle name before these scripts will work. This video shows you how:

How to set Tasker Vars

Installation

Install the software listed above including Tasker
Import the 3 tasks linked above
Run Weather ACE at least once to configure your location
Set your vehicle name in the %TeslaName variable (see video above)
_(Optional)_ Add the *Tesla - HVAC Auto* command to your notification center using *Tasker -> Preferences -> Notification Action Buttons*

Code Walk Through

Here's a walk through of how these scripts work. First, let's take a look at *HVAC - Heat*.

*







*


Use Text-To-Speech to say "Heating <Car Name>".
Flash the same text we're speaking on the screen.
Use the Tesla plugin for Tasker to actually set the temperature in the car. (I set it to 74 but you can easily change it to whatever you find comfortable).
Use the same plugin to turn on the seat heater (I only turn it on for the driver but you can easily change it).
When the Tesla plugin completes (meaning the car has accepted the command), say and show "<Car Name> is heating".

*HVAC - Cool* is very similar










The last part is the magic that chooses which one to run. That's handled by *HVAC - Auto*:










I chose Weather ACE because it's super easy to use within Tasker. You _do_ need to have the Weather ACE app installed on your phone and you need to run it at least once to select your location. After that you never have to run the app again, but I rather like the interface.

Finally, notice that if the temperature is already in a comfortable range neither Heat or AC get run. Instead it simply says "Climate is already comfortable".


----------



## MelindaV (Apr 2, 2016)

eXntrc said:


> I would like to use this thread as a place to collect valuable apps, scripts and tools we've found to automate our Teslas. Whenever a post gathers a lot of interest it will get linked to here at the top. That way the most popular automations will be easy to find, no matter how long the thread gets.
> 
> There are many different ways to automate our Teslas and each option requires a varying degree of effort. For simplicity, I've chosen to group automations into one the following categories:
> 
> ...


don't forget Siri Shortcuts with an extensive thread already


----------



## eXntrc (Jan 14, 2019)

MelindaV said:


> don't forget Siri Shortcuts with an extensive thread already


Awesome. Thank you @MelindaV, I'll add a link directly to that thread.


----------



## eXntrc (Jan 14, 2019)

*Drive Mode*

About






More Tesla automation using Tasker. This time, "Drive Mode".

When the user enters the vehicle:

Spotify starts (if it wasn't already running)
Spotify resumes playback
A hands-free texting app called Drivemode is started
Waze automatically opens

When the user exits the vehicle:

Spotify is paused
Waze closes
Drivemode shuts down

For this to automation work you'll need:

Tasker
Spotify
Waze
Drivemode

This script is split into two parts which can be downloaded here:

Drive Begin
Drive End

*IMPORTANT 1*: Install Tasker on your phone first, then click those links above on your phone to automatically import the scripts into Tasker.

Installation

Install the software listed above including Tasker
Import the 2 Tasks linked above
Trigger *Drive Begin* to run when the vehicles Bluetooth connects.
Trigger *Drive End* to run when the vehicles Bluetooth disconnects.

Code Walk Through

These two scripts are heavily self-commented using Taskers 'Label' feature. In the screenshots below, look at the dark grey bars to understand what's happening at that line.

Drive Begin:










Drive End:










The %AutoNav variable on Line 1 is used for AutoNav, which I'll be posting about soon.

Interestingly Android doesn't allow apps to 'kill' other apps unless your phone is rooted. This is why I'm not using the Tasker 'kill' command to close Waze. Instead we have to send an Android intent that Waze is listening for and will shut down when the intent is received.

The final piece is getting these two tasks to run at the right time. In Tasker we do this on the first tab in the app: *Profiles*.


Make sure your phone has already been paired with the car.
In Tasker, on the *Profiles* tab tap the + button at the bottom of the screen.
Tap on the *State* trigger
Tap on the *Net* state
Tap on *BT Connected*
Next to the *Name* field, tap the magnifying glass then choose "Tesla Model 3" (or whatever your Tesla is named)
Tap the Android Back arrow
A task list pops up. Choose the *Drive Begin* task.

Here's what it looks like when configured correctly:










For *Drive End* the steps are the same but we need to INVERT the Bluetooth connection.


Make sure your phone has already been paired with the car.
In Tasker, on the *Profiles* tab tap the + button at the bottom of the screen.
Tap on the *State* trigger
Tap on the *Net* state
Tap on *BT Connected*
Next to the *Name* field, tap the magnifying glass then choose "Tesla Model 3" (or whatever your Tesla is named)
*CHECK THE INVERT CHECKBOX*
Tap the Android Back arrow
A task list pops up. Choose the *Drive End* task.

Here's what it looks like when configured correctly:










That's it. Everything should run automatically whenever you enter or exit the car.


----------



## eXntrc (Jan 14, 2019)

*Auto Nav*

About






This time we'll use Tasker to route the Tesla navigation and Waze on the phone to the same destination at the same time. Even better, we can do the routing automatically just by getting in the car at a certain time of day.

For this to work you'll need:


Tasker
Tesla Plugin for Tasker
Waze

This is all accomplished using a single script, which you can download here:

Tesla - Auto Nav

An example of how to call this script can be downloaded here:

Nav Home

*IMPORTANT 1*: The address must be fully qualified including City, State and Zip (in the US). Favorite names do not work due to a limitation of the Tesla navigation API.

*IMPORTANT 2*: The 'Auto Nav' script uses several variables. Those variables are described below and you must create these variables before the script will work. This video shows you how:

How to set Tasker Vars

Installation

Install the software listed above including Tasker
Import the *Tesla - Auto Nav* Task linked above
(Recommended) Import the *Nav Home* Task linked above
Set your vehicle name in the *%TeslaName* variable (see video above)
Set your home address in the *%HomeAddress* variable (see video above)
Set the *%NavPromptTimeout* variable to the number of seconds you'd like to wait for the user to confirm navigation before it's automatically cancelled
Set the *%NavPromptWait* variable to the number of seconds you'd like to wait _after the car is started_ before the user is prompted for navigation (this can be zero seconds)
_(Optional)_ Add the *Nav Home* Task to your notification center using *Tasker -> Preferences -> Notification Action Buttons*

Below is a photo of what the variables look like after they've been configured. *%NavConfirm* and *%NavAddress* may change each time, but the other variables are usually only set once.










Code Walk Through

The main guts of the automation are in the *Tesla - Auto Nav* script, but something needs to tell Auto Nav where to route. That's where the *%NavConfirm* and *%NavAddress* variables come into play.

In fact, here's a picture of the *Nav Home* script, which basically just sets these variables.










Here we're setting *%NavAddress* to another variable *%HomeAddress.* But *%NavAddress* can be set to any fully formed address (including City, State and Zip). Unfortunately Tesla favorite names do not work due to a limitation of their API.

After the variables are set, we simply call *Tesla - Auto Nav* to do the work. Let's take a look at that script:










This is a little long, but basically what we do is speak the confirmation prompt and show the user a Yes / No menu.

If the user selects Yes, we send the address on to Tesla using the Tesla plugin and send the same address to Waze using an Intent that Waze is listening for.

If the user selects No, we just speak the words "Navigation canceled".

Finally, we set a variable *%AutoNavResult* to either true or false in case some other script wants to know what the user chose.

This last part is optional but it's super powerful. As we showed in the Drive Mode automation, we can have tasks run automatically whenever the user gets in the car. We can also add conditions like "but only on these days" and "only during these times". With this in place you can set the car to automatically navigate to common destinations simply by getting in the car.

Here's an example:


----------

