Skip to content

Instantly share code, notes, and snippets.


hnykda/ Secret

Last active Oct 23, 2020
What would you like to do?
import requests
from yeelight import Bulb
from concurrent.futures import ThreadPoolExecutor
from fastapi import FastAPI
app = FastAPI()
async def read_root():
"""IFTTT variant: takes about 3 seconds after the switch is toggled to toggle lights.
Unfortunately, Shelly cannot reach external IP addresses for some reason, then there wouldn't
be a need for this server :-(
return "ok"
def toggle_bulb(bulb: Bulb):
return bulb.toggle()
async def yeelight():
"""Is close to immediate"""
a = Bulb("") # you have to change these to your bulb addresses
b = Bulb("")
with ThreadPoolExecutor(2) as executor: # just to switch them concurrently
res =, [a, b])
return res

This comment has been minimized.

Copy link
Owner Author

@hnykda hnykda commented Oct 23, 2020

The way to run it on e.g.

sudo uvicorn --reload main:app --port 80 --host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment