Philips Hue with python
I chose Philips Hue lights over some other connected lights because it has a great API to control your lights. There is some package that made it easier to use with python.
Installing
Install the huesdk package
pip install huesdk
Connexion
To use the Philips Hue API you need two things. The local ip address of your Hue Bridge and a username. The username is an authentication key that is generated by the bridge.
Bridge IP
Go to https://discovery.meethue.com/, to find the IP of your bridge. We will see something like this :
[{"id":"xxx","internalipaddress":"192.168.1.10","port":443}]
App username
Press the button on your bridge and use the connect()
method to generate the username.
from huesdk import Hue
username = Hue.connect(bridge_ip=YOUR_BRIDGE_IP)
print(username)
Connect
Now you can instantiate a Hue
object
hue = Hue(bridge_ip=YOUR_BRIDGE_IP, username=YOUR_USERNAME)
Lights
The package work in an object-oriented way, with Lights, Group and Schedule objects. Let’s start with the lights.