Tuesday, March 18, 2014

Alarm Clock operates your house

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.

rule "Wekker Tom"
        Item pWekkerTom received command ON
logInfo("PERSONAL", "Wekker Tom!")
sendCommand(lBMasterGang, 25)
createTimer(now.plusSeconds(45)) [| sendCommand(lBMasterGang, 50)]
createTimer(now.plusSeconds(90)) [| sendCommand(lBMasterGang, 75)]
createTimer(now.plusSeconds(120)) [| sendCommand(shMaster, UP)]

This rule will:

  1. log a note in the openHAB logs
  2. dim lights in the hallway of the bedroom to 25%
  3. after 45 seconds, dim lights to 50%
  4. after 90 seconds, dim lights to 75%
  5. after 120 seconds, move the shutters up
You can completely customize this to your own desires.

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!

In more detail, this is what we've accomplished:


  1. AWS Training in Bangalore - Live Online & Classroom
    myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    IOT Training in Bangalore - Live Online & Classroom
    IOT Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Reading data through the sensors and processing it with applications sitting in the cloud and thereafter passing the processed data to generate different kind of output is the motive of the complete curricula. Students are made to understand the type of input devices and communications among the devices in a wireless media.

  2. Hadoop concepts, Applying modelling through R programming using Machine learning algorithms and illustrate impeccable Data Visualization by leveraging on 'R' capabilities.With companies across industries striving to bring their research and analysis (R&A) departments up to speed, the demand for qualified data scientists is rising.
    data science training in bangalore
    Big Data and Hadoop training Unlike traditional systems, Big Data and Hadoop enables multiple types of analytic workloads to run on the same data, at the same time, at massive scale on industry-standard hardware.myTectra Big Data and Hadoop training is designed to help you become a expert Hadoop developer. myTectra offers Big Data Hadoop Training in Bangalore using Class Room.
    hadoop training in bangalore
    Looking for best Machine Learning Training in Bangalore then join myTectra the leader in Machine Learning Training in Bangalore. Classroom & Online Training
    machine learning training in bangalore