SHARE
TWEET

Untitled

a guest Jul 19th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. from phue import Bridge
  4. import threading
  5. import random
  6. import time
  7.  
  8. b = Bridge('ip')
  9. # b.connect() #Comment out after first run
  10.  
  11. lights = b.lights
  12.  
  13. # Hue: 0 to 65535
  14. # Saturation: 0 (Black) to 254 (White)
  15. # Brightness: 1 to 254
  16. # Transition time: deciseconds (100ms)
  17.  
  18. fire_effect = [
  19.     {
  20.         "hue": 0, # Red
  21.         "saturation": 126, # Center
  22.         "brightness": 180,
  23.         "fade_in": 12,
  24.     },
  25.     {
  26.         "hue": 3822, # Orange
  27.         "saturation": 126,
  28.         "brightness": 200,
  29.         "fade_in": 5
  30.     },
  31.     {
  32.         "hue": 9284, # Yellow
  33.         "saturation": 126,
  34.         "brightness": 250,
  35.         "fade_in": 3
  36.     },
  37.     {
  38.         "hue": 3822, # Orange
  39.         "saturation": 126,
  40.         "brightness": 200,
  41.         "fade_in": 2
  42.     },
  43.     {
  44.         "hue": 9284, # Yellow
  45.         "saturation": 126,
  46.         "brightness": 250,
  47.         "fade_in": 1
  48.     },
  49.     {
  50.         "hue": 3822, # Orange
  51.         "saturation": 126,
  52.         "brightness": 200,
  53.         "fade_in": 1
  54.     },
  55.     {
  56.         "hue": 0, # Red
  57.         "saturation": 126,
  58.         "brightness": 180,
  59.         "fade_in": 3
  60.     }
  61. ]
  62.  
  63. def play_scene(scene, light, start_index):
  64.     original_state = {
  65.         "on": light.on,
  66.         "brightness": light.brightness,
  67.         "hue": light.hue,
  68.         "saturation": light.saturation
  69.     }
  70.     light.on = True
  71.     for step in range(len(scene)):
  72.         i = ((step+start_index)%len(scene))
  73.         command = {
  74.             "transitiontime": (scene[i]["fade_in"] * 10)if "fade_in" in scene[i] else light.transitiontime,
  75.             "hue": scene[i]["hue"] if "hue" in scene[i] else light.hue,
  76.             "sat": scene[i]["saturation"] if "saturation" in scene[i] else light.saturation,
  77.             "bri": scene[i]["brightness"] if "brightness" in scene[i] else light.brightness
  78.         }
  79.         b.set_light(light.light_id, command)
  80.         time.sleep(command["transitiontime"]/10)
  81.  
  82.  
  83.  
  84.  
  85. for l in lights:
  86.     t = threading.Thread(target=play_scene, args=(fire_effect, l, random.randint(0, len(fire_effect))))
  87.     t.start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top