Skip to main content

A python SDK for the Philips hue API

Project description

huesdk

Python package to control the Philips Hue lights.

Make the usage of the Philips Hue API 1.0 easier with an object-oriented structure.

Installation

pip install huesdk

Discovery

To find the IP of your hue bridge, go to https://discovery.meethue.com. Or alternatively,

from huesdk import Discover
discover = Discover()
print(discover.find_hue_bridge())

Since https://discovery.meethue.com and discover.find_hue_bridge() are rate limited and require an internet connection, you can also search for bridges locally using mDNS:

from huesdk import Discover
discover = Discover()
print(discover.find_hue_bridge_mdns(timeout=5))

Connexion

from huesdk import Hue
# For the first usage 
# Press your bridge button
# the connect method will return a username
username = Hue.connect(bridge_ip=YOUR_BRIDGE_IP)

# You can now create an instance of the Hue class, 
# next you won't need to press the button
hue = Hue(bridge_ip=YOUR_BRIDGE_IP, username=YOUR_USERNAME)

# Turn on all the lights
hue.on()

# Turn off all the lights
hue.off()

Lights

Get all light objects

lights = hue.get_lights()

# Print light properties
for light in lights:
    print(light.id_)
    print(light.name)
    print(light.is_on)
    print(light.bri)
    print(light.hue)
    print(light.sat)

# turn on each lights
for light in lights:
    light.on()

Get single light

# get light with id
light = hue.get_light(id_=1)

# get light with name
light = hue.get_light(name="Room 1")

Lights methods

lights = hue.get_lights()

# turn on
lights[0].on()

# turn off
lights[0].off()

# Change color 
# with hue, red=65535, green=21845 and blue=43690
lights[0].set_color(hue=43690)

# with hexadecimal
lights[0].set_color(hexa="#065535")

# Change brightness, from 1 to 254
lights[0].set_brightness(254)

# Change light's name
lights[0].set_name("Hue color lamp 2")

# Change saturation, from 1 to 254
lights[0].set_saturation(254)

Transitions

For each change, you can set a transition time. This is given as a multiple of 100ms. So transition=10 will make the transition last 1 second. The default value is 4 (400ms).

light = hue.get_light(name="kitchen")

# the light will slowly turn off in 5secs
light.off(transition=50)

# the light will be red after 10 seconds
light.set_color(hexa="#ff0000", transition=100)

Groups

The same methods are available for groups

Get all group objects

groups = hue.get_groups()

# Print light properties
for group in groups:
    print(group.id_)
    print(group.name)

# turn on each groups
for group in groups:
    groups.on()

Get single group

# get group with id
group = hue.get_group(id_=1)

# get group with name
group = hue.get_group(name="kitchen")

Groups methods

groups = hue.get_groups()

# turn on
groups[0].on()

# turn off
groups[0].off()

# Change brightness, from 1 to 254
groups[0].set_brightness(value)

# Change group's name
groups[0].set_name("Hue color lamp 2")

# Change saturation, from 1 to 254
groups[0].set_saturation(value)

Transitions

Transitions are also available for groups.

group = hue.get_group(name="kitchen")
group.off(transition=1000)

Schedules

Get all schedules objects

schedules = hue.get_schedules()

# Print schedules properties
for schedule in schedules:
    print(schedule.id_)
    print(schedule.name)
    print(schedule.description)
    print(schedule.status)
    print(schedule.command)

Schedules methods

schedules = hue.get_schedules()

# Change name
schedules[0].set_name("Schedules 0")
# Change description
schedules[0].set_description("Schedules 0")

# Delete
schedules[0].delete()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

huesdk-1.8-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file huesdk-1.8-py3-none-any.whl.

File metadata

  • Download URL: huesdk-1.8-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for huesdk-1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b3c4c5e1affaf280b6b55cc7cc9fb9040f7e37e35c9f1b2c454eec75e94434c2
MD5 281217a88aa62c7cbaa5672512c83a2a
BLAKE2b-256 945dc0aca0cbe7c5b88c6ea6f60a95866a23ac0ab0dab90d2eaca33520537bfa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page