Skip to main content

Python module to talk to Philips Hue.

Project description

Aiohue

Asynchronous library to control Philips Hue

Requires Python 3.5 and uses asyncio and aiohttp.

import asyncio
from pprint import pprint

import aiohttp
from aiohue.discovery import discover_nupnp


async def main():
    async with aiohttp.ClientSession() as session:
        await run(session)


async def run(websession):
    bridges = await discover_nupnp(websession)

    bridge = bridges[0]
    await bridge.create_user('aiophue-example')
    print('Your username is', bridge.username)

    await bridge.initialize()

    print('Name', bridge.config.name)
    print('Mac', bridge.config.mac)

    print()
    print('Lights:')
    for id in bridge.lights:
        light = bridge.lights[id]
        print('{}: {}'.format(light.name, 'on' if light.state['on'] else 'off'))

    # Change state of a light.
    await light.set_state(on=not light.state['on'])

    print()
    print('Groups:')
    for id in bridge.groups:
        group = bridge.groups[id]
        print('{}: {}'.format(group.name, 'on' if group.action['on'] else 'off'))

    # Change state of a group.
    await group.set_action(on=not group.state['on'])


asyncio.run(main())

Timeouts

Aiohue does not specify any timeouts for any requests. You will need to specify them in your own code. We recommend the async_timeout package:

import async_timeout

with async_timeout.timeout(10):
    await bridge.initialize()

Contribution guidelines

Object hierarchy and property/method names should match the Philips Hue API.

Project details


Download files

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

Source Distribution

aiohue-2.3.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

aiohue-2.3.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file aiohue-2.3.0.tar.gz.

File metadata

  • Download URL: aiohue-2.3.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for aiohue-2.3.0.tar.gz
Algorithm Hash digest
SHA256 d36fa57747191b92e77c89c453c792f13b9af8f7ca9610bb4bb46f2636a536f6
MD5 83919f15cdb215a319fd6ddde54f33cb
BLAKE2b-256 3b167f5005e93a44faa641f4d2fdb65a26ae7dc95d52dff3ec1fb0a115bdb7a1

See more details on using hashes here.

File details

Details for the file aiohue-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: aiohue-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for aiohue-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdbcd6613dd1cb117e425803f7c40c9aacfc954c44febca14ed036ca1e9213af
MD5 91e1f52de0e3669c30833c5f0b2b544d
BLAKE2b-256 5137b02ae6a7c55e058fe22d1e6d7c61bacb47448ebb027ca22baeef688c3a70

See more details on using hashes here.

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