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 __init__(self, mode: LEDControlMode = LEDControlMode.AUDIO_STEREO_MIX, rgb_buffer_len: int = 8, alpha_buffer_length=8, silence_buffer_length=1.5): self.mode = mode if self.mode == LEDControlMode.AUDIO_STEREO_MIX: self.controller = AudioController() self.audio_stream = AudioStream( audio_device=AudioInputDevices.STEREO_MIX, chunk=self.controller.nperseg) elif self.mode == LEDControlMode.MONITOR_COLOR: self.controller = MonitorColorController() rgb_buffer_len = 2 self.hue_buffer = deque([0 for _ in range(rgb_buffer_len)], maxlen=rgb_buffer_len) self.alpha_buffer = deque([2 for _ in range(alpha_buffer_length)], maxlen=alpha_buffer_length) self.silence_buffer = deque( [ 'music' for _ in range( int(silence_buffer_length / self.controller.nperseg * self.controller.fs)) ], maxlen=int(silence_buffer_length / self.controller.nperseg * self.controller.fs)) self.state = 'music' # scan available LED devices scanner = BulbScanner() scanner.scan(timeout=4) print("Found LED controllers:") [print(bulb) for bulb in scanner.found_bulbs] self.bulbs = [] for bulb in scanner.found_bulbs: bulb_info = scanner.getBulbInfoByID(bulb['id']) self.bulbs.append(WifiLedBulb(bulb_info['ipaddr']))
def command_handler(sentence, info): scanner = BulbScanner() coms, classify = commands() msg = sentence + " is not a know flux lightbulb command" function = None print("scanner scan: ", end="") print(scanner.scan(timeout=4)) try: #specific ID/MAC of bulb my_light = scanner.getBulbInfoByID("D8F15BA2EE72") except: msg = "flux lightbulb not detected!" return msg, function print("success!") bulb = WifiLedBulb(my_light["ipaddr"]) for i in coms[0]: #lightbulb color changer res = parse(i, sentence) if res: msg, function = colorChanger(bulb, res[0]) return msg, function if sentence in coms[1]: #turn lightbulb off msg = "turning the flux lightbulb off" function = bulb.turnOff() return msg, function if sentence in coms[2]: #turn the lightbulb on msg = "turning the flux lightbulb on" function = bulb.turnOn() return msg, function for i in coms[3]: #change brightness of lightbulb res = parse(i, sentence) if res: msg, function = brightnessChanger(bulb, res[0]) return msg, function return msg, function
def __init__(self, mode: LEDControlMode = LEDControlMode.AUDIO_STEREO_MIX, rgb_buffer_len: int = 5): self.mode = mode if self.mode == LEDControlMode.AUDIO_STEREO_MIX: self.controller = AudioController() self.audio_stream = AudioStream( audio_device=AudioInputDevices.STEREO_MIX, chunk=self.controller.nperseg) elif self.mode == LEDControlMode.MONITOR_COLOR: self.controller = MonitorColorController() rgb_buffer_len = 2 self.rgb_buffer = { 'r': deque([255 for _ in range(rgb_buffer_len)], maxlen=rgb_buffer_len), 'g': deque([255 for _ in range(rgb_buffer_len)], maxlen=rgb_buffer_len), 'b': deque([255 for _ in range(rgb_buffer_len)], maxlen=rgb_buffer_len) } # scan available LED devices scanner = BulbScanner() scanner.scan(timeout=4) print("Found LED controllers:") [print(bulb) for bulb in scanner.found_bulbs] self.bulbs = [] for bulb in scanner.found_bulbs: bulb_info = scanner.getBulbInfoByID(bulb['id']) self.bulbs.append(WifiLedBulb(bulb_info['ipaddr']))
""" import os import sys import time from itertools import cycle this_folder = os.path.dirname(os.path.realpath(__file__)) sys.path.append(this_folder) from flux_led import WifiLedBulb, BulbScanner, LedTimer scanner = BulbScanner() scanner.scan(timeout=4) # Specific ID/MAC of the bulb to set bulb_info = scanner.getBulbInfoByID('6001948A4F89') print "bulb_info: " + str(bulb_info) bulb = WifiLedBulb(bulb_info['ipaddr']) color_time = 2 # 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)
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"
def autoScan(): scanner = BulbScanner() scanner.scan(timeout=4) bulb_info = scanner.getBulbInfoByID('ACCF235FFFFF') return bulb_info
p = pyaudio.PyAudio() # start the PyAudio class stream = p.open(format=pyaudio.paInt16, channels=1, rate=RATE, input=True, frames_per_buffer=CHUNK) #uses default input device # Find the bulb on the LAN scanner = BulbScanner() scanner.scan(timeout=4) r = 0 g = 0 b = 0 # Specific ID/MAC of the bulb to set bulb_info = scanner.getBulbInfoByID('ACCF235FFFFF') if bulb_info: bulb = WifiLedBulb(bulb_info['ipaddr']) bulb.setRgb(255, 0, 0, persist=False) # create a numpy array holding a single read of audio data while True: #to it a few times just to see data = np.fromstring(stream.read(CHUNK), dtype=np.int16) dataL = data[0::2] dataR = data[1::2] peakL = np.abs(np.max(dataL) - np.min(dataL)) / maxValue peakR = np.abs(np.max(dataR) - np.min(dataR)) / maxValue #print("L:%00.02f \tR:%00.02f"%(peakL*100, peakR*100)) data = data * np.hanning(len(data)) # smooth the FFT by windowing data fft = abs(np.fft.fft(data).real)