Skip to content

Instantly share code, notes, and snippets.

@armindocachada
Last active August 9, 2020 11:08
Show Gist options
  • Save armindocachada/540e2dd74776b5d49e247ee6dbf2b3ab to your computer and use it in GitHub Desktop.
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
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