def initLights(): print "Light Controller v0.1. Made by Yashi Sharma" print "Using McSwindler's python-milight library" controller.send(light.color(milight.color_from_rgb(255, 0, 0), 0)) controller.send(light.color(milight.color_from_rgb(0, 255, 0), 0)) controller.send(light.color(milight.color_from_rgb(0, 0, 255), 0)) controller.send(light.white(0)) controller.send(light.all_off())
def color(self, color=None): '''Get and set color''' if color != None: rgb = milight.color_from_rgb(color[0], color[1], color[2]) self._controller.send(self._lightbulb.color(rgb, self.group)) self._currentColor = color return self._currentColor
def respond(self,msg,sock): splitMsg = msg.msg.split() response="" if splitMsg[0]=='!light': red = int(splitMsg[1]) if red<0: red=0 elif red>255: red=255 green = int(splitMsg[2]) if green<0: green=0 elif green>255: green=255 blue = int(splitMsg[3]) if blue<0: blue=0 elif blue>255: blue=255 self.cont.send(self.light.color(milight.color_from_rgb(red,green,blue),self.lightgroup)) self.lastState = "R"+str(red)+" G"+str(green)+" B"+str(blue) response = "Light changed to R"+str(red)+" G"+str(green)+" B"+str(blue) elif splitMsg[0]=='!disco': self.cont.send(self.light.party('rainbow_jump',self.lightgroup)) self.lastState="Disco Mode" response = "Light switched to disco mode" elif splitMsg[0]=='!swirl': self.cont.send(self.light.party('rainbow_swirl',self.lightgroup)) self.lastState="Rainbow Swirl Mode" response = "Light switched to rainbow swirl mode" elif splitMsg[0]=='!lightgroup': if len(splitMsg)>1: if splitMsg[1].isdigit(): group = int(splitMsg[1]) if group>=1 and group <=4: self.lightgroup=group self.paramsHaveChanged = True response = "Switched to MiLight light group "+str(group) else: response = "Invalid MiLight light group" else: response = "Invalid MiLight light group" else: response = "No MiLight light group provided" ircResponse = "PRIVMSG "+channel+" :"+response+"\n" sock.sendall(ircResponse.encode('utf-8')) return response
def setcolor(ip, port, zone, red, green, blue): red = int(red) green = int(green) blue = int(blue) controller = milight.MiLight( {"host": ip, "port": int(port)}, wait_duration=0.025 ) # Create a controller with 0 wait between commands light = milight.LightBulb(["rgbw"]) # Can specify which types of bulbs to use controller.send(light.color(milight.color_from_rgb(red, green, blue), int(zone))) pyotherside.send( "result", "[INFO] RED=" + str(red) + " GREEN=" + str(green) + " BLUE=" + str(blue), )
def setLight(self, rgb, brightness, group) : self._controller.send(self._light.color(milight.color_from_rgb(*rgb), group)) self.setBrightness(brightness, group)
def setColor(self, rgb, group) : self._controller.send(self._light.color(milight.color_from_rgb(*rgb), group))
def setColourRGB(self, r,g,b): message = self.group.color(milight.color_from_rgb(r,g,b)) self.controller.send(message)
print("waiting on port:", port) light = milight.LightBulb(['rgbw']) #Can specify which types of bulbs to use controller.send(light.on(1)) # Turn on group 1 lights status = "on"; try: while True: d = s.recvfrom(3) new = bytearray(d[0]) # print (colorsys.rgb_to_hls(new[0]/255, new[1]/255, new[2]/255)) if new != last: hls = colorsys.rgb_to_hls(new[0]/255, new[1]/255, new[2]/255); bri = round(100 / 255 * ((new[0]*299) + (new[1]*587) + (new[0]*114)) / 1000) if bri == 0: controller.send(light.color(milight.color_from_rgb(0,0,0), 1)) elif hls[0] == 0 and hls[2] == 0: controller.send(light.color(milight.color_from_rgb(255,255,255), 1)) controller.send(light.brightness(bri, 1)) else: controller.send(light.color(milight.color_from_hls(*hls), 1)) controller.send(light.brightness(bri, 1)) print (bri) last = new except KeyboardInterrupt: print("Exit ...")
def setColor(r, g, b, bulb): controller.send(light.color(milight.color_from_rgb(r, g, b), bulb))
def _calcColor(self, colorTuple): """ calculates hex value for color from colortuple """ return milight.color_from_rgb(*colorTuple)
def setColor(self, color, group=None): """ sets the color tuple """ group = group is None and self.group or group r = self.controller.send(self.light.color(milight.color_from_rgb(*color), group)) logger.debug('Set color to %s (group: %s): %s' % (color, self.group, r))