Connecting LIFX Bulbs with Vera (Z-Wave)

A quick guide on how I got my bulbs (sort of!) connected to my Vera network. No real trickery here. And the bulbs themselves aren’t yet added, instead, I focused on creating common scenes and made scenes in Vera.

What’s needed:

  1. A Raspberry Pi (or other *nix computer that you’re happy with keeping on all the time)
  2. Ensure it has a static IP on your local network – otherwise if the IP keeps changing, this won’t work too well. For mine, the IP is
  3. Ruby v2.0 (Raspbian has an older version, so I had to follow these instructions to get 2.0 installed: ( (this took forever to finsih!!)
    1. sudo aptitude update
    2. sudo aptitude install git-core
    3. curl -L | bash -s stable –ruby
    4. pi@raspberrypi ~ $ source /home/pi/.rvm/scripts/rvm
  4. Make sure root can see the new file by changing the /bin/ruby binary to point to the new ruby that is placed somewhere obscure in your own folder. For me, it: /home/cdrum/.rvm/rubies/ruby-2.1.3/bin/ruby
    1. sudo ln -s ruby /home/cdrum/.rvm/rubies/ruby-2.1.3/bin/ruby
  5. The (unofficial) Ruby HTTP API for controlling LIFX bulbs: (and follow those instructions on getting it installed), but the long and the short of it is:
    1. rvmsudo gem install lifx-http
    2. Note here i’m using rvmsudo – this was key to ensure that the gems are installed systemwide, and that root, during the installation, gets my new ruby 2.1.x environment (otherwise you’ll get complaints that LIFX requires >= Ruby 2.0.
I wrote a simple php script to help generate the Lua code (the language Vera uses) that you can paste into the Scene configuration.
Running my script, you will get a result that looks similar to this:
In Vera, go ahead and create a scene and click on the Luup tab:

Paste the Lua code that is generated from the script above, save, reload, and now you should have a working scene that controls LIFX bulb(s)!!


Putting the pieces together in anticipation…

It’s been a while since I posted here. Primary reason, I had a daughter last March. (my free time disappeared literally overnight). Now that we’re getting settled, it’s time to get back into the home automation game.

In anticipation to our upcoming move to our first home we’ll own, I am ramping up and have decided on the Z-Wave protocol as I don’t want to built my own everything from scratch, but instead I’d like to get a baseline on which I can build on top of.

Will I still hack around with the Raspberry Pi? I think so. More on that later.

The Base

As mentioned above, I decided on Z-Wave. (Other competing standards include ZigBee). I ultimately went with the Vera Lite controller that I kind of bought out of the blue the other day at the IT Show here in Singapore (it was discounted by 10%, but it’s still more expensive in Singapore than elsewhere because it is Singapore).

The kit included the controller (the Vera Lite), 3 Fibaro dimmer switches, and a motion detector. The dimmer switches will be used for connecting some of my downlights to the network (and I am sure I’ll need more later).


I bought 12 LIFX bulbs a while back and they arrived a couple of weeks ago.

No, these don’t talk Z-Wave, but that will be a fun project for me, see below.

As mentioned earlier, I’ll be using dimmer switches (or normal switches) for my other lighting. Even though these switches are expensive (if they are Fibaro), the advantage is, they are small and should fit inside of the light switch socket in the wall (I haven’t confirmed this yet with our new condo, so fingers crossed).

My LIFX bulbs will be placed in both ceiling lights as well as lamps, but the final configuration isn’t yet confirmed (I still have about 3 not yet taken as I am struggling to find rail lights that fit E27 Edison screw bulbs. Tall order.

LIFX is planning to release an SDK sometime this quarter, they claim. Once they do, the hacking begins – I want to build a Z-Wave interface for LIFX, most likely using a Raspberry Pi with Z-Wave shield (it’s a shame that it’s bloody expensive though – more than the Pi itself!).

Aircon and other IR Devices

This is where the fun begins. I was thinking of continuing my previous project of the “ThermostatPi” (which I coincidentally posted about a year ago yesterday), making use of a Raspberry Pi and a USB Toy 2, but following a Singapore Home Automation forum on Facebook the last few months, a very interesting product out of China has stoked my interest, the Broadcom RM2. It’s a proprietary IR blaster (i.e. that doesn’t connect with any other Home Automation standard like Z-Wave), but the reviews promise it “just works” – something I am quite keen on. They are rumored to release an SDK for it in Q1 of this year. And this is where another fun project will come about as I plan to write a RaspberryPi interface to it, much like I plan to do with LIFX as stated above. The goal here is to control everything from single app (switching between apps is too much trouble and certainly not consistent with the whole Home Automation thing).


I’m still researching this and will post more about what plan to do. It looks as though the mechanisms to control curtains is quite costly, so this may need to take a back seat for a while.

ThermostatPi – Controlling airconditioning with the Raspberry Pi and USB IR Toy – First Release!

Finally got around to getting the first release of my current project up!


It’s called ThermostatPi and it makes use of a Raspberry Pi, a USB IR Toy 2 (see my library here), your bargain basement DS18B20 One Wire Temperature Sensor, some Blu-Tack, and a few other miscellaneous wires and such.

In it’s current form, it monitors temperature, and allows the user through a web browser control the wall mount airconditioner over IR. The code contains a command line tool to store presets. (In my case, my air conditioner is complicated, and I couldn’t extract individual button clicks, but instead, the complete configuration of whatever is on the remote at the time.


I wrote everything in PHP. I used Foundation for the web framework. I used RRDTool for charting.
Right now, there are two major screens. First is the current temperature with historic graph.
The next tab is there the controls are shown.

 You see to the right are the last 6 or so commands run. I use SQLite3 to store the history. (I plan to add settings to the db as well down the road).

Using Foundation’s alerts, I show immediate feedback after button presses.

It also works on Mobile, thanks to Foundation.
I have a cron running to update the history charts each minute.
Lastly, I use dyndns so I can access it from my mobile phone. Makes it simple to turn on the air con when I’m on the way home!


This is pretty self explanatory. I have the DS18B20 chip plugged into the GPIO pins.
And lastly, the IR Toy is positioned to point at the air con using Blu-Tack. Thank goodness for Blu-Tack!

 Next Up

I want to start building some intelligence into it. I want to set a temperature, and have it attempt to maintain that temperature. We’ll see how that goes.

PHP Library for Receiving from/Transmitting to the USB IR Toy v2 Ready!

I am a fan of PHP. I am lazy, and I don’t really want to learn Python. Since the IR Toy is a critical component for my next Raspberry Pi project, (of which the code would be primarily written in PHP), I needed a PHP library to interface with the IR Toy.

I found a good, simple to use Python library to interface with the IR Toy by Chris LeBlanc called PyIrToy. I decided to port it to PHP. Thanks, Chris!

My library is unoriginally called “phpIRToy”.

I have open sourced my code under GPL v3. You can grab it from my bitbucket site (mercurial) at Right now it’s on version 1.0 (why not?)

In the repository, other than the License and Readme files, you’ll see 2 main files. In the “lib” folder, the library itself sits. In the “test” folder, I have an example on how to receive a button press from an IR device, and then right away send (transmit) that same button click.

Enjoy! And let me know what you think!

Flashing the USB IR Toy v2

I finally had some time to work on my temperature project and the first step was to make sure my 2 USB IR Toys worked (they finally arrived about 2 weeks ago).

One seemed to work fine (meaning my Raspberry Pi recognised it and enabled the device /dev/ttyACM0), but the other wasn’t being recognised. (In fact the LED was constantly on). I thought I got a faulty one.

I decided to try reflashing it.

Dangerous Prototypes had a howto on how to flash it, but I found it slightly confusing, so here are my instructions (that are for flashing the v2 board with a v22 firmware) on the Raspberry Pi:

Short pins PGC and PGD

First, need to short the PGC and PGD pins. This is simple enough – I just used simple jumper wire.

Get latest Firmware

Downloaded from


Get latest IRToy-specific Firmware Update Utility


This apparently is a patched utility from the board maker at Diolan.


Note, I had to do all of us sudo – kept getting errors while running these as user pi.
export LIBS=-lusb
sudo apt-get install libusb-dev
sudo ./configure (I got g++ errors if I run as pi)
sudo make
cd ..


sudo IRToy-fw_update/fw_update -e -w -v -m all -vid 0x04D8 -pid 0xFD0B -ix USBIRToy.package.v22/firmware/USBIRToy.v22.hex

Make sure your paths are correct in the above command. 
The successful output should look like:
U2IO flash erasing: DONE.
U2IO id programming: DONE.
U2IO eeprom programming: DONE.
U2IO flash programming: DONE.
U2IO id programming: DONE.
U2IO eeprom programming: DONE.
U2IO flash verifying: DONE.
U2IO id verifying: DONE.
U2IO eeprom verifying: DONE.
RESET Device
Operation successfully completed.
I was lucky. The IR Toy I thought was bad now seems to work fine!

Hacked Door Open Remote with RedBee RFID and Raspberry Pi

On 2 Fridays ago, we had a “hackathon” at work where we stayed back and worked on personal hacks/projects. The entry door to our office is controlled by a 4-number code. We have a remote control to open (unlock) it when someone rings the bell. We had a bunch of RFID equipment sitting around for the past year and a half, and I really wanted to make use of it.

We got a few of these back in 2011 when we were looking at options for an RFID solution. We chose this because we liked the openness of the hardware APIs, however, we ultimately chose a different solution (the pcProx USB reader).

We purchased a bunch of these as they fit directly in the RedBee RFID reader – making it a good solution for deploying RFID at on-ground activations. Again, we ultimately chose a different technology, but this wireless module (2 of them actually) would make this hack even better.

Sparkfun XBee Explorer USB

This plugged into a computer, with the XBee module plugged in allows the “base station” to communicate with multiple devices through the plug-and-play mesh network created hassle free with the XBee modules.

Finally, we needed another door remote to hack.

We figured we could hack this and mimic a button press with one of the Raspberry Pi’s GPIO pins by bypassing the button, controlled by the GPIO pin. I did my homework earlier in the week and found that I needed a solid state relay to bypass the button pressing. I found one at Element 14 (my new favorite online store).
This I figured would work just nice. The GPIO pins of the Raspberry Pi are powered by 3.3V, and the Door remote control is powered by a 12V battery (whether or not that’s the voltage that gets sent through the push-to-make buttons or not, no idea) – this SSR allows for a 0V to 48VDC range on the load pins, and a 3V to 12V on the control pins – perfect for this project.
I worked on this with my colleague Yasin. I would take care of the remote hacking and the Raspberry Pi set up – he would take care of the RFID Reader interface and simple DB/logic coding.
The Equipment

Off To Work
I found the correct pins to use for my soldering. 

Soldered the ends to the control pins of the SSR, and then added wires to plug into the Raspberry pi.

And here it is. Simple.

Yes, you can order Domino’s using Midori on the Raspberry Pi, as I did for much needed fuel. On top of that window, you can see the terminal testing out the RFID scanning. We were lucky to note that we only needed to monitor a device (by cating in the simplest form) for the scans.

My colleague Yasin handled the coding on the Raspberry Pi, using Python and SQLite to manage the RFID device monitoring and scan checking. We managed to get a prototype working only after about two hours or so. Here are some videos. Bare with me, had a few beers.