My name is Aaron Tinsley

An eclectic collection of thoughts and projects on a variety of (mostly) tech topics.

OpenHAB + Tasker: Use your Android phone to control your home

Nexus One!

Above (beautiful) photo of Nexus One by johncatral / Foter / CC BY-NC-ND

Update 2015-01-03: I’ve written a new post on this topic which can be found at this link.  The method used in the new post is simpler and doesn’t require the use of a 3rd-party app.

In this post, I’m going to give you an introduction to controlling your OpenHAB system using your Android phone. In this example, I’ll turn a lamp on and off using my phone.  How are we going to do this, you ask? We’re going to use a great app by the name of Tasker!

I first bought Tasker 2 or 3 years ago and have been coming up with new uses for it ever since. It’s probably the best 7 dollars I’ve ever spent on software, but you’re in luck! As of writing this post, it’s only 3 bucks! It’s well worth the price of admission.

Prerequisites

For the sake of this post, I’m going to assume that you already have your OpenHAB system installed with at least one device configured.  You’ll also need dynamic DNS set up so that you have a static hostname that always points to your home network, even if your IP address changes.  I recommend No-IP as a great free option for DDNS.

Make sure you’ve purchased Tasker and installed it on your phone.  You’ll also need to install the free RESTask for Tasker plugin.

The final step is that you’ll need to set up port forwarding on your router so that port 8443 is forwarded to your server which is running OpenHAB.  Port 8443 is the default OpenHAB port for communications, which means that all communication between your phone and OpenHAB system will be encrypted.

OpenHAB + Tasker Security

Hey! Security is important!
I’m a big believer in using the proper security with your home automation system from the very get-go.  Please do not ignore the security piece of this post!  It’s very easy to set up and it will protect you and your home automation system from all those evil ne’er-do-wells.

It’s very important to make sure all of  your traffic between OpenHAB and Tasker is encrypted.  To do this, we’ll need to download the SSL certificate from our OpenHAB system and place it on to your phone.  The easiest way to do this is by using your favorite browser!  I’ll walk you through the process using Chrome.

  1. Go to your PC which is running OpenHAB and navigate to https://127.0.0.1:8443/rest/items.  Chrome might balk and complain about the certificate being used, but click Advanced and then click proceed to 127.0.0.1.
  2. Click on the lock icon right next to the URL as shown below
    OpenHAB Local URL
  3. Once you’ve clicked on the lock, you’ll want to be on the “Connection” tab. Click on “Certificate Information”.
    Chrome Certificate Menu
  4. Go to the “Details” tab and click “Copy to File…”.
    Copy the OpenHAB Certificate to file
  5. Go through the Wizard.  Export as a DER encoded binary X.509.  Ignore my small obsession with Python and save the certificate as openhab.cer.
    Export the OpenHAB certificate Save the OpenHAB Certificate
  6. Move the openhab.cer file to your phone!  We’ll need it to make sure our traffic stays safe and encrypted.  Take note of the directory you’ve placed the certificate in.

Configuring Tasker

When opening Tasker for the first time, you might want to read the Help dialogs that come up.  They’ll provide you with a good overview of what you can accomplish using the app.  It goes far beyond home automation!

When you’re greeted by the main page of Tasker, you’ll want to go to the “TASKS” tab and click the big + sign on the bottom for a new task.  Put in a descriptive name.  In this case, it’s “Turn Lamp On”

Click the + sign to add a task

Click the + sign again on the next page to add a new Action.  Click on the Plugin category and then on RESTask.  If you don’t see it, you need to install the app!  Go to the top of this page under Prerequisites for the link.  If you still don’t see it, restart your phone and try again.

Tasker RESTask Plugin

When configuring the ResTASK part of our task, there are several things you’ll need to change to match your specific setup.  Here’s the list of what you should look at.  Leave everything else alone!

  • RESTask Settings
    • Settings Tab
      • Request Type => POST
      • Host => Your OpenHAB item URL (e.g. https://tinsley.no-ip.com:8443/rest/items/Light_Outdoor_Deck would control my deck light (Not really.  I’m not giving you my URL!))
        • Tip: Go to https://127.0.0.1:8443/rest/items on your OpenHAB PC to see all of your available items
      • Basic Auth => Your OpenHAB username and password, if needed.  You SHOULD have a username and password enabled!  Go here to learn how to configure authentication.
      • Enable custom body => checked
      • Custom body => ON
        • Tip: ON will turn the lamp on (obviously).  OFF will turn it off.
      • SSL certificate => checked
      • Certificate => I hope you remember where you saved openhab.cer from the Security section of this post!  Navigate to the folder and select it!
    • Headers Tab
      • Add a parameter with name Content-Type and value text/plain
    • Parameters Tab
      • No changes

When all your settings are correct, you can hit the Play button on the top right to test.  You should get a popup window with Return code: 201 and Return data empty!  At this point, you should be able to turn your lamp on or off by changing the Custom body field to ON or OFF.  Click the floppy disk icon on top to save the RESTask settings and then hit the Tasker icon in the top left twice.  You can follow the same steps again to create a Turn Lamp Off task so you can toggle the lamp on and off to your heart’s content!

Cool, huh?!?  As you become more familiar with Tasker and controlling OpenHAB with it, you’ll be able to do all sorts of cool things, including control your whole home with just your voice!  I guess that’s a topic for another post on another day, though :).

Questions?

I know this is all a little tough to follow right now, so if you have any questions feel free to comment below and I’ll do my best to help!

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *