def setBrightness(self, action, device): try: self.debugLog(u"setBrightness: device: " + device.name + u", action:\n" + unicode(action)) bulb = WifiLedBulb(device.address) bulb.refreshState() # get RGB rgb = bulb.getRgb() self.debugLog("RGB Read as: " + str(rgb)) r=rgb[0] g=rgb[1] b=rgb[2] #Convert RGB to HSV #hsb = RGBColor(red, green, blue, rgb_type='wide_gamut_rgb').convert_to('hsv') #hue = int(round(hsb.hsv_h * 1.0)) #saturation = int(round(hsb.hsv_s * 100.0)) #brightness = int(round(hsb.hsv_v * 100.0)) #Change V #Update bulb self.debugLog(u"Setting RGB: " + str(r) + "|" + str(g) + "|" + str(b) ) bulb.setRgb(r,g,b,True,action.actionValue * 2.55) except Exception: t, v, tb = sys.exc_info() self.handle_exception(t,v,tb)
def main(): # Find the bulb on the LAN scanner = BulbScanner() scanner.scan(timeout=4) # Specific ID/MAC of the bulb to set bulb_info = scanner.getBulbInfoByID('ACCF235FFFFF') if bulb_info: bulb = WifiLedBulb(bulb_info['ipaddr']) color_time = 5 # seconds on each color red = (255,0,0) orange = (255,125,0) yellow = (255, 255, 0) springgreen = (125,255,0) green = (0,255,0) turquoise = (0,255,125) cyan = (0, 255, 255) ocean = (0,125,255) blue = (0,0,255) violet = (125, 0, 255) magenta = (255, 0, 255) raspberry = (255, 0, 125) colorwheel = [red, orange, yellow, springgreen, green, turquoise, cyan, ocean, blue, violet, magenta, raspberry] # use cycle() to treat the list in a circular fashion colorpool = cycle(colorwheel) # get the first color before the loop color = next(colorpool) while True: bulb.refreshState() if not bulb.isOn(): # if the bulb isn't on, don't do anything time.sleep(60) continue # set to color and wait bulb.setRgb(*color) time.sleep(color_time) #fade from color to next color next_color = next(colorpool) crossFade(bulb, color, next_color) # ready for next loop color = next_color else: print "Can't find bulb"
def main(): # Find the bulb on the LAN scanner = BulbScanner() scanner.scan(timeout=4) # Specific ID/MAC of the bulb to set bulb_info = scanner.getBulbInfoByID('ACCF235FFFFF') if bulb_info: bulb = WifiLedBulb(bulb_info['ipaddr']) color_time = 5 # seconds on each color red = (255, 0, 0) orange = (255, 125, 0) yellow = (255, 255, 0) springgreen = (125, 255, 0) green = (0, 255, 0) turquoise = (0, 255, 125) cyan = (0, 255, 255) ocean = (0, 125, 255) blue = (0, 0, 255) violet = (125, 0, 255) magenta = (255, 0, 255) raspberry = (255, 0, 125) colorwheel = [ red, orange, yellow, springgreen, green, turquoise, cyan, ocean, blue, violet, magenta, raspberry ] # use cycle() to treat the list in a circular fashion colorpool = cycle(colorwheel) # get the first color before the loop color = next(colorpool) while True: bulb.refreshState() # set to color and wait # (use non-persistent mode to help preserve flash) bulb.setRgb(*color, persist=False) time.sleep(color_time) #fade from color to next color next_color = next(colorpool) crossFade(bulb, color, next_color) # ready for next loop color = next_color else: print "Can't find bulb"
def getBulbStatus(self, deviceId): # Get device status. try: device = indigo.devices[deviceId] bulb = WifiLedBulb(device.address) bulb.refreshState() self.debugLog(str(bulb)) except Exception: t, v, tb = sys.exc_info() self.handle_exception(t,v,tb)
def setPreset(self, action, device): try: self.debugLog(u"setPreset: device: " + device.name + ", action:\n" + unicode(action)) preset = int(action.props.get('preset', 0),0) speed = int(action.props.get('speed', 0),0) bulb = WifiLedBulb(device.address) bulb.refreshState() bulb.setPresetPattern(preset, speed) bulb.turnOn() except Exception: t, v, tb = sys.exc_info() self.handle_exception(t,v,tb)
def actionControlDimmerRelay(self, action, device): try: try: self.debugLog(u"actionControlDimmerRelay called for device " + device.name + u". actionValue: " + str(action) ) except Exception, e: self.debugLog(u"actionControlDimmerRelay called for device " + device.name + u". (Unable to display action or device data due to error: " + str(e) + u")") currentBrightness = device.states['brightnessLevel'] currentOnState = device.states['onOffState'] self.debugLog("current brightness: " + str(currentBrightness)) bulb = WifiLedBulb(device.address) bulb.refreshState() self.debugLog(str(bulb)) # Get key variables command = action.deviceAction ##### TURN ON ##### if command == indigo.kDeviceAction.TurnOn: try: self.debugLog(u"device on:\n%s" % action) except Exception, e: self.debugLog(u"device on: (Unable to display action data due to error: " + str(e) + u")") # Turn it on. bulb.turnOn()
class Led_Strip(switch_base.Switch_Base): def __init__(self, sensorId, sensorName, macAddr): super().__init__(sensorId, sensorName) self.sensorType = "led" self.brightness = 0.0 self.macAddr = macAddr self.ledDevice = None # Find the bulb on the LAN self.scanner = BulbScanner() self.connect() def connect(self): self.scanner.scan(timeout=4) # Specific ID/MAC of the bulb to set bulb_info = self.scanner.getBulbInfoByID(self.macAddr) if bulb_info: self.ledDevice = WifiLedBulb(bulb_info["ipaddr"]) self.ledDevice.refreshState() def reportBrightness(self): if self.mqttClient and self.mqttClient.is_connected(): self.mqttClient.publish( self.mqttHeader + self.sensorId + "/aux/brightness", self.brightness, qos=1, retain=True, ) def setBrightness(self, brightness): self.brightness = brightness newState = brightness > 0.0 if newState != self.state: super().setState(newState) self.reportBrightness() def setState(self, newState, retry=2): if self.ledDevice: if not newState: self.ledDevice.turnOff() self.brightness = 0.0 else: self.ledDevice.turnOn() self.state = newState self.reportState() elif retry: self.connect() self.setState(newState, retry=(retry - 1)) def init(self, mqttHeader, mqttClient): super().init(mqttHeader, mqttClient) self.reportBrightness() topic = self.mqttHeader + self.sensorId + "/aux/setBrightness" mqttClient.subscribe(topic) def on_message(client, obj, msg): try: brightness = utils.parseFloat(msg.payload) assert 0.0 <= brightness <= 1.0 except: logger.error(f"Invalid brightness value: {msg.payload}") return self.setBrightness(brightness) mqttClient.message_callback_add(topic, on_message)
def main(): syslog.openlog(sys.argv[0]) # Change location to nearest city. location = 'San Diego' # Get the local sunset/sunrise times a = Astral() a.solar_depression = 'civil' city = a[location] timezone = city.timezone sun = city.sun(date=datetime.datetime.now(), local=True) if debug: print 'Information for {}/{}\n'.format(location, city.region) print 'Timezone: {}'.format(timezone) print 'Latitude: {:.02f}; Longitude: {:.02f}\n'.format( city.latitude, city.longitude) print('Dawn: {}'.format(sun['dawn'])) print('Sunrise: {}'.format(sun['sunrise'])) print('Noon: {}'.format(sun['noon'])) print('Sunset: {}'.format(sun['sunset'])) print('Dusk: {}'.format(sun['dusk'])) # Find the bulbs on the LAN scanner = BulbScanner() scanner.scan(timeout=4) # Specific ID/MAC of the bulbs to set porch_info = scanner.getBulbInfoByID('ACCF235FFFEE') livingroom_info = scanner.getBulbInfoByID('ACCF235FFFAA') if porch_info: bulb = WifiLedBulb(porch_info['ipaddr']) bulb.refreshState() timers = bulb.getTimers() # Set the porch bulb to turn on at dusk using timer idx 0 syslog.syslog( syslog.LOG_ALERT, "Setting porch light to turn on at {}:{:02d}".format( sun['dusk'].hour, sun['dusk'].minute)) dusk_timer = LedTimer() dusk_timer.setActive(True) dusk_timer.setRepeatMask(LedTimer.Everyday) dusk_timer.setModeWarmWhite(35) dusk_timer.setTime(sun['dusk'].hour, sun['dusk'].minute) timers[0] = dusk_timer # Set the porch bulb to turn off at dawn using timer idx 1 syslog.syslog( syslog.LOG_ALERT, "Setting porch light to turn off at {}:{:02d}".format( sun['dawn'].hour, sun['dawn'].minute)) dawn_timer = LedTimer() dawn_timer.setActive(True) dawn_timer.setRepeatMask(LedTimer.Everyday) dawn_timer.setModeTurnOff() dawn_timer.setTime(sun['dawn'].hour, sun['dawn'].minute) timers[1] = dawn_timer bulb.sendTimers(timers) else: print "Can't find porch bulb" if livingroom_info: bulb = WifiLedBulb(livingroom_info['ipaddr']) bulb.refreshState() timers = bulb.getTimers() # Set the living room bulb to turn on at sunset using timer idx 0 syslog.syslog( syslog.LOG_ALERT, "Setting LR light to turn on at {}:{:02d}".format( sun['sunset'].hour, sun['sunset'].minute)) sunset_timer = LedTimer() sunset_timer.setActive(True) sunset_timer.setRepeatMask(LedTimer.Everyday) sunset_timer.setModeWarmWhite(50) sunset_timer.setTime(sun['sunset'].hour, sun['sunset'].minute) timers[0] = sunset_timer # Set the living room bulb to turn off at a fixed time off_timer = LedTimer() off_timer.setActive(True) off_timer.setRepeatMask(LedTimer.Everyday) off_timer.setModeTurnOff() off_timer.setTime(23, 30) timers[1] = off_timer bulb.sendTimers(timers) else: print "Can't find living room bulb"
def main(): syslog.openlog(sys.argv[0]) # Change location to nearest city. location = 'San Diego' # Get the local sunset/sunrise times a = Astral() a.solar_depression = 'civil' city = a[location] timezone = city.timezone sun = city.sun(date=datetime.datetime.now(), local=True) if debug: print 'Information for {}/{}\n'.format(location, city.region) print 'Timezone: {}'.format(timezone) print 'Latitude: {:.02f}; Longitude: {:.02f}\n'.format(city.latitude, city.longitude) print('Dawn: {}'.format(sun['dawn'])) print('Sunrise: {}'.format(sun['sunrise'])) print('Noon: {}'.format(sun['noon'])) print('Sunset: {}'.format(sun['sunset'])) print('Dusk: {}'.format(sun['dusk'])) # Find the bulbs on the LAN scanner = BulbScanner() scanner.scan(timeout=4) # Specific ID/MAC of the bulbs to set porch_info = scanner.getBulbInfoByID('ACCF235FFFEE') livingroom_info = scanner.getBulbInfoByID('ACCF235FFFAA') if porch_info: bulb = WifiLedBulb(porch_info['ipaddr']) bulb.refreshState() timers = bulb.getTimers() # Set the porch bulb to turn on at dusk using timer idx 0 syslog.syslog(syslog.LOG_ALERT, "Setting porch light to turn on at {}:{:02d}".format(sun['dusk'].hour, sun['dusk'].minute)) dusk_timer = LedTimer() dusk_timer.setActive(True) dusk_timer.setRepeatMask(LedTimer.Everyday) dusk_timer.setModeWarmWhite(35) dusk_timer.setTime(sun['dusk'].hour, sun['dusk'].minute) timers[0] = dusk_timer # Set the porch bulb to turn off at dawn using timer idx 1 syslog.syslog(syslog.LOG_ALERT, "Setting porch light to turn off at {}:{:02d}".format(sun['dawn'].hour, sun['dawn'].minute)) dawn_timer = LedTimer() dawn_timer.setActive(True) dawn_timer.setRepeatMask(LedTimer.Everyday) dawn_timer.setModeTurnOff() dawn_timer.setTime(sun['dawn'].hour, sun['dawn'].minute) timers[1] = dawn_timer bulb.sendTimers(timers) else: print "Can't find porch bulb" if livingroom_info: bulb = WifiLedBulb(livingroom_info['ipaddr']) bulb.refreshState() timers = bulb.getTimers() # Set the living room bulb to turn on at sunset using timer idx 0 syslog.syslog(syslog.LOG_ALERT, "Setting LR light to turn on at {}:{:02d}".format(sun['sunset'].hour, sun['sunset'].minute)) sunset_timer = LedTimer() sunset_timer.setActive(True) sunset_timer.setRepeatMask(LedTimer.Everyday) sunset_timer.setModeWarmWhite(50) sunset_timer.setTime(sun['sunset'].hour, sun['sunset'].minute) timers[0] = sunset_timer # Set the living room bulb to turn off at a fixed time off_timer = LedTimer() off_timer.setActive(True) off_timer.setRepeatMask(LedTimer.Everyday) off_timer.setModeTurnOff() off_timer.setTime(23,30) timers[1] = off_timer bulb.sendTimers(timers) else: print "Can't find living room bulb"
colorwheel = [red, green, blue] # for x in xrange(200): # i = x % 3 # color = colorwheel[i] # print str(color) # bulb.setRgb(*color) # time.sleep(0.1) # use cycle() to treat the list in a circular fashion colorpool = cycle(colorwheel) # get the first color before the loop color = next(colorpool) while True: bulb.refreshState() # set to color and wait # (use non-persistent mode to help preserve flash) print color # bulb.setRgb(*color) # time.sleep(color_time) #fade from color to next color next_color = next(colorpool) crossFade(bulb, color, next_color) # ready for next loop color = next_color