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

James’ Programming Journey part 11

Dynamically reloading rails_admin model concerns in development

How I Built My First MERN Stack App in a Week

Simple ways to pass to and share data with widgets/pages

GraphQL - Case Study : KASKUS Groups

Building the Business Case for Test Automation

Lambda Functions Continuous Deployments with GitHub Actions

Python — PIP

the result of pip help command

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

Crop Image to Face with Square Crop in Python

Easier Python Package Deploying

Sorting Algorithms in Python — Radix Sort

How to Update/Partial Update data in Elasticsearch Using Python Client