Skip to main content

Python Hue V2

Python library to control the Philips Hue lighting system for Hue-V2 API.

Features

  • Design for Hue API 2.0

High Level Control

Simple Example

import time
from python_hue_v2 import Hue, BridgeFinder

finder = BridgeFinder()
time.sleep(1)  # wait for search
# Get server by mdns
host_name = finder.get_bridge_server_lists()[0]  # Here we use first Hue Bridge
addresses = finder.get_bridge_addresses()
# or hue = Hue('ip address','app-key')
hue = Hue(addresses[0], 'hue app key')  # create Hue instance

# If you don't have hue-app-key, press the button and call bridge.connect() (this only needs to be run a single time)
# hue = Hue(host_name)
# app_key = hue.bridge.connect() # you can get app_key and storage on disk

lights = hue.lights

for light in lights:
    print(light.on)
    light.on = True
    light.brightness = 80.0

Scenes

You can get scenes from hue bridge.

from python_hue_v2 import Hue

hue = Hue('bridge-ip', 'app-key')

scenes = hue.scenes
for scene in scenes:
    print(scene.id)
    print(scene.data_dict)

Recall scene using active, dynamic_palette, static.

scene = scenes[0]
scene.recall(action='active')

If you want create one scene with light actions in a room:

from python_hue_v2.scene import ActionPost, ScenePost

light_id = []
lights = hue.lights
for light in lights:
    light_id.append(light.light_id)

actions = []
for rid in light_id:
    actions.append(
        ActionPost.create_by_parameters(
            target_rid=rid,
            target_rtype='light',
            on=True,
            brightness=50,
            color_xy=(0.1, 0.3)  # xy color tuple
            # mirek=200 % or use mirek
        )
    )

# Get all rooms, may be empty
rooms = hue.rooms

# ScenePost should have a group property, here we bind with a room

# refer to https://developers.meethue.com/develop/hue-api-v2/api-reference/#resource_scene_post
# Group associated with this Scene. All services in the group are part of this scene. 
# If the group is changed the scene is update (e.g. light added/removed)
scene_post: ScenePost = ScenePost.create_by_parameters(
    actions=actions, name='test', group_rid=rooms[0].id, group_rtype="room"
)
hue.create_scene(scene_post)

Also, you can delete scene by id.

hue.delete_scene('scene-id-example')

Grouped Light

Get group Lights from hue.

from python_hue_v2 import Hue

hue = Hue('bridge-ip', 'app-key')
grouped_lights = hue.grouped_lights

for group in grouped_lights:
    print(group.type)
    # group.on = True
    group.set_state(True, 100, None) 
    group.set_state(on=True, brightness=100, duration_ms=1) # Feature in version 2.0.1
    

Low Level Control

Low level function may be changed when update

You can use some basic functions in this library.

For example, you can use get_lights,set_light or other low level control functions to implement some custom functions.

import time
from python_hue_v2 import Hue

# or hue = Hue('ip address','app-key')
hue = Hue('host_name', 'hue app key')  # create Hue instance
bridge = hue.bridge

bridge.get_lights()
bridge.set_light('id', light_property_name='on', property_value={'on': True})

bridge.get_zones()

Attention

Some API may be de deprecated When major version updates.

  • Grouped light API will be changed after version 2.0.0

Metadata

Release files for python-hue-v2 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-hue-v2 2.3.1
File Size Uploaded Provenance Actions
python_hue_v2-2.3.1.tar.gz 15.1 kB Without provenance Details for python_hue_v2-2.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-hue-v2 2.3.1
File Interpreter ABI Platform Actions
python_hue_v2-2.3.1-py3-none-any.whl Python 3 none any Details for python_hue_v2-2.3.1-py3-none-any.whl

Total release size: 31.6 kB

Release files / python_hue_v2-2.3.1.tar.gz

Download URL python_hue_v2-2.3.1.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5aa6979e2ce987f136060e6abae9486f4ddf0f4f21ce42554bde138168876b7c
BLAKE2b-256 checksum
How to use checksums
e3b10e4c3dfe1ff271b25638eb69587e3611890185483964eb23260ca8f081f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / python_hue_v2-2.3.1-py3-none-any.whl

Download URL python_hue_v2-2.3.1-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c81ff1994cef14de3d6407f073d94b65e4dc8ce865d518356a684464deacc5d
BLAKE2b-256 checksum
How to use checksums
5ead2944a4a479bf886024506a5a6ec22f632eb5751a41b1fe2d262807356468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for python-hue-v2 2.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page