Last active
August 9, 2020 11:08
-
-
Save armindocachada/540e2dd74776b5d49e247ee6dbf2b3ab to your computer and use it in GitHub Desktop.
Method showing how you can create a lightflow for the Yeelight smart lights using Python
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
def setupWeatherFlow(bulb,weather,durationFlowSeconds=60): | |
""" | |
We use HSV color transitions. In case there is no precipitation, the color will remain static for a minute or two. | |
If there is precipitation, the light will pulse with varying levels of brightness. | |
Depending on the temperature the light will be deep red if it is hot or deep blue if it is freezing. | |
The flow itself will end automatically based on the durationFlowSeconds parameter. | |
""" | |
hue = 0 | |
saturation = 100 | |
if weather['temperatureCode'] == "Hot": | |
hue = 370 | |
elif weather['temperatureCode'] == "Warm": | |
hue = 370 | |
saturation = 41 | |
elif weather['temperatureCode'] == "Fair": | |
hue = 50 | |
elif weather['temperatureCode'] == "Cold": | |
hue = 173 | |
elif weather['temperatureCode'] == "Freezing": | |
hue = 240 | |
if (weather["precipitation"]): | |
if weather["heavyRain"] or weather["heavySnow"]: | |
duration = 100 | |
else: | |
duration = 1000 | |
count = durationFlowSeconds * 1000 / duration | |
transitions = [HSVTransition(hue, saturation, brightness=bright, duration=duration) | |
for bright in range(0, 100, 15)] | |
flow = Flow( | |
count=count, | |
transitions=transitions | |
) | |
else: | |
transitions = [HSVTransition(hue, saturation, brightness=100, duration=1000)] | |
flow = Flow( | |
count=durationFlowSeconds, | |
transitions=transitions | |
) | |
bulb.turn_on() | |
bulb.start_flow(flow) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment