Plugwise gateway on NSLU2

I’m using some Plugwise circles to control various devices around the house. A few lights and the amplifiers of my SqueezeBoxes are automatically switched on and of as required. To couple this with MisterHouse, I built an NSLU2-based gateway to the Plugwise ZigBee network.

The Plugwise system consists of neat plugin adapters that fit between a device and the power socket. The adapters can turn the plugged mains device on and off, and can at the same time measure the power consumption of the device that is attached.
The plugs are called ‘Circles’ and they form a wireless ZigBee mesh network around a coordinator (called Circle+). By itself, the network has no intelligence, it needs a link to a computer. This link is provided by a USB stick device (called ‘Stick’).

My problem: my home automation server is located upstairs, and my Circles are on the ground floor. The Stick cannot reliably communicate with the Circles.

Solution 1: buy the device called ‘Stretch’ provided by Plugwise. This device allows you to connect the Stick to your LAN to place it in range of your Circles.

Solution 2: build a custom device that performs the same functionality (and adds some neat features ;-))

Obviously, we go for solution 2 🙂

On domoticaforum, somebody published a first version of an xPL module that could communicate with the Circles through the Stick (firmware v1). This module is written in Perl (yay!).

So, I dusted off my trusty old NSLU2 (nick-named ‘Slug’), put a Debian install on it, and now the Slug is hosting my Stick on the home LAN on the ground floor. Commands are sent from Misterhouse through an xPL module I wrote to control the devices that are connected to the Circles.

The steps required to duplicate this setup:

Get a Slug.

Flash it with the Debian firmware. I tried other firmwares, but eventually I ran into problems to install all required software to get the xPL module up and running every time. So I went with a full Debian install.

Install the xpl-perl software package (add deb ./ to sources.list),

Install the following packages

apt-get update
apt-get install libxpl-perl
apt-get install runit
apt-get install daemon-tools
apt-get install libclass-dbi-loader-perl
apt-get install libdatetime-event-sunrise-perl
apt-get install libdevice-serialport-perl
apt-get install libdigest-CRC-perl

Patch the xpl-perl file in your install so that it uses the Device::SerialPort module.

Add the xPL support to the xpl-perl software that has been installed by fetching and installing the files from my account.

Run xpl-perl-setup

This will generate the required folders/files to run the daemons required for xPL (mainly the hub and xpl-plugwise)

Edit the xpl-hub run file to add the -i eth0, else the hub does not work.

Copy one of the /etc/xpl/services folders to /etc/xpl/services/xpl-plugwise and edit the run file to contain

exec 2>&1
exec setuidgid xplperl envdir ./env softlimit -d300000 /usr/bin/xpl-plugwise --verbose --plugwise-verbose --interface eth0 --plugwise-tty /dev/ttyUSB0

Execute the ‘run’ for xpl-plugwise manually in the terminal to verify that it works correctly.

Finally, ensure that everybody has write access to /dev/ttyUSB0, or add the user xplperl to the dailout group. The way I did this was adding to /etc/rc.local the following line:

/bin/chmod a+rw /dev/ttyUSB0

That’s it, now you can control your Circles from whatever device on your LAN usign the open xPL protocol. If you install the Debian to a flash disk, the complete device (Slug+Stick) uses ~4 W.

The only disadvantage it that when Plugwise upgrades their firmware again and you migrate, you might need to update the xpl-plugwise software on the Slug to keep the communication ongoing. This is of course only a problem if you continue using the Stick with the windows software.

So for the moment, I’m still running the pre-February2010 firmware (called v1). When you buy new Circles right now, you get them with newer firmware that is not supported with the current version of the xpl-perl Plugwise module because Plugwise updated their API.

All in all, I’m quite happy with this setup…

Note:  before considering to duplicate this setup, be aware that there are some disadvantages to the Plugwise hardware.

First of all, the software that is provided to control the Circles is Windows only.
Secondly, the people behind Plugwise refuse to document the protocol that is used to communicate between their software and the Stick. It is not clear to me what they try to obtain by doing that, as every time they update their protocol there is always someone who reverse-engineers it.
Another annoyance with the hardware is that some of the Circles emit a low-volume buzzing noise when they are enabled. This is something to keep in mind should you plan to use the plug for a reading light next to your couch.
Finally, there is no way to find out what RF links between Circles are good and what links have a marginal link budget. The solution provided by the company is ‘just place more plugs to make the network more robust’. Nice plan, but when you have most on the plugs on the ground floor, and your server upstairs, then you don’t want to put buzzing Circles in your sleeping room to have a reliable link between the PC and the ZigBee network.

So, why did I choose to use the Plugwise system then? Well, the plugs have a nice formfactor, and Plugwise was the the only company I know of that delivered a ZigBee-based solution at the time I bought the hardware. Indeed, originally it was stated on their website that using the appropriate network key other devices could also make use of the ZigBee mesh network. I thought it would be nice to build a basic mesh network in my house to which other devices/sensors could be added. Unfortunately, when I asked for the key, I got a friendly reply that this feature was not supported, I got the offer to return the hardware if I had a problem with that, and finally, the statement was withdrawn from their website…