It occurred to me that I should probably let strangers from the internet control the lights in my kitchen.
(Because why not?)
And now you can, by tweeting to @kitchencolors.
During our recent kitchen remodel, I made a special point to build in power outlets for a couple sets of Philips Hue LightStrips.
With the Philips Hue IFTTT channel, these lights have been set to turn on around sundown and turn off at 11pm.
That’s perfectly cool and all, but lately I’ve been itching to build something fun to take advantage of the bigger RGB color range available with the LightStrips.
Finally last night it dawned on me that I should let the internet choose the colors of my kitchen lights.
Before I began, I wrote down these three goals:
- Make it fast! (No waiting on IFTTT or anything like that.)
- Step out of my PHP comfort zone.
- Power this with my Raspberry Pi.
Make it fast!
The Philips Hue API works by making HTTP requests to a bridge connected to your local network. That, in itself, created some limitations.
One thought was to schedule a cron job on a machine in my home network to run every minute and hit an endpoint on a public webserver to check for new color changes. That approach seemed pretty wasteful (and still pretty slow, honestly). That, and it’d require building a front-end interface to interact with the app.
So then I thought about using Twitter to handle the color requests, and realized this would a perfect time to try the user stream API, since it seems to be nearly instantaneous.
Step out of my PHP comfort zone
Next I started thinking about how I’d want people to make the color requests. Since the Hue API accepts X & Y coordinates from the CIE color space, I knew we would need an easy way to translate casual color requests without being too limiting. In other words, I didn’t want to simply hard-code 20 or so colors, because Hue actually supports 16 million colors.
The Hue command-line interface by bahamas10 accepts CSS color names and also hex color values. This tool runs on Node.js, and I was already familiar with it because I’ve actually been using it for a few months to control my lights from the command-line. (HOYVIN-GLAVIN!).
I don’t have much experience with Node.js, so this seemed like a perfect opportunity to try something new.
The next task was to figure out how to consume the Twitter user stream API from Node.js. After a little digging, I came across twitter-mentions-pushover by Baptist Candellier. This provided everything I needed to consume my user stream. I just trimmed off the part in the script that sends the tweet to Pushover, removed any @mentions and # symbols, and added the NPM module exec() to send the color command to hue-cli. All said and done, I maybe wrote 6 lines of code.
Power this with my Raspberry Pi
Since the node process needs to be constantly running to consume the Twitter stream and pass requests to the Hue bridge, I wanted to keep my power usage low. The Raspberry Pi runs on a simple 5V power supply, and it’s completely silent. It runs headless and sits nicely next to my modem, router, and hue bridge.
Finally, I created a fork of twitter-mentions-pushover and renamed the project Kitchencolors.
See it in action!
I made a hilariously dramatic video to show how quickly tweets are processed as color.
LOL. It was either that or the sound of my dishwasher running.
Give it a try!
To change the colors of my kitchen lights, just send a tweet to @kitchencolors with a css color name or a hex value.
So far, I’ve had people from all over the United States, England, Brazil, New Zealand, and Panama decide what color my kitchen should be.
Open up your Hue lights to strangers
It’s still pretty rough around the edges, but you can download the source here! Future updates will include better color parsing to pull colors out of tweets that contain other text. If that sounds like fun, or if you have other feature ideas, please send me a pull request!