Skip to content

A Python library for the Philips Hue system

License

Notifications You must be signed in to change notification settings

stefan-kuepper/phue

 
 

Repository files navigation

phue: A Python library for Philips Hue

Full featured Python library to control the Philips Hue lighting system.

Features

  • Compliant with the Philips Hue API 1.0
  • Support for Lights
  • Support for Groups
  • Support for Schedules
  • Support for Scenes
  • Support for Sensors
  • Compatible with Python 2.6.x and upwards
  • Compatible with Python 3
  • No dependencies
  • Simple structure, single phue.py file
  • Work in a procedural way or object oriented way

Installation

Using distutils

sudo easy_install phue

or

pip install phue

Manually

phue consists of a single file (phue.py) that you can put in your python search path or in site-packages (or dist-packages depending on the platform) You can also simply run it by putting it in the same directory as you main script file or start a python interpreter in the same directory. phue works with Python 2.6.x, 2.7.x and 3.x

Examples

Basic usage

Using the set_light and get_light methods you can control pretty much all the parameters :

#!/usr/bin/python

from phue import Bridge

b = Bridge('ip_of_your_bridge')

# If the app is not registered and the button is not pressed, press the button and call connect() (this only needs to be run a single time)
b.connect()

# Get the bridge state (This returns the full dictionary that you can explore)
b.get_api()

# Prints if light 1 is on or not
b.get_light(1, 'on')

# Set brightness of lamp 1 to max
b.set_light(1, 'bri', 254)

# Set brightness of lamp 2 to 50%
b.set_light(2, 'bri', 127)

# Turn lamp 2 on
b.set_light(2,'on', True)

# You can also control multiple lamps by sending a list as lamp_id
b.set_light( [1,2], 'on', True)

# Get the name of a lamp
b.get_light(1, 'name')

# You can also use light names instead of the id
b.get_light('Kitchen')
b.set_light('Kitchen', 'bri', 254)

# Also works with lists
b.set_light(['Bathroom', 'Garage'], 'on', False)

# The