Giter Club home page Giter Club logo

huesdk's Introduction

huesdk

Python package to control the Philips Hue lights.

Make the usage of the Philips Hue API 1.0 easier with an object-oriented structure.

Installation

pip install huesdk

Discovery

To find the IP of your hue bridge, go to https://discovery.meethue.com. Or alternatively,

from huesdk import Discover
discover = Discover()
print(discover.find_hue_bridge())

Connexion

from huesdk import Hue
# For the first usage 
# Press your bridge button
# the connect method will return a username
username = Hue.connect(bridge_ip=YOUR_BRIDGE_IP)

# You can now create an instance of the Hus class, 
# next you won't need to press the button
hue = Hue(bridge_ip=YOUR_BRIDGE_IP, username=YOUR_USERNAME)

# Turn on all the lights
hue.on()

# Turn off all the lights
hue.off()

Lights

Get all light objects

lights = hue.get_lights()

# Print light properties
for light in lights:
    print(light.id_)
    print(light.name)
    print(light.is_on)
    print(light.bri)
    print(light.hue)
    print(light.sat)

# turn on each lights
for light in lights:
    light.on()

Get single light

# get light with id
light = hue.get_light(id_=1)

# get light with name
light = hue.get_light(name="Room 1")

Lights methods

lights = hue.get_lights()

# turn on
lights[0].on()

# turn off
lights[0].off()

# Change color 
# with hue, red=65535, green=21845 and blue=43690
lights[0].set_color(hue=43690)

# with hexadecimal
lights[0].set_color(hexa="#065535")

# Change brightness, from 1 to 254
lights[0].set_brightness(254)

# Change light's name
lights[0].set_name("Hue color lamp 2")

# Change saturation, from 1 to 254
lights[0].set_saturation(254)

Transitions

For each change, you can set a transition time. This is given as a multiple of 100ms. So transition=10 will make the transition last 1 second. The default value is 4 (400ms).

light = hue.get_light(name="kitchen")

# the light will slowly turn off in 5secs
light.off(transition=50)

# the light will be red after 10 seconds
light.set_color(hexa="#ff0000", transition=100)

Groups

The same methods are available for groups

Get all group objects

groups = hue.get_groups()

# Print light properties
for group in groups:
    print(group.id_)
    print(group.name)

# turn on each groups
for group in groups:
    groups.on()

Get single group

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

# get group with name
group = hue.get_group(name="kitchen")

Groups methods

groups = hue.get_groups()

# turn on
groups[0].on()

# turn off
groups[0].off()

# Change brightness, from 1 to 254
groups[0].set_brightness(value)

# Change group's name
groups[0].set_name("Hue color lamp 2")

# Change saturation, from 1 to 254
groups[0].set_saturation(value)

Transitions

Transitions are also available for groups.

group = hue.get_group(name="kitchen")
group.off(transition=1000)

Schedules

Get all schedules objects

schedules = hue.get_schedules()

# Print schedules properties
for schedule in schedules:
    print(schedule.id_)
    print(schedule.name)
    print(schedule.description)
    print(schedule.status)
    print(schedule.command)

Schedules methods

schedules = hue.get_schedules()

# Change name
schedules[0].set_name("Schedules 0")
# Change description
schedules[0].set_description("Schedules 0")

# Delete
schedules[0].delete()

huesdk's People

Contributors

alexisgomes avatar jsalter2013 avatar kellerkind84 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.