Security. Cloud. Sometimes transit.

Project: Changing Smart Lights with a Raspberry Pi

We used the Raspberry Pi Sense HAT’s joystick to interact with the REST API of the Philips Hue to control hue and brightness of the lights in our space.

In one of our recent meetups we were showing off how quickly you can go from ‘what do I do with my Pi’ to interactive prototype with the Raspberry Pi Sense HAT.

Beyond having a really cool 8x8 LED Matrix and a myriad of sensors, you are also given a joystick input on the device. To me, one of the quickest and most impactful demo applications is showing that the joystick input on the Sense HAT can be used to control your smart home devices. In our case, we wanted to connect and work with a Philips Hue internet connected lightbulb.

To replicate this project:

  1. Set up a Raspberry Pi with Raspbian (extra points for setting up wifi!)
  2. Install the HAT and set up the Raspberry Pi Sense Hat software
  3. Install evdev for joystick use sudo pip3 install evdev (you may need to run sudo apt-get install python3-pip
  4. Set up your Philips Hue lights based upon the instructions provided (use the app at first to make sure they work!)
  5. Go through the getting started steps for the Hue API
  6. Take note of the URL you are using to interact with the light’s hue, as it will be used in our code.
  7. Save the code at the bottom of the page as sense_hue.py
  8. Run python3 sense_hue.py

You should be able to start using the joystick to change the Hue by moving to the left or right and change the brightness by moving the joystick up and down.

Check out the code on github!