Last active
November 1, 2022 15:05
-
-
Save loudambiance/2d216ec438b0da966e806d2ee71c8330 to your computer and use it in GitHub Desktop.
kasa flicker using python-kasa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Makes a supported Kasa bulb flicker. Wrote for use on Halloween. Uses the python-kasa package.