lamps-1798692_1920

Create your DIY remote for Philips Hue with Raspberry Pi

You know those Philips Hue lights, which are amazing and really cool gadgets for your house? Well, thanks to Philips it is also easy to create your very own DIY remote control for them. Yes, of course you can get a remote for these lights in the shop as well, but why would you if you can program one yourself?!

To do this I’ve used my Raspberry Pi 2 model B, and from my Arduino Starter Kit I’ve used a breadboard, a remote control and an IR (infrared) receiver. I’ve named my remote control “SpecialForMP3”, since this is the only text I could find on it. But you can use any infrared remote control you want, so if you have some useless remote controls lying around, just give them a purpose again.

RemoteControl_IRreceiver

First, we need to setup the Raspberry Pi to be able to receive infrared signals sent by the remote control. Furthermore, we have to make sure the Raspberry Pi can not only receive the signals, but is also capable of deciphering them. In other words, we want to make sure the Raspberry Pi can “hear” the remote control and is also capable of understanding what is said; they need to speak the same language.

The first step towards achieving this goal, is connecting the IR receiver to the Raspberry Pi. After we’ve done this we can start with setting up the LIRC (Linux Infrared Remote Control) package on the Raspberry Pi. LIRC is a package that allows you to decode and send infrared signals of many (but not all) commonly used remote controls. To setup both the IR receiver and LIRC, you can follow the steps as described here. You can find the resulting LIRC configuration file on GitHub, together with the rest of the code needed to finish this project.

When finished, my setup looks like this:
20170827_161012 20170827_160940

As a side note, I had some troubles using mode2 -d /dev/lirc0, after pushing a button on my remote instead of seeing something like the example I got the message “Partial read 8 bytes” and then it just stopped. After changing the driver from devinput to default in lirc_options.conf this issue was fixed.

When you find yourself having no permission to change files, look at the chmod 777 option, this makes sure everybody has read-write-execute permissions on the specified files and/or folders.

Now we’re ready for installing Python packages that make it possible to use LIRC and connect to the Philips Hue Bridge which controls the lights:

  • sudo pip install phue
  • sudo apt-get install python-lirc

We get started by connecting the Philips Hue Bridge through a Python script, this can easily be done by using it’s IP address. You can find out what the correct IP address is in multiple ways, an easy one is using the (official) Philips Hue app:

  • Go to the settings menu in the Philips Hue app and go to My Bridge, click on Network settings and switch off the DHCP toggle; the IP address of the bridge will show.

The next thing we need to do is connect to the Philips Hue Bridge and determine the names of the available lights and light groups.

# import the necessary packages
from phue import Bridge
# identify the bridge
b = Bridge(‘192.168.1.128’)
# connect to the bridge (first press button on bridge)
# this only has to be done the first time you setup the connection
b.connect()
# get the names of all the lights
print b.get_light_objects(‘name’)
# get the names of the light groups
print b.get_group()

 In order to change the colour of a light, we need to know the XY code of this colour. Since we’re more familiar with using RGB codes for colour, we can use this function to convert RGB to XY.

Finally, we can connect to the LIRC and create the loop in which we will change the colour of the lights. In my case I have the following lights available: Zithoek, Zithoek bloom, Raamkant, Midden, Keukenkant, Slaapkamer. And I have the following light groups available:  Zithoek, Eetkamer, Slaapkamer. You can find the complete script to use the remote to control the Philips Hue Lights on GitHub as well, this script connects to the Philips Hue Bridge and to LIRC and has ten different scenes for the lights, but you can of course adapt this to your own needs and wishes.

Good luck and enjoy!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *