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.
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.
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
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.
Open up Tasker and make sure you’re in the
PROFILES tab, then select the plus icon to create a new profile. Select
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
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”.
Now you can go back to the main Tasker screen and create another profile but this time replace
Off. After you’ve done that go to the main screen again and select the menu button at the top then
Save first to make sure everything is saved properly.
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/