Skip to content

Instantly share code, notes, and snippets.

@dcoles
Created July 17, 2019 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcoles/cb9c69077ecbfcef42d054e6b0eda25c to your computer and use it in GitHub Desktop.
Save dcoles/cb9c69077ecbfcef42d054e6b0eda25c to your computer and use it in GitHub Desktop.
Halloween for Phillips Hue
# Copyright 2013-2018 Sony Interactive Entertainment LLC
import asyncio
import random
from phue import Bridge
b = Bridge('10.128.12.96')
BEDSIDE = b.lights[0]
ALEX = b.lights[1]
LAMP = b.lights[2]
LIVING = b.lights[3]
async def reset(brightness=0x7F):
# Turn on and set brightness to 50%
for l in b.lights:
print(f'Found {l.name}')
l.on = True
l.saturation = 0xFF
l.brightness = brightness
async def flicker(light, on_mean=3.0, off_mean=0.2):
while True:
await asyncio.sleep(random.expovariate(1.0/on_mean))
print(f'Flickering {light.name}')
light.on = False
await asyncio.sleep(random.expovariate(1.0/off_mean))
light.on = True
async def main():
await reset(0x33)
#await reset()
ALEX.brightness = 0x7F
LIVING.brightness = 0xCC
LIVING.hue = 0.74*65535
LIVING.saturation = 0xFF
BEDSIDE.brightness = 0x99
BEDSIDE.hue = 0.13*65535
await asyncio.gather(
flicker(ALEX),
flicker(LAMP, 1.0),
flicker(LIVING),
flicker(BEDSIDE),
)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
except InterruptedError:
pass
loop.stop()
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment