Skip to content

Instantly share code, notes, and snippets.

@KidA001
Created February 26, 2021 18:05
Show Gist options
  • Save KidA001/1bde9b0bce1daba884e63cecbb7362cf to your computer and use it in GitHub Desktop.
Save KidA001/1bde9b0bce1daba884e63cecbb7362cf to your computer and use it in GitHub Desktop.
DELAY_RANGE_START = 3
DELAY_RANGE_END = 6
def shuffler(array):
random.shuffle(array)
return array
def chunks(array, n):
"""Splits array into chunks"""
for i in range(0, len(array), n):
yield array[i:i + n]
def firefly():
lights = [1, 2, 3, 4, 5, 6, 7, 8, 9]
random_chunks = list(chunks(shuffler(lights), 3))
for pair in random_chunks:
rand_delay = random.uniform(DELAY_RANGE_START, DELAY_RANGE_END)
for light_num in pair:
light = 'light.fairy_light_{}'.format(light_num)
turn_off(light)
time.sleep(rand_delay)
for light_num in pair:
light = 'light.fairy_light_{}'.format(light_num)
turn_on(light)
time.sleep(0.200)
time.sleep(0.700)
def turn_on(light):
service_data = { "entity_id": light, "brightness_pct": 50 }
hass.services.call("light", "turn_on", service_data, False)
def turn_off(light):
service_data = { "entity_id": light }
hass.services.call("light", "turn_off", service_data, False)
firefly()
firefly()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment