Quick intro... this is my 'Hueberry'. It will allow you to control Philips Hue lights using a Raspberry Pi.

Conventionally one would control their Hue using either their computer or a mobile phone app. Personally I find these two options a bit 'nerdy' and also in my opinion they over-complicate a process that is essentially 'flipping a light switch'. Also, using a mobile phone app is cool right up until you have guests over. Should all of your guests download an app and pair their phone with your Hub just so that they can turn the light on? I suggest not.

I think my solution fills a void because it provides one a single device that everybody inside the house can use (without downloading an app/tinkering with anything). Also, it's pretty cheap/easy to setup.

So... how do you make one? Also, how much do they cost?

Step 1: Step 1: Buying All of the Parts

This step is the least fun because it involves parting with hard earned money. So... I'll try to make it as easy as cheap as possible for you. Shop around and find the following parts:

1) A Raspberry Pi. Look around for prices... mine is a 'Model B' which you can no longer purchase (it has been replaced by the Model B+). However, I purchased it from Element 14 who appear to be selling the Model B+ for $38 USD.

2) A power cable and a power supply. I grabbed these from ebay for ~$5AUD... not particularly high quality but they get the job done.

3) A PiTFT... I got mine from Tronixlabs for $44.95 AUD (including tax). I buy a lot of things from Tronixlabs because I like their service.

4) An enclosure for your PiTFT. Mine cost $12.95AUD.

5) 4 Tactile buttons for your PiTFT/enclosure. $5.50AUD for a pack of 20.

6) A WiFi controller. I grabbed mine from ebay for roughly $3 AUD... they are dirt cheap.

7) A wooden table lamp... I got mine on special from K-Mart for $10 AUD because it had been damaged. So what? I only wanted it for the stand.

8) An SD card... I had one lying around, an 8GB card should work. A quick look around Fleabay (Ebay... or whatever auction sit you use) tells me that you can get them for ~$7AUD. Speed/storage aren't a big concern because we'll only be doing simple things.

Grand total: $38 USD + $5AUD + $44.95 AUD + 12.95 AUD + $5.50 AUD + $10. Roughly $126.40 AUD with one of the items being in USD. The AUD recently crashed significantly. However, at the time I purchased my Pi the AUD and USD were roughly the same so I'm not going to do the conversion. Either way, approximately $100USD.

Step 2: Step 2: Setting Up Your Device (basic Setup)

This will eventually be a wireless unit, but out of the box it's definitely not (and it's a bit of a cow setting things up using a 320x240 display). Personally find it easier to set everything up using a full-sized desktop (mine's a Mac but that's my choice... you can use whatever kind of desktop you like).

Note: Since you're using a PiTFT you cannot use the normal Raspbian (well maybe you can, but there's a modified version that works out of the box). Adafruit provides the correct installation image as well as detailed installation instructions here. I'm going to assume that you either know how to install the OS on your SD card or that using the link provided, you are able to figure it out.

1) Install the modified version of Raspbian (mentioned in the note above) to your SD card.

2) Solder your tactile buttons onto your PiTFT.

3) Plug your PiTFT into your Raspberry Pi.

4) Place your Raspberry Pi (with the PiTFT attached) into the enclosure.

5) Plug your SD card into your raspberry.

6) Plug your wifi controller into your USB port.

7) Plug your Pi into your router using an ethernet cable (it will be wireless once setup, however, I find it easier to configure things remotely using SSH so stick with me on this one).

8) Plug your USB cable into your USB power source and switch on the power. SUCCESS!! (It turns on... right?)

The next step will explain how to setup your software...

Step 3: Step 3: Installing and Configuring Your Software

Now that your machine has started up, you're going to want to get it setup. I personally think the easiest way to do this is to SSH into it (using a terminal) and doing everything remotely. Feel free to use your own preferred method though (e.g. plugging it into a a bigger screen/keyboard/mouse or plugging a USB keyboard/mouse into your new 320x240 screen). For SSH, do the following

1) Open up a Terminal (I'm on a Mac, but you could do this on a Linux box... maybe Windows too?)

2) Find out the internal IP of your Pi using your router's 'view connected DHCP clients' functionality. Typically this will involve pointing a web browser to, logging in as admin and checking which internal IP your raspberry uses. I think it will also have the default name 'raspberrypi'. Need to double check that one, but if you can't be bothered finding the internal IP then try using raspberrypi instead of the IP.

3) In your terminal enter ssh pi@[IP Address] (e.g. without the quotes... 'ssh pi@192.168.1.*'

4) When asked for a password, enter 'raspberry'. You're in and have complete control over your pi!!!

5) Enter sudo raspi-config and set things up. My personal suggestion is to Expand Filesystem, Change User Password, setup your Internationalisation Options, Overclock (the new boards are pretty stable I find and should be able to hack the turbo setting but your board... your risk... your call...etc) also in Advanced Options change your Memory Split (in my opinion 16MB of VRAM is all you'll need... the most demanding graphical program you'll be using is a pong screensaver). Oh and in Advaned Options change your hostname if you like. I made mine 'hueberry' and that means I no longer need to go searching for my IP every time I SSH in or VNC in.

6) Select 'Enable Boot to Desktop/Scratch' and select 'Desktop Log in as user 'pi' at the graphical desktop'. Select Finish and reset your machine. You will then need to SSH back into it (once it has reset) however, if all went well, you should now be able to look at the Pi's screen and see that it has booted into the desktop.

You will now need to install the following apps using apt-get (I'll list them so that I don't forget anything):

- wicd... I might be special, however, I just couldn't get the darn built-in WiFi to work and connect to the network at startup. wicd... no worries! There's a guide here that explains how to install and configure wicd.

- tightvncserver... I like being able to access the pi using VNC. Here a guide if you're not sure how to install tightvncserver.

- xscreensaver... optional but I personally like using the 'pong' screensaver as a clock. Simply type:

sudo apt-get remove xscreensaver xscreensaver-data-extra xscreensaver-gl-extra

into your SSH session and it'll be ridgy didge.

- curl.. this will be powering the bulk of your scripts so make sure it's installed!

sudo apt-get install curl

I think that's it, tell me if I left anything out.

Step 4: Step 4: Configure Your Desktop and Make Sure Those Scripts Are Working

Before doing any of this I personally suggest that you reset your pi. Maybe some daemons...etc just need to be reset? I'd personally just reset your machine. Also, if you followed the previous steps correctly, you should now be wireless, so get rid of that ethernet cable.

1) Install VNC Viewer on your computer (works on Mac, Windows and Linux) and login to your Raspberry Pi. A little like SSH, I think this is a better option than plugging in a physical keyboard and mouse. YMMV... to me this is intentionally a single-purpose device so I like the idea of all the setup going on remotely (so that the user doesn't have to deal with it).

2) Delete all of the icons from your desktop aside from the shutdown icon. Realistically you're not going to be using any of them without a bigger display and they just take up space.

3) Right click on your task bar, select Panel Settings and the Panel Preferences should appear. Click the Advanced tab and then click the Minimize panel when not in use checkbox. There! Your task bar is hidden. Close the panel and move on.

4) Open up your Desktop Preferences using the task bar (the task bar will appear when you place your cursor at the bottom of the screen), set the Background [colour] to white and switch wallpaper mode to Fill with background. I dunno... I like the solid colour.

5) NOW... go and pour yourself a beer. You're nearly there and all you need to do now is a bit of scripting!!!

Step 5: Step 5: Do a Bit of Scripting

Before trying to run scripts on your Hue, you're going to need to go through Philips' Getting Started tutorial. This not only teaches you the basics of Hue scripting, but it will also setup your 'newdeveloper' account so that your pi is paired with your Hue's hub. I'll be using 'newdeveloper' in my sample scripts, so they should work out of the box if you follow these instructions.

1) Go back to your Pi's SSH session (or open a new one) you'll do all your scripting using an SSH session.

2) Straight away type sudo mkdir huescripts and then open this directory... cd ~/huescripts

3) Type sudo nano Lights_On.sh and you will be given the opportunity to create a script.

4) Copy and past the following into your 'nano' document. '' Is the internal IP for my Hue's hub... find the internal IP address for your hub and replace with your hue's IP.

curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":100,"sat":120,"hue":0}' curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":100,"sat":120,"hue":0}' curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":100,"sat":120,"hue":0}' curl -H "Accept: application/json" -X PUT --data '{"on":true,"bri":100,"sat":120,"hue":0}'

5) Press ctrl + o (followed by y and then enter). Then quit out of nano by pressing ctrl + x.

6) Now to make a desktop shortcut that will launch your script. Type cd ~/Desktop

7) Create a desktop shortcut using nano... sudo nano Lights_On.desktop

8) I used the following script to turn my lights on...

[Desktop Entry]
Name=Lights On Comment=My comment Icon=/usr/share/pixmaps/openbox.xpm Exec=lxterminal -t "Turning Lighs On" --working-directory=/home/pi/huescripts/ -e ./Lights_On.sh Type=Application Encoding=UTF-8 Terminal=false Categories=None;

9) Same thing as before... ctrl + o and ctrl + x

10) You should now see this script on your Pi's desktop and be able to turn your lights on! However, you'll need to double tap them... to make a single tap suffice, go into the taskbar and open File Manager PCManFM and then select Preferences from the Edit menu. Make sure the box titled open files with single click is checked and you'll be able to open your desktop icons with a single tap.

Step 6: Step 6: the Remaining Scripts...

Here is the logic behind my 'mood' setting. It's an infinite loop and I don't suggest you use it for that reason. However, it shows how you can setup your own conditional statements in Bash. Also, it shows how the colours work when dealing with the Hue. As you can see... my script creates a random number for the x value and slides along the x scale. Experiment and use the colour chart I've uploaded (stolen directly from Philips' API guide).

While I haven't scripted this particularly well, this is the 'dream' of this device if you like. Ideally the plugin structure will allow people to make their own 'moods' and share them online, opening things up a little.

Step 7: Step 7: Cookie, Pong and Farewell Note

We've come to the end of this guide... thanks for reading and please feel free to tell me if anything needs further clarification.

One thing I forgot to talk about is how to setup pong. Earlier you installed xscreensaver. I think that the next step is both cool and adds the functionality of the clock, so it's a really nice touch.

1) In your taskbar find screensaver

2) Select Pong as your screensaver

3) Now the frustrating part...push tab 7 times (because the settings button is waaaaay off the screen due to the size of our screen)

4) Press enter. Now, make sure that the Clock mode box is checked, push tab 6 times and then press enter. Click on Pong again, press tab 3 times and then enter the number of minutes you would like the system to wait before going into pong mode. BOOM! Get rid of the screensaver preferences and pretend I NEVER told you to manipulate a program like that (ideally there's a way to do this all through the CL but I couldn't figure it out and it isn't core functionality for the device so I just did it).

5) Enjoy. You now have a Hueberry... all you need to do now is rip apart your lamp and find a way to mount your pi onto a lamp (my method was really shonky/ad-hoc so I'm not going to go into the dirty details).

Thanks again for reading all the way through this guide and I hope you've at least taken something out of it. I think it's an okay idea and am keen to develop it into something that's a bit cheaper (due to some kind of mass production) and doesn't demand that the user go through all these steps in order to get to their finished product.

Feel free to comment me with comments/suggestions/advice...etc. If you can improve upon any of these methods (which I'm sure you can) then feel free to produce something better (so that I can use it). Until then... this is my favourite device for controlling my Hue! Best of all, it's an 'open' device that runs on your raspberry pi, so can be hacked/modified infinitely.


<p>&quot;Simply type:</p><p>sudo apt-get remove xscreensaver.... &quot;</p><p>It's an old guide, but surely you mean sudo apt-get install</p><p>:)</p>
<p>This is so cool, looks like a port to the future! Definitely has some fun possibilities as well!</p>

About This Instructable




More by Gambizzle:Hueberry 
Add instructable to: