Skip to main content

Python3 Module for controlling Philips Hue lights

Project description

PyPI - Python Version PyPI 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!

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

py3_PyHue-0.1a7-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page