Overview

Skill Level: Any Skill Level

-smart light technology lovers, IoT developers, raspberry pi enthusiast,

Ingredients

- Philips Hue Lights

- Raspberry Pi

- Wifi Dongle (for the Pi)

Step-by-step

  1. Introduction

    The Hue system consists of 3 main components: a bridge, a portal and lights. The bridge – which comes with the Hue system package, abstracts a web service with a set of Restful APIs through which you can communicate with and control the different properties of the bulbs in your lighting system.The lights themselves are connected to the bridge via an open standards protocol called ZigBee Light Link. It is also possible to talk directly to the bulbs without the bridge interface.

    In this project you will learn how you can quickly connect your lighting system to the IBM Watson IoT Platform service using a Raspberry Pi as a connection and messaging interface.

  2. Using Hue Resful APIs

    At the core of the Hue, everything in your system has a unique URL served by the bridge. And using these urls helps you interact bidirectionally with the system only within the same local area network. The base address being:

      http://<bridge IP address>/api.

    In this way you have independent control over the bridge and every bulb in the system. Using this interface you can build interesting applications around the ‘internet of things.’ This interface makes it easy to develop applications that interact with the bulbs with the ony requirement being that your application must be in the same wifi network. Nonetheless, with this tutorial we are able to extend this basic functionality so that the bulbs are universally accessible by any application through the Watson IoT service.

  3. Connecting Lights to a Raspberry Pi

    – Your first step is to discover the bridge ip address. This involves mutiple steps with heirarchical set of fail over techniques summarized in the chart below:

    source: http://www.developers.meethue.com/documentation/hue-bridge-discovery

    – No one of the four different methods is robust enough for ip address discovery.

    – Alternatively you may connect your bridge directly to your Raspberry Pi via its ethernet port using a physical ethernet cable so that the bridge’s networking requirements are met by a private network served by the Raspberry Pi. In this setup, discovery of the Raspberry Pi’s bridge ip address is a one step process using this linux command:

    arp -n 

    This returns a list of devices in the private network with the ‘eth0’ listing containing the ip address that belongs to your bridge.

  4. Controlling Lights from a Raspberry Pi

    – You may use raw HTTP verbs to communicate with the lights to control the brightness, color, density, and other states of the bulbs.

    – Alternatively you can use one of the SDKs developed by Hue and other third party libraries in your favorite language.

    – Here is a sample code snippet using python to connect to a bridge and change color of a bulb to red:

    from beautifulhue.api import Bridge

    bridge = Bridge(device={'ip':bridgeIP}, user={'name':username})

    resource = {'user':{'devicetype': 'beautifulhuetest', 'name': username}}
    response = bridge.config.create(resource)['resource']
    if 'error' in response[0]:

    if response[0]['error']['type'] != 101:
    print 'Unhandled error creating configuration on the Hue'
    sys.exit(response)
    else:
    created = True

     def changeLightOneToRed():
    resource = {'which':1}
    res = bridge.light.get(resource)['resource']['state']['hue'] resource = {'which':1, 'data':{'state':{'hue':65280, 'on':True, 'bri':10}}}
    bridge.light.update(resource)
    return

  5. Connecting Raspberry Pi to Watson IoT service

    – You can search for another tutorial here in remix that shows you how to connect a Raspberry Pi to the Watson IoT service in order to publish commands, events and subscribe to the same objects.

    – Note that using this set up, you are able to remove the barrier to application development that limits functionality of your application to a similar network as the Hue system. You can now develop completetly autonomous and decentralized applications that use the Hue System.

  6. Conclusion

    Using these building blocks you can connect your Philips Hue System to the Watson IoT service which in turn empowers you to scale and build applications as diverese as your imagination can strech in order to publish commands to dynamically control the lights to desired configurations. For instance you can develop a temperature monitoring solution that changes the color of lights based on ambient temperature state of a room, and many more use cases.

Join The Discussion