Hi everyone !
A year ago, I posted a tutorial showing how to use Tasker with Home Assistant.
After more that 10 thousands views, I’ve decided to update the tutorial so it’s easier to follow, with better screenshots and better ways to identify problems
It also uses new features of Tasker, such as HTTP headers.
Let’s get started !
1. Create a token
First of all, go the the “Long-Lived Access Tokens” section at the bottom of the Profile page of your Home Assistant. This page can be accessed by clicking on your name, at the bottom of the main menu
Create a new token, and keep the token value somewhere for step 2.
2. Create variables
In the VARS tab of tasker, create 2 new variables:
-
HA_ADDR
is the address of your home-assistant instance
Add the port if there is one, and no trailing slash
Examples:https://my-ha.duckdns.org:8123
, orhttp://111.222.33.44
-
HA_TOKEN
is the token you created in step 1.
Be sure to copy the whole token! It’s easy to miss a piece if you’re using your mobile
Pro tip: useCut + Paste
instead ofCopy + Paste
to be sure you have everything
3. Import generic tasks
I’ve created two generic tasks called HA call-service
and HA template
, which you will import in Tasker. There are two ways do to that
Method 1 - Using Tasker Share
Just click on the following links with your mobile device and follow the instructions
Method 2 - Download and import
If you cannot import the tasks using method 1, here is an alternative method
- Download the tasks HA call-service and HA template
- Save them to your mobile device
For each one of the files:
- Click on the TASKS tab in tasker
- Click “Import Task”
- Select the file you downloaded
4. Create your own tasks
Part 1 - Calling a service
In this first part, I’ll show you how to call a service from Tasker, in order to interact with your integrations (i.e send data / trigger things)
If you’re not familiar with Home Assistant services, I suggest you go to the Developper tools > Services page of your Home Assistant and try doing things first. You can also check out the documentation
The first thing you need to do is creating a new task
When it’s done, add a new action, choose the Perform Task Action, and fill the following fields:
-
In the
Name
field, write “HA call-service”
That’s the generic task you imported in step 3
You can use the icon to find it -
In the
Priority
field, leave%priority
Don’t change it unless you know what you’re doing -
In
%par1
, write the name of the service to call
Example:light.turn_on
-
In
%par2
, write the service data
The data format should be JSON, not YAML! Here is a converter if you need one
Example:{ "entity_id": "light.example_light", "brightness": 255 }
That’s it !
If your task raises an error, the details should be visible in the notifications
At the end, your new task should look like the screenshots below
Part 2 - Retrieving data from Home Assistant
In this second part, I’ll show you how to retrieve data using the Template syntax
If you’re not familiar with Templates, I suggest you go to the Developper tools > Template page of your Home Assistant, or that you read the documentation
The first thing you need to do is creating a new task
When it’s done, add a new action, choose the Perform Task Action, and fill the following fields:
-
In the
Name
field, write “HA template”
That’s the generic task you imported in step 3
You can use the icon to find it -
In the
Priority
field, leave%priority
Don’t change it unless you know what you’re doing -
In
%par1
, write the template of your choice
I suggest you test it first in the Developper tools > Template page
Example:Temperature is {{ states("sensor.temperature") }} °C
-
Leave
%par2
empty -
In
Return Value Variable
, write a variable name of your choice, starting with%
Note: A lowercase variable can only be used in the current task, but you can also use global variables which are in uppercase
No-brainer example:%result
The result of your template will be available in the variable you created (%result
in my example)
You can do whatever you want with it, for example display it in a flash (see screenshot below)
If your task raises an error, the details should be visible in the notifications
That’s it!
I sincerely hope my tutorial will help as many people as the first one did
Don’t hesitate to share your feedback, your examples, or your ideas of improvement!
Have fun