Skip to content

Instantly share code, notes, and snippets.

@estesmax
Last active July 30, 2016 18:29
Show Gist options
  • Save estesmax/667a86b06a0305477e047305a0af8da6 to your computer and use it in GitHub Desktop.
Save estesmax/667a86b06a0305477e047305a0af8da6 to your computer and use it in GitHub Desktop.
from phue import Bridge
import colorsys, time, re, random
#setup bridge
b = Bridge('192.168.XXX.XXX') #hue bridge IP address.
b.connect()
# I grouped the different set's of fixtures in the office into arrays
# which made sense based on their physical locaiton in the office.
# The numbers in the array are the same number used in the hue app to identify
# lights in the color picker.
#light configuration
desks = [1,2,3,4]
chandelier = [6,11,7,9,8,12,13,10]
all = [1,2,3,4,6,7,8,9,10,11,12,13]
# hue supports controlling lights in groups, so here I'm defining them
# this is only needed if you want to control your lights in groups
b.create_group('desks', desks)
b.create_group('chandelier', chandelier)
# Here's an experimental function to try to convert RGB values to a format
# which the hue understands, It's not that accurate, and I reccomend not
# using it. RGB simply doesn't translate to the colorspace used by the hue,
# but enjoy this questionalable approximation if you like.
def rgbToHue((r, g, b)):
r = r/255.0
g = g/255.0
b = b/255.0
h, s, v = colorsys.rgb_to_hsv(r, g, b)
data = { 'hue': 0, 'sat': 0, 'bri' : 0 }
data['hue'] = int(h * 65535)
data['sat'] = int(s * 255)
data['bri'] = int(v * 255)
return data
#a function I made to set a light to a color, you can consider this deprecated.
def lightState(color, transition=0):
toColor = color
lightSettings = {
'transitiontime' : transition,
'on' : True,
'sat': rgbToHue(toColor)['sat'],
'hue': rgbToHue(toColor)['hue'],
'bri': rgbToHue(toColor)['bri']}
return lightSettings
# Global base light state signal. This is the color I want the lights to be at
# when no event is occuring. Try matching your office lighting!
baseLightState = {'bri': 120, 'sat': 0, 'transitiontime' : 10, 'on' : True}
# Function sets all lights to the base state.
def baseLights():
b.set_group('chandelier', baseLightState)
b.set_group('desks', baseLightState)
time.sleep(1)
# This is the function used to twinkle the chandelier lights
# it picks two random lights, making sure they're not the same lights.
# Then turns them, with
def blipLight(lightState):
pickedLight = random.randint(0,7)
pickedLightTwo = random.randint(0,7)
while pickedLightTwo == pickedLight:
pickedLightTwo = random.randint(0,7)
b.set_light(chandelier[pickedLight], lightState)
time.sleep(.2)
b.set_light(chandelier[pickedLightTwo], lightState)
time.sleep(.3)
b.set_light(chandelier[pickedLight], baseLightState)
b.set_light(chandelier[pickedLightTwo], baseLightState)
print "blip", pickedLight, pickedLightTwo
# this function parses the production events stream for certain words and
# defines the color to twinkle the lights
def productionEvent(text):
if "signed" in text:
blipLight({'bri': 120, 'sat': 254, 'hue': 28000, 'transitiontime' : 2, 'on' : True})
print "signed"
elif "accepted" in text:
blipLight({'bri': 120, 'sat': 254, 'hue': 40000, 'transitiontime' : 2, 'on' : True})
print "accepted"
elif "registered" in text:
blipLight({'bri': 120, 'sat': 254, 'hue': 14000, 'transitiontime' : 2, 'on' : True})
print "registered"
elif "logged in" in text:
blipLight({'bri': 120, 'sat': 254, 'hue': 20000, 'transitiontime' : 2, 'on' : True})
print "logged in"
else:
# for all uncategorized production events
blipLight({'bri': 200, 'sat': 0, 'transitiontime' : 2, 'on' : True})
print "other production Event"
# this function is the pattern displayed when a tweet appears in the twitter slack channel
def tweetMention():
b.set_light(chandelier[0], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[1], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[0], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[2], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[1], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[3], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[2], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[4], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[3], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[5], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[4], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[6], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[5], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
b.set_light(chandelier[7], {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[6], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
time.sleep(.2)
b.set_light(chandelier[7], {'hue': 43690, 'sat': 0, 'bri': 120, 'transitiontime': 3})
time.sleep(1)
baseLights()
def goodNpsLights():
# But For this function I define the colors I'm going to use. I also
# Used really bad names, as I changed what they were after some tests,
# but never bothered to rename the colors. Note I'm defining the colors
# for use with the rgb function which I don't reccomend, but can work
# if you don't want to deal with the hue values.
green = (120,255,150)
lightGreen = (50, 180, 80)
middlegreen = (25, 140, 40)
b.set_light(chandelier[0], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[1], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[2], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[3], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[4], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[5], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[6], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[7], lightState(lightGreen,2))
time.sleep(.025)
b.set_group('desks', lightState(lightGreen, 1))
time.sleep(.1)
for n in range(3):
# loops 3 times!
# this type of thing could really use a number to iterate through
# for setting the lights in sequence, but I found being explicit
# about each step easier for designing and experimenting
b.set_light(chandelier[0], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[1], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[2], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[3], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[4], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[5], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[6], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[7], lightState(green,2))
time.sleep(.025)
b.set_light(chandelier[0], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[1], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[2], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[3], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[4], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[5], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[6], lightState(lightGreen,2))
time.sleep(.025)
b.set_light(chandelier[7], lightState(lightGreen,2))
time.sleep(.025)
# waits half a second
time.sleep(.5)
# returns lights back to baseline
baseLights()
def badNpsLights():
# event played when we're rated poorly on the internet
# set all the lights on the desks to red
b.set_group('desks', {'hue' : 0, 'sat' : 254, 'transitiontime' : 5, 'on' : True })
# The chandelier then flickers. This code looks annoyingly long and could be done with a loop,
# but it's useful to define each step in the animation.
b.set_light(chandelier[7], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.25)
b.set_light(chandelier[7], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[3], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.25)
b.set_light(chandelier[7], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[3], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.25)
b.set_light(chandelier[3], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : False })
time.sleep(.25)
b.set_light(chandelier[3], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[7], {'hue' : 0, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.2)
# returns lights back to base state
baseLights()
def newSignUp():
# event when a new company signs up on eShares
# All lights are set to blue
b.set_group('chandelier', {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 5})
b.set_group('desks', {'hue': 43690, 'sat': 254, 'bri': 254, 'transitiontime': 5})
time.sleep(.5)
# green blips flicker through the chandelier.
# Note that I'll set a light to turn green, wait slightly longer than it's transition time,
# then turn it back to blue as I'm turning the next light in the sequence.
b.set_light(chandelier[2], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[1], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[0], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[4], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[5], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[6], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[7], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[7], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[2], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[3], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[3], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[1], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[0], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[4], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[5], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[6], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[7], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[7], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[2], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[3], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[3], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[1], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[0], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[4], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[5], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[6], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[7], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[7], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[2], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[2], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[1], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[1], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[0], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[0], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[4], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[4], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[5], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[5], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[6], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[6], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
b.set_light(chandelier[7], {'hue' : 25574, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.025)
b.set_light(chandelier[7], {'hue' : 43690, 'sat' : 254, 'transitiontime' : 2, 'on' : True })
time.sleep(.2)
baseLights()
def goLive():
# when a company get's on board and stock certificates are sent out!
for i in range(3):
# the lights flash pink and green.
# the chandelier is organized such that with this pattern it looks like bulbs are blinking in stripes
b.set_light(chandelier[0], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
b.set_group('desks', {'hue': 60535, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[2], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[1], {'bri' : 254, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[3], {'bri' : 254, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[4], {'bri' : 254, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[5], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[7], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[6], {'bri' : 200, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
# ========
b.set_group('desks', {'hue': 25574, 'sat': 254, 'bri': 254, 'transitiontime': 3})
b.set_light(chandelier[0], {'bri' : 200, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[2], {'bri' : 200, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[1], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[3], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[4], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[5], {'bri' : 200, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[7], {'bri' : 200, 'sat': 254, 'hue': 25574, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
b.set_light(chandelier[6], {'bri' : 254, 'sat': 254, 'hue': 60535, 'transitiontime' : 3, 'on' : True })
time.sleep(.05)
# return to default light state
baseLights()
def successfulImport():
# When a user imports a cap table with no errors.
# This turns the chandiler into a rainbow, stepping up the lights.
# I step throught the hue gamut, for each light.
b.set_light(chandelier[0], {'hue': 0, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[1], {'hue': 7857, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[2], {'hue': 15714, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[3], {'hue': 23571, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[4], {'hue': 31428, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[5], {'hue': 39285, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[6], {'hue': 47142, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.05)
b.set_light(chandelier[7], {'hue': 55000, 'sat': 254, 'bri': 254, 'transitiontime': 3})
time.sleep(.3)
b.set_group('chandelier', {'sat': 254, 'bri': 128, 'transitiontime': 10} )
time.sleep(1)
baseLights()
def huePoint(color):
# Splits the spectrum up by the number of lights in the chandiler to get
# an evenly spaced rainbow of colors
color = int(color%len(chandelier))
hue = 65535 / len(chandelier)
hue = hue * color
return hue
def partyLights(cycles):
# our party function, it takes in a number of cycles as an argument, which I arbitrarily defined
# as 16 lights getting blinked.
# it sets a random light, the next step in the rainbow, defined using the huePoint function
cycles = cycles * 16
lastLight = None
for i in range(cycles):
whichLight = random.randint(0,len(chandelier)-1)
while lastLight == whichLight:
whichLight = random.randint(0,len(chandelier)-1)
b.set_light(chandelier[whichLight], {'hue': huePoint(i), 'sat': 254, 'bri': 254, 'transitiontime': 1})
lastLight = whichLight
time.sleep(.05)
for i in range(len(chandelier)):
b.set_light(chandelier[i], {'sat': 0, 'bri': 120, 'transitiontime': 3})
time.sleep(.2)
baseLights()
def fatalImport():
# after a cap table is imported and we can't interpret it, this event happens
# it does a cascade of reddish colors across the lamps.
b.set_group('desks', {'hue': 7500, 'sat': 254, 'bri': 200, 'transitiontime': 3})
b.set_light(chandelier[7], {'hue': 7500, 'sat': 200, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[6], {'hue': 6428, 'sat': 210, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[5], {'hue': 5357, 'sat': 220, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[4], {'hue': 4285, 'sat': 230, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[3], {'hue': 3214, 'sat': 240, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[2], {'hue': 2142, 'sat': 254, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[1], {'hue': 1071, 'sat': 254, 'transitiontime': 2})
time.sleep(.025)
b.set_light(chandelier[0], {'hue': 0, 'sat': 254, 'transitiontime': 2})
time.sleep(.2)
baseLights()
def brokenImport():
# turns all lights reddish, then flash white
b.set_group('desks', {'hue': 7500, 'sat': 254, 'bri': 200, 'transitiontime': 3})
b.set_group('chandelier', {'hue': 7500, 'sat': 254, 'bri': 200, 'transitiontime': 3})
time.sleep(.35)
b.set_group('desks', {'hue': 7500, 'sat': 0, 'bri': 240, 'transitiontime': 1})
b.set_group('chandelier', {'hue': 7500, 'sat': 0, 'bri': 240, 'transitiontime': 1})
time.sleep(.15)
baseLights()
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# THIS IS WHERE SLACK MESSAGES COME IN
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# The rtmbot.py plugins, use this function here to process messages
def process_message(data):
# data refers to the contents of any message in any channel your bot is
# invited to.
print data
# You can use the following print statements to review whats in the contents
# of a message.
## print all the different types of information sent with a slack message
# print data.keys()
## Get the ID of a bot user
# print data.get('bot_id')
## Get the ID of a channel
# print data.get('channel')
## Get the attachments of a message
# print data.get('attachments')
## Get the text of a message
# print data.get('text')
## Note messages from other bots are often written as attachments, which are
## different to select from since attachments are in an array. You may need
## to do something like this to get the text out of some bot messages.
# text = data.get('attachments')[0].get('text')
# ==============
# save your channel, bot, and user IDs as variables here.
# remember your bot must be invited to a channel to recieve messages from it.
autobots = 'C0972B6KZ'
twitter = 'C0J6ARVV2'
captableimporter = 'C0D752R4Z'
twitterBot = 'B0J6G9DQX'
production = 'C02ALBQFX'
# to parse messages for key words I have a pile of 'if' statements here.
# The general syntax is like this. Python does substring matching easily
# out of the box. So using a conditional like this can work in quite a lot
# of cases.
# if "text" is in data.get('text'):
# myLightFunction()
# Conditionals can be combined if you want to specify only a certain channel or
# user/bot's messages will be interpreted.
# if "text" is in data.get('text') and data.get('channel') == "C0XXXXXXZ":
# myLightFunction()
# if "text" is in data.get('text') and data.get('bot_id') == "B0XXXXXXZ":
# myLightFunction()
# We use a few regex tricks on our lights to interpret messages from slack
# and take specific numbers out of the messages. I didn't write these, and
# frankly regex frightens me. It's used in the NPS and party light examples
# below. Copypasta those and google fu as you see fit. Maybe call your
# favorite engineer.
if data.get('attachments') is not None and data.get('channel') == captableimporter:
print "Cap table importer", data.get('attachments')
text = str(data.get('attachments'))
if text is not None:
if "successfully imported" in text:
successfulImport()
if "fatal error" in text:
fatalImport()
if "Broken spreadsheet" in text:
brokenImport()
if data.get('attachments') is not None and data.get('channel') == production:
text = data.get('attachments')[0].get('text')
if text is not None:
productionEvent(text)
if data.get('text') is not None and data.get('channel') == autobots:
# is an NPS response
npsSearch = re.compile("NPS: ([1-9]|10) \(new\)")
npsMessage = npsSearch.search(data.get('text'))
if npsMessage is not None:
npsResult = int(npsMessage.group(1))
#is a good NPS
if npsResult > 8:
goodNpsLights()
print "good nps"
if npsResult < 5:
badNpsLights()
print "bad nps"
else:
baseLights()
signUpSearch = re.compile("Signed up:")
signedUp = signUpSearch.search(data.get('text'))
if signedUp is not None:
print "somebody signed up"
newSignUp()
wentLiveSearch = re.compile("Went live:")
wentLive = wentLiveSearch.search(data.get('text'))
if wentLive is not None:
goLive()
print "somebody went live"
# for testing tweet mentions
if "Test mention" in data.get('text'):
tweetMention()
print "tweet mention test"
if "successfully imported" in data.get('text'):
successfulImport()
print "successful import test"
if "Fatal import" in data.get('text'):
fatalImport()
print "fatal import test"
if "broken import" in data.get('text'):
brokenImport()
print "fatal import test"
partySearch = re.findall("(p|P)arty time: (\d+)", data.get('text'))
if partySearch:
partyTime = int(partySearch[0][1])
partyLights(partyTime)
print "some party", partyTime
if data.get('bot_id') == twitterBot and data.get('channel') == twitter:
tweetMention()
print "eShares was mentioned"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment