Philips Hue with python

Python philips hue
Source unsplash

Installing

pip install huesdk

Connexion

Bridge IP

[{"id":"xxx","internalipaddress":"192.168.1.10","port":443}]

App username

from huesdk import Hue
username = Hue.connect(bridge_ip=YOUR_BRIDGE_IP)
print(username)

Connect

hue = Hue(bridge_ip=YOUR_BRIDGE_IP, username=YOUR_USERNAME)

Lights

# Get all the lights connected to the bridge
lights = hue.get_lights()
# get a single light with id
light = hue.get_light(id_=1)

# get light with name
light = hue.get_light(name="Room 1")
light.id_
light.name
light.is_on
light.bri # Brightness from 1 to 254
light.hue # the color with a value between 0 and 65535
light.sat # Saturation from 1 to 254
# turn on
light.on()

# turn off
light.off()

# Change color
# with hue, red=65535, green=21845 and blue=43690
light.set_color(hue=43690)

# with hexadecimal
light.set_color(hexa="#065535")

# Change brightness
light.set_brightness(254)

# Change light's name
light.set_name("Hue color lamp 2")

# Change saturation
light.set_saturation(254)
# the light will slowly turn off in 5secs
light.off(transition=50)
# the color's light will transition from the current color to red in 10seconds
light.set_color(hexa="#ff0000", transition=100)

Groups

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

# get group with name
group = hue.get_group(name="kitchen")
group.on()
group.off(transition=40)
group.set_brightness(value)
group.set_name("Hue color lamp 2")
group.set_saturation(value)
group.set_color(hexa="#065535", transition=100)

--

--

--

I work at yper. I’m a python developer, learning data science. I’ve made a www.blindfoldchesstactic.com app

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Reverse Engineering Sphero R2D2 With Javascript

Your first Augmented Reality app with Vuforia and Unity Engine

How to set up Lumen with Doctrine

CS371p Fall 2021: Sruthi Rudravajjala

WebSockets Demystified, Part 1: Understanding the Protocol

Deploying Django websites on Apache

Meet the Team: Imre Dobos

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexis Gomes

Alexis Gomes

I work at yper. I’m a python developer, learning data science. I’ve made a www.blindfoldchesstactic.com app

More from Medium

Exception Handling Python

How python is used in automation?

Robot Framework in Python

Adding local dependency to a python project