Building a Hue light switch using a Raspberry Pi Zero

I have smart ‘Hue’ lighting in my living room: light bulbs I can switch on and off, or change color using my phone. Nice, but there was something missing: a physical switch. Let’s fix that by building our own!

The problem: when I get home when it’s dark outside, I used to just flick a switch to turn on the light in my living room. Now I walk into the room and notice the light switch is already switched to ‘on’. This is because the smart Hue bulbs need power to operate, a light switch that’s set to ‘on’ doesn’t inherently mean the bulbs emit light.

Now I enter my living room and notice it’s dark, I need to get my phone, open the Hue app, and press the digital switch in the app. The old school/’dumb’ physical switch isn’t so bad after all!

I really like the smart bulbs since you can dim them and they can have all kinds of colors, but I found a physical switch was an important missing feature in the Hue starter set. You can buy a separate physical switch for Hue, but the best feature of Hue is you can send pieces of code in JSON format to the hub that’s controlling the bulbs. And that’s what I’m going to use to my advantage!

Building a smart light switch

I really like the combination of code and the physical world, and I love my Hue bulbs. Buying the physical switch would be easy, but the reason I won’t is because it’s limited in it’s options: on, off, dim down, dim up. My light bulbs are ‘smart’, but just on/off and dimming looks a lot like the ‘dumb’ light switches I already had. I wanted a better physical switch than Philips (the manufacturer of Hue) could offer. So, I went online and got myself an early Christmas present: a Raspberry Pi Zero W starter set (including casing, SD card, etc.).

Getting the Raspberry Pi Zero W ready for action

I bought a 16GB SD card with a system called ‘NOOBS’ on it. Seems like an appropriate name, since I had no idea what it actually did. Turns out is installs OS’es for you using a nice interface. So, attached the tiny Raspberry Pi Zero to my huge 43″ television. Also connected the power adapter, USB, and HDMI cable. There I encountered my first problem: the Raspberry Pi Zero weighs only 9 grams, the force of the attached cables pulls it harder is no match for the Raspberry so I needed to fixate it using a dumbbell I use for weight training.

All attachment cables pull but the Raspberry Pi Zero has no weight to compensate. Here I’ve attached the Raspberry to the bottom of the casing, you’ll see more of this later.

After solving that unexpected first world problem I got down to business: making sure the Raspberry had a network connection. That turns out to be really easy with NOOBS, started to like this way of setup. After a connection had been established I installed the recommended option recommended by NOOBS: Raspbian. Installing it took far longer than I expected: installing Raspbian directly would have been faster.
After downloading Raspbian I booted it to set up two major things needed for this project: SSH access and booting to the CLI. SSH access meant I could access the Raspberry to modify stuff on it, without the need to attach it to my television. Booting to CLI is handy since I won’t need a graphical interface, just the underlying system Raspbian offers. While in Raspbian I also opened the terminal: I had no idea on what ip address the Raspberry lived in my home network. Typing hostname -I gives you the ip address without having to guess it while looking at a list of connected devices in your router.

After that I rebooted the Raspberry. Time for the check-up: can I access it using my laptop? Yes I can! Time to do some hardware!


Essential for this project is using the GPIO pins: I’ve used these pins before on my other Raspberry. GPIO stands for ‘General Purpose Input and Output’. The Raspberry Pi GPIO documentation has a nice explanation:

These pins are a physical interface between the Pi and the outside world. At the simplest level, you can think of them as switches that you can turn on or off (input) or that the Pi can turn on or off (output). Seventeen of the 26 pins are GPIO pins; the others are power or ground pins.

Basically this is the point where code meets hardware. The Raspberry Pi Zero comes with the pins but these aren’t attached to the Pi itself: this is where I could practise my soldering! I concluded that maybe my soldering iron is a bit too chunky for soldering this kind of tiny parts together but after soldering the pins were attached:

Moment of truth: will the Pi still work? The board is made of plastic, which obviously melts when exposed to something hot, like for example my soldering iron. During the soldering I had some moments I thought I melted my Pi. It turns out I was careful enough since the Pi still worked!

I’ve decided to use this post as an introduction with a bit of ‘how I did it’. The next blog post will get into more detail on how to make it all work, now the base setup has been done!

edit: see part two of Building a Hue light switch using a Raspberry Pi Zero