📅  最后修改于: 2023-12-03 14:46:03.237000             🧑  作者: Mango
Python pyhue is a Python library for controlling Philips Hue lights. With this library, programmers can easily integrate the control of Hue lights into their Python applications.
Easy-to-use: Python pyhue provides a simple and intuitive API for controlling Philips Hue lights. You can easily turn lights on/off, adjust brightness, and change colors with just a few lines of code.
Customizable: The library allows customization of light attributes such as brightness, color temperature, and RGB color values. You can create dynamic lighting effects or synchronize the lights with other applications.
Group management: Python pyhue supports group management, allowing you to control multiple lights together. You can create groups of lights and control them as a single unit.
Bridge discovery: The library includes automatic bridge discovery functionality, making it effortless to connect to Philips Hue bridges on the local network.
To install Python pyhue, you can use pip:
pip install pyhue
Make sure you have Python 3.x installed on your system before installing the library.
To get started with Python pyhue, you need to follow these steps:
Discover Bridges: Use the pyhue.discover_bridges()
function to discover Philips Hue bridges on the local network. This function returns a list of bridge IP addresses.
Connect to Bridge: Choose a bridge from the discovered bridges and create a bridge object using the pyhue.Bridge(ip_address)
constructor.
Authentication: If not previously authenticated, you need to press the link button on the Hue bridge and use the bridge.authenticate()
method to authenticate your application.
Control Lights: Once authenticated, you can use various methods and properties of the bridge object to control the Hue lights. For example, you can turn on/off lights with light.on = True
or light.on = False
, adjust brightness with light.brightness = 50
, and change the color with light.xy = [0.5, 0.4]
.
Here are some examples to illustrate the usage of Python pyhue:
import pyhue
bridges = pyhue.discover_bridges()
bridge = pyhue.Bridge(bridges[0])
if not bridge.authenticated:
bridge.authenticate()
lights = bridge.get_lights()
# Turn on all lights
for light in lights:
light.on = True
# Change the color of a selected light
selected_light = lights[0]
selected_light.xy = [0.5, 0.4] # Set coordinates of the desired color
# Adjust brightness of all lights in a group
group = bridge.get_group(1)
group.brightness = 100
# Create a dynamic lighting effect
import time
while True:
for light in lights:
light.on = True
light.brightness = 50
light.xy = [0.5, 0.4]
time.sleep(1)
light.on = False
time.sleep(1)
For more detailed documentation, please refer to the Python pyhue GitHub repository.
Python pyhue simplifies the integration of Philips Hue lights into Python applications. It provides an easy-to-use API for controlling lights, supports group management, and offers customization options for creating dynamic lighting effects. Whether you want to automate your home lighting or create interactive lighting effects for your application, Python pyhue is the perfect library to use.