Being friend with Philips Hue lights

This tutorial runs a python script on a raspberry, or the like, and publishes a XMPP JID that you be friend with and then use both XEP 323 read and XEP 325 control. But you can also use plain chat to interact with the lamp through simple chat.

#Preparations you need an environment that can run python scripts.

A JID for each lamp

You need one Jabber ID or JID for short. First setup these accounts for each lamp on your favourite XMPP site for example [jabber.se] or find one on any of the free public and secure XMPP sites

##Get the python code

Clone the philipshue api and SleekXMPP code from github

>$ git clone https://github.com/studioimaginaire/phue.git
Cloning into 'phue'...

>$ git clone -b xep_0323_325 https://github.com/joachimlindborg/SleekXMPP.git
Cloning into 'SleekXMPP'...

start the Hue Api client

The script will try to connect to the local HUE gateway. If it cannot get access the script will ask you to push the connect button. If It is able to connect it will log on to the gateway. It uses the central Philips Hue service to find the IP adress for the gateway

  • Each lamp is known as “individual” so you start one script for each lamp.
  • If you don’t provide an individual you will adress the whole group of lamps connected to the hue gateway

when the script starts the first time you need to press the button on the Philipshue gateway to open access to it. Use a - - debug to get more information

>$ cd SleekXMPP/examples/IoT/
>$ python IoT_PhilipsHueApi.py -j john@your.domain.com -p password -n “John” --individual 1

INFO     Negotiating TLS
INFO     Using SSL version: 3
WARNING  Could not find pyasn1 and pyasn1_modules. SSL certificate COULD NOT BE VERIFIED.
INFO     JID set to:  john@your.domain.com/544301500141697366520183
WARNING  Could not find pyasn1 and pyasn1_modules. SSL certificate
expiration COULD NOT BE VERIFIED.

you can now start chatting with the lamp by sending hi or ? in the chat window.

>$ cd SleekXMPP/examples/IoT/
>$ python IoT_PhilipsHueApi.py -j john@your.domain.com -p password -n “John” --individual 1

INFO     Negotiating TLS
INFO     Using SSL version: 3
WARNING  Could not find pyasn1 and pyasn1_modules. SSL certificate COULD NOT BE VERIFIED.
INFO     JID set to:  john@your.domain.com/544301500141697366520183
WARNING  Could not find pyasn1 and pyasn1_modules. SSL certificate
expiration COULD NOT BE VERIFIED.

giving a debug flag would give more information

Reading a value from a device

We now start a script that continiously reads values from the first.

Writing a value to a device

keep the two scripts above running ans start a third one changing values in the sever device.


Joachim Lindborg

Written by

Updated