Friday, April 15, 2016

Using Cisco Spark as notification channel for Openhab

Notify from Openhab using Cisco Spark

I'm using Openhab for my home automation for a couple years now and am very happy with it.  One of the things it can do it notify you on various events around the house.  I had XMPP configured to send messages to my Google account, but the last months this has been failing.  Some error about pinning certificates.  There's some information on the internet about how to solve this, but I'm using a Google account with a custom DNS name which seems to complicate matters a bit.

Since Cisco added APIs to the Cisco Spark service (try it!!), I wanted to use Spark instead for my notifications.  The proper way of integration with Openhab is to develop an Openhab plugin, but I wanted something more versatile. So I started the development of a CLI interface for Spark: sparkcli.  Let's get going!

Install and configure sparkcli

First download a copy of sparkcli here: .  Make sure the binary is on the PATH for the OS user that's running Openhab.  Typically /usr/local/bin will do just fine.

Once downloaded, following the configuration instructions here: https://github.com/tdeckers/sparkcli
In short these are the steps you'll follow:

  1. Set up Cisco Spark developer account and configure an app
  2. Go through the OAuh authorization process
  3. Create a configuration file.  Note: easiest is if you create this in the home directory of the OS user that's running Openhab.
  4. Login once using sparkcli to get access tokens.
That's it.

Use sparkcli in Openhab rules

Now you can use this in any rule that you define in Openhab.

rule "Notify alarm"
when
  Item o_alarmFull changed
then
  if (o_alarmFull.state == ON) {
    //sendXMPP("you@yourplace.com", "Alarm aan")
    executeCommandLine("sparkcli@@m@@create@@-@@Alarm@@aan")
  } else {
    executeCommandLine("sparkcli@@m@@create@@-@@Alarm@@uit")
  }
end

Openhab has some weird syntax about spaces in command lines, but it works.

Later!

I might get around building a proper Cisco Spark plugin for Openhab, so stay tuned!