⚙️ Using Tasker with Home Assistant (V2)

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 ! :rocket:

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.

Token

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, or http://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: use Cut + Paste instead of Copy + 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


imageimage

Method 2 - Download and import

If you cannot import the tasks using method 1, here is an alternative method

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 :mag: 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 ! :+1:

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 :mag: 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 :+1:

85 Likes

Is it possible you could do a tutorial on how to add tiles in the notification bar? This way we could press a say light bulb icon to turn it on or off via home assistant?

Sure !
Here is how to do that:

  1. Open the top-right menu in Tasker and click “Preferences”
  2. In the “Monitor” tab, activate the “Notification Action Buttons” and choose up to 3 tasks
  3. Close Tasker to apply

2 Likes

thanks for this.

how about on the notification tiles? I guess you have to use AutoNotification for that?

Oh, I think I misunderstood what you were talking about!

  1. Open the top-right menu in Tasker and click “Preferences”
  2. In the “Action” tab, go to “Quick Settings Tasks” and choose up to 3 tasks
  3. Close Tasker to apply
  4. New tiles will be available

image image

Is it what you call “notification tiles”?

1 Like

yeah thats it but i thought you need to use autonotification?

Nope, no additional modules / apps are needed

2 Likes

So I get this error using the HA call service task:

Any idea?

Thanks.

You should have a detailed error in your notifications

HA call-service is meant to be called from another task using the “Perform Task” action, not directly… :confused:

All the instructions on how to do this are in the tutorial above, but I guess it’s not clear enough

Ok makes sense managed to get it working thanks. On to the notification tile now using toggle. Thanks

1 Like

Ok managed to add it on the notification tiles. However 1. I need it to report the state of my light.
2. I need to make a toggle task so just display one task for example “light” in the notification tile section on my phone. I guess this can be achieved via an if statement?

Hi can i send information from tasker to HA?

Well, yeah, by calling a service !

You can read more about service calls here

How can I send phone wifi status?
Like this: %HA_ADDR/api/states/sensor.phoneblue?api_password=

Seriously man, just read the documentation and the tutorial before spamming…
.
You just need to figure out 2 things:

  • A service name
  • Service data

Then apply the step 4.1 of the tutorial

Maybe the Developper tools > Services page of your Home Assistant will help your figure out these 2 things

2 Likes

@bokub any idea mate?

Thanks for the updated tutorial! When Tasker added support for proper HTTP headers it really made this a lot easier.
I use PebbleTasker to run tasks from my watch and my favourite implementation is to control my garage door this way :blush:

I just noticed, there is now a Home Assistant Tasker plug-in in the play store, including autocompletion of services and entites. It makes calls to Home Assistant from tasker really easy

6 Likes

How may I Trigger an Automation via Tasker? I can run a scene or turn on/off a device, but how may I Trigger an Automation? Would this be a rest url > Trigger/Service or Event?

Edit: I created and called a script instead of an automation; like executing a Task in Tasker.

Yeah, a script is a good solution, or you can call the automation.trigger service if you need to keep it as an automation

1 Like