Table of Contents

IoT Home Automation

Platform

Installation

Download latest Raspbian image:

sudo raspi-config sudo apt-get update sudo apt-get upgrade

Wireless sensors

WT450H temperature and humidity transmitter and TellStick Duo USB receiver/transmitter.

Installation

There are many alternative installation instructions for telldus-core in the net. This one is proven to work with Debian in Raspberry Pi and BeagleBone Black: http://www.telldus.com/forum/viewtopic.php?f=15&t=3960

sudo su
echo "deb-src http://download.telldus.com/debian/ stable main" >> /etc/apt/sources.list
wget -q http://download.telldus.se/debian/telldus-public.key -O- | sudo apt-key add -
apt-get update
apt-get build-dep telldus-core
apt-get install cmake libconfuse-dev libftdi-dev help2man
apt-get --compile source telldus-core
dpkg --install *.deb

Test installation:

tdtool -l

Message broker

Installation

Install MQTT Broker:

sudo apt-get install mosquitto mosquitto-clients
(sudo apt-get install nodejs npm)

In order to install td-mqtt-bridge, node needs to be upgrades: http://joshondesign.com/2013/10/23/noderpi.
Then install Telldus-MQTT bridge: https://www.npmjs.org/package/td-mqtt-bridge

npm install td-mqtt-bridge --registry http://registry.npmjs.org
sudo npm install -g forever --registry http://registry.npmjs.org

Telldus to MQTT Bridge

Simple node.js bridge compatible with GaianDB and JSON databases. Requirements: net, mqtt.

npm install mqtt

Package: telldus-mqtt.tgz

telldus-mqtt.js:

/***
 * Telldus-MQTT bridge
 * Parse messages from telldus-core and publish to local MQTT broker.
 *
 * Jaakko Ala-Paavola 2014-08-22
 */ 

var net = require('net');
var mqtt = require('mqtt');

var lasttime = 0, lastid = 0;

var publisher = mqtt.createClient(1883,'localhost');
var telldus = net.createConnection('/tmp/TelldusEvents');
telldus.setEncoding('utf-8');

telldus.on('connect' , function () {
    console.log("Connected to Tellstick.");
});

telldus.on('data', function(data) {
    var pos = data.indexOf("TDRawDeviceEvent");
    if (pos > -1)
    {
	var measure={}, keyval=[];
	var arr = data.substr(data.indexOf(":",pos)+1).split(";");
	for (var i=0; i<arr.length; i++) {
	    keyval[i] = arr[i].split(":");
	    measure[keyval[i][0]] = keyval[i][1];
	}

	if ( measure.class == "sensor" && 
	     measure.protocol == "mandolyn" &&
	     measure.model == "temperaturehumidity" )
	{
	    // prevent duplicates
	    var now = new Date().getTime();

	    if (data.id != lastid || now > lasttime+1000)
	    {
		var topic = "gdb/sensor/temperature/"+measure.id+"/celsius";
		console.log(topic+": "+measure.temp);
		publisher.publish(topic, measure.temp);

		var topic = "gdb/sensor/humidity/"+measure.id+"/RH";
		console.log(topic+": "+measure.humidity);
		publisher.publish(topic, measure.humidity);
		
		lastid = data.id;
		lasttime = now;
	    }
	}
    }
});