Package: huesdk
huesdkPython package to control the Philips Hue lights.Make the usage of the Philips Hue API 1.0 easier with an object-oriented structure.Installationpip install huesdkDiscoveryTo find the IP of your hue bridge, go tohttps://discovery.meethue.com. Or alternatively,fromhuesdkimportDiscoverdiscover=Discover()print(discover.find_hue_bridge())Sincehttps://discovery.meethue.comanddiscover.find_hue_bridge()are rate limited
and require an internet connection, you can also search for bridges locally using mDNS:fromhuesdkimportDiscoverdiscover=Discover()print(discover.find_hue_bridge_mdns(timeout=5))ConnexionfromhuesdkimportHue# For the first usage# Press your bridge button# the connect method will return a usernameusername=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 buttonhue=Hue(bridge_ip=YOUR_BRIDGE_IP,username=YOUR_USERNAME)# Turn on all the lightshue.on()# Turn off all the lightshue.off()LightsGet all light objectslights=hue.get_lights()# Print light propertiesforlightinlights:print(light.id_)print(light.name)print(light.is_on)print(light.bri)print(light.hue)print(light.sat)# turn on each lightsforlightinlights:light.on()Get single light# get light with idlight=hue.get_light(id_=1)# get light with namelight=hue.get_light(name="Room 1")Lights methodslights=hue.get_lights()# turn onlights[0].on()# turn offlights[0].off()# Change color# with hue, red=65535, green=21845 and blue=43690lights[0].set_color(hue=43690)# with hexadecimallights[0].set_color(hexa="#065535")# Change brightness, from 1 to 254lights[0].set_brightness(254)# Change light's namelights[0].set_name("Hue color lamp 2")# Change saturation, from 1 to 254lights[0].set_saturation(254)TransitionsFor each change, you can set a transition time.
This is given as a multiple of 100ms.
Sotransition=10will 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 5secslight.off(transition=50)# the light will be red after 10 secondslight.set_color(hexa="#ff0000",transition=100)GroupsThe same methods are available for groupsGet all group objectsgroups=hue.get_groups()# Print light propertiesforgroupingroups:print(group.id_)print(group.name)# turn on each groupsforgroupingroups:groups.on()Get single group# get group with idgroup=hue.get_group(id_=1)# get group with namegroup=hue.get_group(name="kitchen")Groups methodsgroups=hue.get_groups()# turn ongroups[0].on()# turn offgroups[0].off()# Change brightness, from 1 to 254groups[0].set_brightness(value)# Change group's namegroups[0].set_name("Hue color lamp 2")# Change saturation, from 1 to 254groups[0].set_saturation(value)TransitionsTransitions are also available for groups.group=hue.get_group(name="kitchen")group.off(transition=1000)SchedulesGet all schedules objectsschedules=hue.get_schedules()# Print schedules propertiesforscheduleinschedules:print(schedule.id_)print(schedule.name)print(schedule.description)print(schedule.status)print(schedule.command)Schedules methodsschedules=hue.get_schedules()# Change nameschedules[0].set_name("Schedules 0")# Change descriptionschedules[0].set_description("Schedules 0")# Deleteschedules[0].delete()