-
-
Save hnykda/126f682c7a0edad8c4f8cca714309d55 to your computer and use it in GitHub Desktop.
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 requests | |
from yeelight import Bulb | |
from concurrent.futures import ThreadPoolExecutor | |
from fastapi import FastAPI | |
app = FastAPI() | |
@app.get("/") | |
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 :-( | |
""" | |
requests.get("https://maker.ifttt.com/trigger/bedroom_switch/with/key/XXX") | |
return "ok" | |
def toggle_bulb(bulb: Bulb): | |
return bulb.toggle() | |
@app.get("/yl") | |
async def yeelight(): | |
"""Is close to immediate""" | |
a = Bulb("192.168.0.172") # you have to change these to your bulb addresses | |
b = Bulb("192.168.0.136") | |
with ThreadPoolExecutor(2) as executor: # just to switch them concurrently | |
res = executor.map(toggle_bulb, [a, b]) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The way to run it on e.g. 192.168.0.121