Ruby Gems for home automation: nlhue and xap_ruby

Nitrogen Logic code on GitHub

The web interfaces for the Nitrogen Logic depth and automation controllers are written in Ruby. To talk to the Philips Hue lighting system and some other DIY home automation systems, I created two Ruby libraries, nlhue and xap_ruby. I recently converted these libraries to Ruby Gems available from

Both of them depend on EventMachine for fast network event handling, but that also makes them a bit difficult to use. They were developed in a bit of a hurry, follow C rather than Ruby indentation, lack automated tests, and don’t represent the best code quality. Nevertheless they have been battle tested in real products working well for real people, and they may yet be useful.

Continue reading for more information about these gems.


I wrote the nlhue gem so Nitrogen Logic controllers could have a clearly licensed, pure Ruby, and EventMachine-based interface for the Philips Hue lighting system. Though they are expensive and often laggy, Philips Hue lights remain one of the best ways to get full remote control of brightness and color without rewiring.

Initially, the Nitrogen Logic Automation Controller only supported the DMX-512 protocol for controlling lights, using a C library I wrote called libdmx485. DMX-512 is fast, versatile, and lag free, but requires dedicated dimmer packs in a centralized location and/or new wiring to DMX-enabled fixtures. It’s commonly used for stage lighting, and sometimes for architectural lighting.

Needing a more consumer-friendly option, Philips Hue support was added to the Depth Camera Controller, and the nlhue library was born. Now it’s been converted to a gem for easier use and review.

Download nlhue via RubyGems, or view the nlhue source on GitHub.


The xap_ruby gem was created because there were no pure-Ruby libraries that could speak the xAP Automation protocol. xAP support was requested by a Nitrogen Logic customer to interface the Depth Camera Controller with a Homeseer-based DIY home automation system. That allowed motion and presence events from the Depth Camera Controller to turn lights on and off in Homeseer. Although there are a number of systems that support xAP, its use never became very widespread outside of the DIY market.

The xAP protocol has its warts, with multiple semi-overlapping “schemas” that could have been better implemented as layers of added meaning on a base schema. As such, the xap_ruby gem only implements the Basic Status and Control schema, which provides simple on/off or numeric level values for up to ~250 named parameters per device.

You can view the xap_ruby source on GitHub, or see the xap_ruby page on RubyGems.