Tuesday, March 18, 2014

I have my house wired up pretty nicely with all kinds of automation - I'll post details on this later. Today, I wanted to hook up the alarm clock on my phone. Basic scenario: when the alarm goes off, turn on the lights and open the shutters. Let's get to it.

I have a KNX-based home automation system, but most of the advanced scenarios are configured in OpenHAB. The basic flow for automating this alarm clock scenario is documented here:

Let's go wild and start with the middle part here. We configure an item in OpenHAB that we can use to trigger the alarm. Look here for details on adding items in OpenHAB. We'll add this line:

Switch pWekkerTom"Wekker Tom"{autoupdate="false"}

If you're not familiar with this 'autoupdate' parameter, don't worry about it. It just makes this switch act as a trigger without changing its state. The scenario would work even without it.

Next we create a rule that catches commands for the pWekkerTom item, and performs whatever actions we want when our alarm goes off.

Now all is left is a way to have our mobile phone trigger all of the above. For this purpose, we use the swiss army knife of Android automation: Tasker. (Apologies iPhone users - you're out of luck here. I'm sure Tasker equivalents exist, I just don't have any experience with them).

We'll use the OpenHAB REST API, so we'll also install the RESTask for Tasker plugin. This provides a bit more features than the native Tasker HTTP actions.

Once both are installed from the Google Play Store, first go to the Tasks tab in Tasker and create a new Task. in this Task, create an Action by clicking the + sign at the bottom of the screen. For action category, select Plugin -> RESTask.

In the configuration of the RESTask, fill in these fields:

Request Type: POST

Host: https://link.to.your.openhab:7443/rest/items/pWekkerTom

Basic Auth: <your credetials>

Enable custom body: check!

Custom body: ON

You can leave most other settings to their defaults, but it depends on your setup.

Save all this goodness. The last step is to create a profile that ties the alarm clock to the task.

Go to the Profiles tab in Tasker and create a new Profile by clicking the + sign at the bottom of the screen. In event category select Date/Time -> Alarm Clock.

Save this, and then associate this profile with the Task you have created earlier. Done!