Skip to main content

Python module to talk to Philips Hue.

Project description

Aiohue

Asynchronous library to control Philips Hue

Requires Python 3.8+ 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.6.3.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

aiohue-2.6.3-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiohue-2.6.3.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for aiohue-2.6.3.tar.gz
Algorithm Hash digest
SHA256 ce9c240ca3eb1394c56503b403589f4d0ee7f93445a578b78da8b7879a65c863
MD5 dc425625d2c6995852f0c28155ce139a
BLAKE2b-256 f698fdd80deb4afff964f6c7f7e41d2bea258258cd12911308ce742d0add41a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiohue-2.6.3-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for aiohue-2.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78c8d9bf7517a3a8e074a99c0327106da09a0ada75385ef98acc8e2902b721af
MD5 5fea1badc12bb39e33c5d7589db7397d
BLAKE2b-256 ffd7c1fa5687f1d4749f23babe27d8f50ba28c052487cbb1b1b677ec2707c656

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