Skip to content

Instantly share code, notes, and snippets.

@loudambiance
Last active November 1, 2022 15:05
Show Gist options
  • Save loudambiance/2d216ec438b0da966e806d2ee71c8330 to your computer and use it in GitHub Desktop.
Save loudambiance/2d216ec438b0da966e806d2ee71c8330 to your computer and use it in GitHub Desktop.
kasa flicker using python-kasa
import asyncio
from kasa import SmartBulb
from random import *
async def main():
previous=100;
current=100;
bulb = SmartBulb("192.168.1.179")
while True:
y = randint(0,1)
await bulb.update()
#randomly get new brightness
if y == 1: #big jump
x = randint(-100, 100)
else: #little jump
x = randint(-15, 15)
current = previous + x
#ensure values are valid
if current > 100:
current = 100
elif current < 5:
current = 5
previous = current
await bulb.set_brightness(current,transition=400)
await asyncio.sleep(0.5)
if __name__ == "__main__":
asyncio.run(main())
@loudambiance
Copy link
Author

Makes a supported Kasa bulb flicker. Wrote for use on Halloween. Uses the python-kasa package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment