Activating Tasker tasks from Home Assistant using command line switches

![](upload://d64K8CZUBz6iLj8kmjsoOkWZCrR.png) In this tutorial I will explain how you can activate Tasker tasks from Home Assistant command line switches. We are going to set up a switch that when toggled will make your Android device say either “On” or “Off”.

You could also do this with the automation component instead so whenever you put your house to sleep mode for example your Android device will open up Google Play Books or the Kindle app ready for you to read as well as dimming your lights, but this tutorial is all about the switches.

AutoRemote URL

First things first you should install Tasker and AutoRemote onto your Android device and launch AutoRemote. You should see a URL above the QR code, visit it in your browser and it should bring up a page a bit like this.

![](upload://rEEb04OgbdGak2ZY1wvp5oxIAGU.png)

Now type in SayOn in the Message box and you should see a box appear on the right with a URL in it, this is what we will be using in the Python script later on so save that for later. Do the same thing again but this time replace SayOn with SayOff. Now just click the Send message now! button to test that your commands will get sent to your Android device, if they do you will see a toast message at the bottom of your screen like this one.

![](upload://3Ad1DkR8yJGyrUwYG3FBlQQij5P.png)

Tasker Setup

Open up Tasker and make sure you’re in the PROFILES tab, then select the plus icon to create a new profile. Select Event -> Plugin -> AutoRemote -> AutoRemote and then the pencil icon to configure the AutoRemote event. Select Message Filter and enter in SayOn then go back until it asks you for a task. Select New task then just leave the next field blank and select the tick icon. This is where we’ll configure our task, so select the plus icon to select an action. Select Alert -> Say to add a Say action. Enter On in the text field and go back to test your task, make sure your media volume is up then select the play icon, you should hear your device say “On”.

![](upload://r208Be9yWeMFkyoxymPmNmMtXhB.png)

Now you can go back to the main Tasker screen and create another profile but this time replace SayOn with SayOff and On with Off. After you’ve done that go to the main screen again and select the menu button at the top then Exit and Save first to make sure everything is saved properly.

Python Script

Now it’s time to set it up the script, so create a new Python script and name it On.py then enter this code:

import requests
requests.get('[URL]')

Enter in your “On” URL then save it. Create another script but this time call it Off.py and enter your “off” URL instead.

Home Assistant Configuration

Add a command line switch to your Home Assistant configuration:

switch:
  platform: command_switch
  switches:
    tasker_say:
      oncmd: python "[LocationOfOnScript]"
      offcmd: python "[LocationOfOffScript]"

Now load up Home Assistant and whenever you toggle the switch you created your Android device will respond with either “On” or “Off”. :-)


This is a companion discussion topic for the original entry at https://home-assistant.io/blog/2015/12/10/activating-tasker-tasks-from-home-assistant-using-command-line-switches/
1 Like

Has any1 tried this? Were you successful?

I use autoremote to send my home assistant home/not_home status to my phone. I then use this to turn owntracks on or off.

Thank you for the insight.

i found that the Configuration.yaml did not work for me.
it seems HA updated the “command_switch” to “command_line

i used the following instead and it works

Configuration.yaml

switch:
  - platform: command_line
    switches:
      tasker_say:
        command_on: "[LocationOfOnScript]"
        command_off: "[LocationOfOffScript]"

Thanks for your guide.

Where does the Python Script go? Is that in Tasker, or Home Assistant? I looked in both but didn’t see a place to add it.