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

TODO

  • Zones Control Class

Download files

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

Source Distribution

python_hue_v2-2.2.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_hue_v2-2.2.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file python_hue_v2-2.2.0.tar.gz.

File metadata

  • Download URL: python_hue_v2-2.2.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for python_hue_v2-2.2.0.tar.gz
Algorithm Hash digest
SHA256 a99a9108c3df382bab0a02aa9c40e90fe32214f461e4e8c5d6af5f660e80370d
MD5 c20e3032fcca2476a76644a62c7c9ef2
BLAKE2b-256 8869c73ae2911eda8a57b5cd37f041f0a093c67b275a40008be8a976a4a7af1e

See more details on using hashes here.

File details

Details for the file python_hue_v2-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: python_hue_v2-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for python_hue_v2-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 95cbacba81dd4fc26849ad0573313b5638d76de6238dedf78374d285cfb76ee5
MD5 7fd07b2bffe137ec78536035c5ffe7e2
BLAKE2b-256 92f30c52dc648c3f14f4e1904b36435407fc4abb3f9dcf33db3e8e867f2e3df1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page