Let’s talk about HomeKit. Apple’s framework for home automation allows you to set up of virtual Homes and Rooms that can contain different accessories. These map 1:1 with your home. You then set up Actions and Triggers to control those accessories. If you’re new to HomeKit there’s an excellent primer here.

I chose HomeKit over the sea of other “standards” because it satisfies my last two directives. HomeKit is built for iOS and works with iPhone, iPad and soon with the new AppleTV. It also has full Siri integration (Yay!). So what’s are the downsides of such a magnificent technology?

Slow adoption from hardware vendors Many existing products don’t support it The products that do are still very pricey

How then do we satisfy the first prime directive?

Some companies have made their non-HomeKit compatible products work with HomeKit by way of a hub. These hubs acts as an intelligent intermediary. Buying a HomeKit compatible hub would significantly increase my cost and only work with that companies line of products. It turns out that a few individuals have created an open-source reverse-engineered version of the HomeKit API in JavaScript running on Node.js called HomeBridge. Think of it as a software version of a HomeKit hub. It includes a feature not found on any Apple approved device: the ability for developers to create integration plugins for any non-HomeKit compatible device. This means by using one of the many community contributed plugins I can integrate any device into the HomeKit ecosystem.

Now the hard part: what can I use to control the lamps? I recently came across a Geek Dad article singing the praises of the Etekcity Wireless Remote Control Electrical Outlets. These are very inexpensive outlet adapters that can turn on and off anything up to 120V connected to an electrical outlet. They work by transmission of a signal from an included remote control over the 433Mhz RF band. At ~$45 for 5 outlets they are cheaper than buying a single smart outlet on the market today, plus remote controls can program in a variety of different ways. I affixed a remote to the wall so I can turn the lights on and off if I don’t have my phone handy, a feature you don’t see with any smart outlets on the market today.

Etekcity wireless remote control outlet

My phone can now talk to HomeKit using HomeBridge and I have a device that can turn on and off the lights. How do I get HomeBridge to talk to these devices which can only receive signals over 433Mhz radio frequency?

The answer involves the use of a Raspberry Pi. It turns out I am not the first person to encounter this problem. Tim Leland put together a guide for building a circuit using the Raspberry Pi to send the appropriate signals using a 433Mhz transmitter connected to the Pi’s general purpose input/output pins. He put up a code repository with two command line utilities RFSniffer and codesend. The former detects button presses (interpreted as RF codes) by listening to RF signals.. The latter transmits an RF signal by passing an RF code as a parameter to the command. Each Switch has two codes, one for on the other for off.

I wrote a small Node.js HTTP server that executes the codesend utility as a remote procedure call. This allows me to open a URL from any device on the internal network and have the Pi send a code over RF. The code is sent as a parameter in the URL. If the code were for example 123456 the URL to execute would be the following:

http://sensor/api/switch/123456

The Raspberry Pi can now receive HTTP requests and turn a switch on and off. The last piece of the puzzle is having HomeBridge execute those HTTP requests when a HomeKit command is given. To accomplish this the homebridge-http Node.js plugin is required. The plugin creates HomeKit accessories and attaches HTTP URLs to the accessories on and off states. Here is an example JSON configuration for a single switch.

"accessories": [

{

"accessory": "Http",

"name": "bunny lamp",

"switchHandling": "yes",

"http_method": "GET",

"on_url": "http://sensor/api/switch/xxxxxx",

"off_url": "http://sensor/api/switch/xxxxxx",

"status_url": "",

"service": "Light",

"brightnessHandling": "no",

"brightness_url": "",

"brightnesslvl_url": "",

"sendimmediately": "",

"username" : "",

"password" : ""

}

]

Each switch requires an accessory object added to the accessories array. HomeBridge will register “bunny lamp” as an accessory which is also the name that Siri will respond do. Everything should now be in place and the flow of our Siri requests should resemble the following diagram.