Did you know that you can enjoy many members-only features simply by quickly registering (no CAPTCHA!)?
Registering gives you access to our giveaways, forum features, increased search performance, access to our Download Library, create your own blog & gallery, and more!
Once you have registered, stop by in 'Hello World', and introduce yourself.
Categories See All →
Jumping from SQ Blaster to On Controls for remote control.
bucko - Sep 04 2014 06:40 PM
Controlling Your Home Automation Controller with TaskerAndroid Remote
- Turn WiFi of when you arrive at home.
- remind you every 60 seconds that you missed an important call, while turning the ringer volume up every time it reminds you.
- Save your battery by turning the screen brightness down at night (or whenever you put your house into night mode, tutorial coming soon!)
- Automatically back up your phone when connected to your home network
- Announce SMS/E-mail messages using TTS when driving.
- Start music playback as soon as you get into your car.
Now that Tasker has repeatedly been mentioned in a home automation context, I thought it was time to create a simple tutorial showing how you can create a widget to execute a simple automation task, or turn on/off a device such as your lights, using the built-in web server of your home automation controller.
Tasker can emulate a web browser in order to retrieve data. This is the feature we will be using for this tutorial. I will show you how you can figure out the correct commands you have to send, in case you have a home automation controller with an undocumented web server, or are trying to do something which no one else has tried before.
There are 3 major steps to this process:
- Learn: We need to figure out what command is sent whenever we click that 'on' button when accessing the home automation controller webserver.
- Create: We need to create a task in Tasker, and link it to a widget, using the data we learned in step 1.
- Execute: We now should be able to control the light/event/task by pushing the Widget installed on your Android desktop.
- A home automation controller with web services enabled (such as HomeSeer, CQC, Vera, etc.).
- Tasker. I'm going to assume you are already familiar with this app, if you aren't, feel free to ask for more help in the comments section, or use your favorite search engine to find the many Tasker tutorials. There is a trial version, and the screenshots should offer plenty of assistance with helping you start from scratch.
- Access to the network which is running the web server. Do NOT expose your home automation server to the internet, especially for this tutorial. I will create another guide soon, covering multiple ways of securely controlling your setup while not at home.
- If possible, create a separate account for use with Tasker only. This makes it easier to kill remote access should the account become compromised, and might help with troubleshooting any problems.
In order to figure out what URL & data is sent whenever you activate a light/task via your home automation web server, we need to monitor these requests coming from your browser. But before that, I need to quickly explain (in a simplified way) the types of requests your browser sends to a web server. There are 2 types/methods, and in this example, let's assume we are trying to control a light with an ID # of 4, and we are trying to turn it on. The URL is the string found in the address bar of your browser.
- GET: The browser sends any variables as part of the URL.
Example: http ://127.0.0.1/control.php?light=4&action=on
This is a fictional example which controls a light with ID # 4, and turns it on. Extremely simple, and if this is how your home automation system works, simply save the URL you see once you click the on/off button, and you can move on to the next step.
- POST: The browser sends the variables in the background.
Example: http ://127.0.0.1/control.php
As you can tell, the variables are not visible to the casual observer. A POST command is a little bit more secure, because your browser caches URLs (and appended variables). This is also the reason that almost every site relies on POST for authentication, so your credentials won't be exposed via the browser history, or proxy servers logging URLs. Imagine if your bank used ://my.bankurl.com/givememoney.php?user=john&pass=foobar. This would obviously get ugly really fast. POST requests are also not cached, and aren't restricted in length, while the length of a URL (GET) is limited.
If your web server relies on GET for control, just note the URL and proceed to the next step. If your web server uses POST, then we need to install a tool which can display the variables we are sending to the web server whenever we activate a light/task.
To make this process easy, I recommend you install Fiddler, which is a web debugging proxy, and should work with your preferred browser. There are other tools, such as Tamper Data, Firebug & Live HTTP Headers for FireFox, or Chrome's internal Developer Tools (use F12 to activate). In order to keep this tutorial browser-agnostic and simple, I will be using Fiddler to capture the POST data, and HomeSeer as my home automation controller, but the concept is the same for any other home automation controller.
Start up the Fiddler software, wait for it to finish loading, and proceed with activating a task/device via the web interface.
Fiddler logs all data your web browser sends out and receives, so you should be able to catch the POST data, including the required variables. Just pay attention to the URL you see in your browser's address bar, and look for the server address and path in the Fiddler window (Inspectors > WebForms tab).
The screenshots below show the data transmitted when I issued the ON command, an OFF command, and when I executed an event via the HomeSeer web server.
Once you have this data, you can move on to the next step, where we will create a Tasker task & widget. If you have problems with this step, don't hesitate to post in the comments below.
Note: The Rover plugin for Homeseer uses the GET method, so if you want to skip the 'difficult' part, just point your Tasker widget to the Rover plugin instead.
It's now time to create the Tasker task & widget. Let's start with the task, as the widget is just a shortcut which points to this task.
- Select the 'Tasks' tab on your Tasker screen.
- Add a task by clicking the green + symbol.
- Enter a name. Keep in mind that this is the name which will appear under the icon on your Android home screen. For this tutorial, I am entering 'LightOn'.
- You should now be in the Action screen.
- Since a widget requires an icon, let's select an icon for this task by clicking the last button at the bottm, next to the 'tools icon', and above the icon with the play button.
- We now have to add an action to this task. Select the button with the blue plus symbol.
- We are looking for the HTTP Get or HTTP Post action, which can be found in the 'Net' category.
- If your home automation controller uses GET, then select HTTP Get, otherwise, select HTTP Post. For this tutorial, I am selecting HTTP Post, but I will include an HTTP Get example in the screenshots.
- You should now be seeing the screen which allows you to configure the HTTP Post parameters.
- Under 'Server:Port', specify the credentials and IP address of your server. Example: http ://user:[email protected]
- Under 'Path', specify the rest of the URL as you see it in your browser. In this example, I will specify '/stif' as this is what HomeSeer uses.
- 'Data/File' are the variables you want to send to the server. In this HomeSeer based example, we need to send the device ID, and the type of action, both variables can be found with Fiddler in the previous step. I also included an example for the OFF command, and an event execution in the screenshots below. The variables we are adding are:
- You don't have to fill out any of the other fields, unless you want to process the server response, or adjust other connectivity parameters.
- That's it! Use the green check mark button to save your work. I also recommend you test the action by pressing the button with the blue play symbol. This will verify the tasks works before we move to the next step.
All we have to do now is create the widget (a clickable icon in the Android world) now that we have created the task.
There are 2 types of Android Tasker widgets: 'Widget' and 'Shortcut'. For more information about the differences, check out the Tasker site. In this tutorial, I am going to select the standard shortcut (Task Cut).
Add a widget via the Android Widget screen (sometimes, you can press & hold on the home screen to activate this screen, or in the newer Android releases, go to the screen which lists your applications, and select the 'WIDGETS' tab on top.
- Select the 'Task Cut' widget.
- A 'Task Selection' windows should now appear, and list all the tasks you have defined. Select the task we created earlier, 'LightOn' in my example.
- Once selected, you should now see the actions associated with your task. Confirm the details by pressing the button with the green check mark.
- That's it. You should now see an icon on your home screen.
Tapping the icon should activate the task you defined earlier. I highly recommend you put these widgets in a 'folder' on your home screen, to avoid accidental activation, plus it gives you quick access to all your home automation widgets.
This is an extremely simple example of how to interact with your home automation system. You could take it a step further now, and process the web server response, or change the widget icon based on the state of the device.
You could use this widget to open your garage door (do this via an event, so you can do some safety checks, etc.), turn on your outside lights, reboot your cable modem or internet router, anything you can think of, as long as it comes with a web server.
As mentioned earlier, you really shouldn't expose your web server directly to the internet. I will publish a guide soon which will show several ways of accessing your system remotely, in a more secure fashion.
If you have any questions or comments, post them below, I will answer them as soon as possible.
In an attempt to make this process easier, I would like to ask the community to share the 'Path' and a 'Data' example for their home automation controller if it isn't covered by this tutorial already (host/port isn't needed). Whenever someone posts a new Path/Data in the comments, I will add it to this article (with proper credit if desired). This should make it really easy for anyone to get this working without having to analyze the HTTP Post data.
Dynamic data (such as the ID of a device) is underlined, make sure to replace this with the actual value. Only data in green should be added to your Tasker Action.
HomeSeer (2.x) - Control Device
HomeSeer (2.x) - Execute Event