Skip to content

jkampich1411/PyHue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI - Python Version PyPI PyPi - Downloads DocsImage

Python3 Module for controlling Philips Hue lights.

Quick Start Guide:

Installation:

without VirtualENV:

python3 -m pip install py3-PyHue

with VirtualENV:

Windows:

.\<envname>\Scripts\python.exe -m pip install py3-PyHue

Linux:

./<envname>/bin/python3 -m pip install py3-PyHue

Setup:

Here you have 2 options: Either the Auto-Discovery or the manual setting!

Auto-Discovery:

    from PyHue import *
    bridge = Bridge()

Manual:

    from PyHue import *
    bridge = Bridge(ip='<your ip address>')

Now a new instance of the Hue class is created. If you already used this package, you will notice, that the package will automagicaly connect to the Hue bridge. To restart the discovery process, stop the Python3 script and delete the file '.cached_ip_important' from the root directory (i.e. There, where the main script is located).

After a bridge was discovered, the authentication process will start. You will have to press the button on the front of the Bridge. After that, press the enter key to proceed. After this process you will have a new file '.cached_username_important' in the root directory.

Now you can start coding!

Usage:

All of the available methods are described in the documentation! (It's linked above! You should really check it out!)

To list all lights, you can use this!:

    from PyHue import *
    bridge = Bridge()
    print(bridge.get_all_lights())

But for example, to toggle the light with the id '1', you can use the following code:

    from PyHue import *
    bridge = Bridge()
    
    light = Lights(bridge, 1)
    light.toggle_power()

To turn the light on, use this: (In this case using light-id '1' again)

    from PyHue import *
    bridge = Bridge()

    light = Lights(bridge, 1)
    light.power = True

    # or to turn it off:
    light.power = False 

Finally, if you want to make custom API-Requests, you should use this:

    from PyHue import *
    bridge = Bridge()
    print(bridge.api_request('<METHOD>', '<ENDPOINT>', <body (dict)>))

Happy Coding!

More information is in the Docs linked above!