Wednesday, June 04, 2014

Introduction to Huginn & Owntracks (or how to make your own Google latitude and IFTTT)

Huginn is an open source IFTTT or Zapier clone written in RubyOnRails. Right now it's in the early phases, but it is easy to imagine this beginning to approach feature parity with those closed platforms.

What I really like about it is how easy it is to get up and running - a development copy is just a git clone and bundle away from functional.

To deploy it on a server, they've even provided Chef recipes.

Right now the architecture leaves a little bit to be desired - everything is based off of ActiveRecord and caters for many, many concerns - from publication, receiving events, generated UI from class metadata, configuration, and the actual setup of the various code to act on your behalf, all in the same model. If you put that aside; the surrounding framework is fantastic - it provides all of the robustness of a decent queuing or job management system, while being generic enough to execute any agents you choose.

The thing that is missing from my Ninjablocks or TheThingSystem is deep integration with a variety of webservices. Zapier or IFTTT doesn't integrate for example, but can do many useful things - how neat would it be to turn on lighting when I leave a foursquare place I've checked into?

The thing that is missing from either of the web platforms is really knowing much about my house and home automation setup. I don't really want a generic house or to control specific Wemo powerpoints from a web system, I want something to knows and discovers things within my local network - things behind the firewall.

TheThingSystem excels at this, and Ninjablocks speaking to a variety of 433mhz actuators (provided you have a big enough aerial) to switch on lamps = a cheap, decent way to get things done around your house.

To fix that, I've added in MQTT publish/subscribe support to Huginn.

Now any Huginn agent can publish their results to a broker, and vice versa.

How can you do the same?

Get a MQTT Broker

You have two main options here, hosted or self hosted. I recommend CloudMQTT's free plan - 10 connections will go a long way, and it's literally a few clicks to spawn a new instance.

Once you are hooked, you can look at the plans available or cook you own.

You'll need to take note of the URL, credentials and more.

Install Huginn

Pretty easy to do. Experienced ruby folks may want to use rbenv or rvm as suitable. Assumes ubuntu or debian:

git clone git://
apt-get install ruby1.9.3 ruby1.9.1-dev rubygems mysql-server
cd huginn
gem install rake bundle
bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:seed
bundle exec foreman start

There's plenty more guidance here, but if the above has worked you can now visit

Install Owntracks

Straight forward enough, simply visit and follow the links to the apt-store.

Configuration - Owntracks

Fire up the app, and under preferences, enable Advanced connection details. You probably want to tick 'start on boot' as well.

Next, configure the broker settings:

Don't forget to pick a snazzy name for your device, as it'll be your proxy on the map.

Hit connect, and everything should be all good.

Next, you'll want to define a waypoint (geofence). Particularly useful as you can choose when the event should fire - entering, leaving, or both.

That's it!

Configuration - Huginn

You'll want to do this last, as it'll make a whole lot of things start to happen.

  1. Add a new Agent
  2. Select MQTTAgent
  3. Populate the MQTT url from the details before.
    It's like a http url

  4. Choose what you are going to subscribe to. For now, I recommend adding a topic of:
    which boils down to "Give me everything!"

The big test

Now that you've done all of the configuration, in Owntracks, use the icon to force share your location if it hasn't run already.

In a few moments (or you can force it to run), your MQTT Agent in Huginn will execute and give you a nice nested JSON event to play with:

There's plenty more you can do, now set up trigger agents to invoke other tasks; or deploy this as a service via chef.

Post a Comment