def find_lights(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number\ of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs # at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in # advance simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) # get devices devices = lifx.get_lights() print("\nFound {} light(s):\n".format(len(devices))) for d in devices: try: print(d) except(): pass
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. lifx = LifxLAN(num_lights) # get devices print("Discovering lights...") devices = lifx.get_lights() print("Found {} lights:".format(len(devices))) for d in devices: print("{} ({}) P: {} (HSBK): {}".format(d.get_label(), d.mac_addr, d.get_power() / 65535, d.get_color()))
def main(): # Get the data from standard in # lines = read_in() num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) # get devices devices = lifx.get_lights() bulb = devices[0] print("Selected {}".format(bulb.get_label())) # get original state # original_power = bulb.get_power() # original_color = bulb.get_color() # TURN BULB ON over time bulb.set_power("on", 20000)
def __init__(self, bulb_mac=None, bulb_ip=None): logging.debug("Initialising LifxController.") self.lan = LifxLAN() self.bulbs = None self.groups = None self.bulb_labels: list = [] self.group_labels: list = [] self.bulb = None self.group = None self.bulb_mac = bulb_mac self.bulb_ip = bulb_ip # Logger config self.logger = logging.getLogger(__name__) self.logger.setLevel(logging.DEBUG) self.ch = logging.StreamHandler() self.ch.setLevel(logging.DEBUG) self.formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s') self.ch.setFormatter(self.formatter) self.logger.addHandler(self.ch) # When loading config, we don't need to discover the bulb if self.bulb_mac and self.bulb_ip: from lifxlan import Light self.bulb = Light(self.bulb_mac, self.bulb_ip)
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) print("Discovering lights...") lifx = LifxLAN(num_lights) devices = lifx.get_lights() bulb = devices[0] print("Making colors happen...") while True: bulb.set_color(WHITE, 15000, False) time.sleep(60) bulb.set_color(BLUE1, 15000, False) time.sleep(60) bulb.set_color(PINK1, 15000, False) time.sleep(60)
def main(): # Knowing the number of bulbs in advance would make initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN() #if len(sys.argv) != 2: # print("NO BUILD STATUS SPECIFIED") # print(" python {} <build status>\n".format(sys.argv[0])) # exit(1) status = sys.argv[1] # find device devices = lifx.get_lights() bulb = [x for x in devices if x.get_label() == "Bedroom Roof"] print("Found device: {}".format(bulb)) if not bulb: print("No bulb found") return bulb = bulb[0] power = bulb.get_power() print(power) if power: print("Power is ON") print(bulb.get_color()) target_color = build_color(status) bulb.set_color(target_color, 0.4)
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, verbose=True) # get devices devices = lifx.get_lights() labels = [] for device in devices: labels.append(device.get_label()) print("Found Bulbs:") for label in labels: print(" " + str(label))
def main(): config = load_config_file() pir_sensor_port = config['pir_sensor_port'] pir = MotionSensor(pir_sensor_port) fade_in_duration = config.get('fade_in_duration', 1000) fade_out_duration = config.get('fade_out_duration', 1000) wake_time = config.get('wake_time', 15 * 1000) lan = LifxLAN() group_name = config.get('group', None) if group_name is not None: group = lan.get_devices_by_group(config['group']) if group is not None: watch_group(group, pir, fade_in_duration, fade_out_duration, wake_time) light_name = config.get('light', None) if light_name is not None: light = lan.get_device_by_name(light_name) if light is not None: watch_device(light, fade_in_duration, fade_out_duration, wake_time) else: print('')
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selected {}".format(strip.get_label())) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_count = len(all_zones) delay = 0.06 snake_color = RED background_color = GREEN snake_size = zone_count/2 # length of snake in zones tail = 0 head = snake_size - 1 try: while True: # Case 1: Snake hasn't wrapped around yet if head > tail: if tail > 0: strip.set_zone_color(0, tail-1, background_color, 0, True, 0) strip.set_zone_color(tail, head, snake_color, 0, True, 0) if head < zone_count - 1: strip.set_zone_color(head+1, zone_count-1, background_color, 0, True, 1) # Case 2: Snake has started to wrap around else: if head > 0: strip.set_zone_color(0, head-1, snake_color, 0, True, 0) strip.set_zone_color(head, tail, background_color, 0, True, 0) if tail < zone_count - 1: strip.set_zone_color(tail+1, zone_count-1, snake_color, 0, True, 1) # update indices for the snake's head and tail tail = (tail+1) % zone_count head = (head+1) % zone_count sleep(delay) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 500, True)
def get_light(label: str) -> Optional[Light]: lan = LifxLAN() lights = lan.get_lights() # need to call get_label as otherwise it's not initialized lights = [l for l in lights if l.get_label() and l.label == label] if len(lights) == 1: return lights[0] return None
def get_lights(): num_lights = 2 lifx = LifxLAN(num_lights) lights = lifx.get_lights() light_dict = {} for light in lights: light_dict[light.get_label()] = light return light_dict
def __init__(self, number_of_devices=1): self.device_controller = LifxLAN(number_of_devices) self.colour = None self.power = None self.reset_color() self.turn_on() if config.PrintLog: print "Light switched on with warm white"
def getBulbInfo(): lifx = LifxLAN(1) try: bulb = lifx.get_lights()[0] except: print("No bulbs found. Exiting.") exit(1) return bulb
def __init__(self, *args, **kwargs): self.devices = LifxLAN(NUM_LIGHTS) sched.add_job(self.get_lights, 'interval', minutes=2, id='get_lights', replace_existing=True) BaseHTTPRequestHandler.__init__(self, *args, **kwargs)
def __init__(self): lifx = LifxLAN() devices = lifx.get_color_lights() if len(devices) < 1: print('not found...') sleep(0.2) devices = lifx.get_color_lights() self.light = devices[0]
def main(): lifx = LifxLAN(3) devices = lifx.get_lights() for d in devices: print("{} ({}) HSBK: {}".format(d.get_label(), d.mac_addr, d.get_color())) if __name__=="__main__": main()
def __update_local_lights(self): refresh = self.last_refresh_time - time.time() > self.refresh_threshold self.last_refresh_time = time.time() if (self.mac is None) or (self.ip is None) or refresh: lifx = LifxLAN() self.lights = lifx.get_lights() for _light in self.lights: self.mac = _light.get_mac_addr() self.ip = _light.get_ip_addr()
def main(version): app = Application() lan = LifxLAN(1) lights = lan.get_lights() for a in lights: a.set_power(0) return app.run(sys.argv)
def main(): lifx = LifxLAN(2) print("Discovering lights") original_powers = lifx.get_power_all_lights() print("Discovered lights") flag = check_flag() if not flag: print("Exiting, flag is off") return for bulb in original_powers: power = original_powers[bulb] flag &= power == 0 if not flag: print("Exiting, some bulb is on") return total_time = 60 #seconds periods = 60 step = 65535 / periods #make the lights dim print("Setting up lights") setup = False count = 1 while not setup and count < 20: try: for bulb in original_powers: bulb.set_brightness(0) bulb.set_saturation(0) bulb.set_hue(0) bulb.set_colortemp(3500) time.sleep(1) bulb.set_power(1) setup = True except Exception as e: print(str(e)) print("Failed setting up lights {} time(s)".format(count)) count += 1 time.sleep(1) for i in range(periods): if check_flag(): for bulb in original_powers: bulb.set_brightness(i * step, rapid=True) print("Set lights to: {}".format(i * step)) time.sleep(total_time / periods) else: print("Exiting, flag turned off mid-run") return print("Success!")
def init_bulb(num_lights=1): """ Initializes the light bulb for use """ lifx = LifxLAN(num_lights) devices = lifx.get_lights() # I have only one Lifx light currently, may change this code in the future bulb = devices[0] return bulb
def get_function(self, message=None): lifx = LifxLAN(1) devices = lifx.get_lights() mac = message.get("mac", "none") for each_buld in devices: print (each_buld.mac_addr) if each_buld.mac_addr == mac: self.bulb = each_buld return self.toggle
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_buff = all_zones ignore = [-1] try: while True: for i in range(12): z = -1 while z in ignore: z = randrange(0, len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 2000, k strip.set_zone_color(z, z, [h, s, 40000, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) for i in range(12): z = -1 while z in ignore: z = randrange(0, len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 65535, k strip.set_zone_color(z, z, [h, s, 65535, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) #sleep(0.25) ignore = [-1] except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True)
def __init__(self): lifx = LifxLAN() devices = lifx.get_color_all_lights() if len(devices) < 1: print('not found...') sleep(0.1) devices = lifx.get_color_all_lights() self.lights = [] for l in devices: if not l.supports_color(): self.lights.append(l)
def main(): print("Discovering lights...") lifx = LifxLAN() # get devices devices = lifx.get_lights() print("\nFound {} light(s):\n".format(len(devices))) for d in devices: try: print(d) except: pass
def main(): num_lights = None if len(sys.argv) != 2: print( "\nDiscovery will go much faster if you provide the number of lights on your LAN:" ) print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. lifx = LifxLAN(num_lights) bulbs = lifx.get_lights() # test power control print("Discovering lights...") original_powers = lifx.get_power_all_lights() original_colors = lifx.get_color_all_lights() print(original_colors) half_period_ms = 2500 duration_mins = 20 duration_secs = duration_mins * 60 print("Breathing...") try: start_time = time() while True: for bulb in original_colors: color = original_colors[bulb] dim = list(copy(color)) half_bright = int(dim[2] / 2) dim[2] = half_bright if half_bright >= 1900 else 1900 bulb.set_color(dim, half_period_ms, rapid=True) sleep(half_period_ms / 1000.0) for bulb in original_colors: color = original_colors[bulb] bulb.set_color(color, half_period_ms, rapid=True) sleep(half_period_ms / 1000.0) if time() - start_time > duration_secs: raise KeyboardInterrupt except KeyboardInterrupt: print("Restoring original color to all lights...") for light in original_colors: color = original_colors[light] light.set_color(color) print("Restoring original power to all lights...") for light in original_powers: power = original_powers[light] light.set_power(power)
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = deepcopy(all_zones) zone_buff = all_zones ignore = [-1] try: while True: for i in range(12): z = -1 while z in ignore: z = randrange(0,len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 2000, k strip.set_zone_color(z, z, [h, s, 40000, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) for i in range(12): z = -1 while z in ignore: z = randrange(0,len(zone_buff)) ignore.append(z) h, s, v, k = zone_buff[z] zone_buff[z] = h, s, 65535, k strip.set_zone_color(z, z, [h, s, 65535, k], 500, True) sleep(0.01) #l.set_zone_colors(zone_buff, 2000, True) #sleep(0.25) ignore = [-1] except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True)
def main(): lifx = LifxLAN(1) devices = lifx.get_lights() count = 0 while len(devices) == 0 and count < 10: sleep(2) devices = lifx.get_lights() count += 1 bulb = devices[0] bulb.set_power("on") bulb.set_color(RED, 10, True) sunrise(bulb, 30, 100)
def main(): lan = LifxLAN() tiles = "" if environ.get('MAC_ADDR') is None and environ.get('IP_ADDR') is None: lights = lan.get_tilechain_lights() if not lights: print("Lights not found.") raise("Lights not found.") print("Lights found:") for light in lights: print(light) tile_number = 0 if environ.get('TILE_NUMBER') is not None: tile_number = os.environ['TILE_NUMBER'] tiles = lights[tile_number] else: mac = environ.get('MAC_ADDR') ip = environ.get('IP_ADDR') tiles = TileChain(mac, ip) # milisecond delay in changing the color color_delay = 1000 # Available colors a = (22573, 65535, 33183, 3500) b = (24029, 65535, 21626, 3500) c = (24426, 61139, 22213, 3500) d = (22068, 35606, 40227, 3500) none = (24426, 12584, 22213, 3500) for i in range(1, 6): if sys.argv[i] == "0": tiles.set_tile_colors(i - 1, [none] * 64, color_delay) elif sys.argv[i] == "1": tiles.set_tile_colors(i - 1, [d] * 64, color_delay) elif sys.argv[i] == "2": tiles.set_tile_colors(i - 1, [c] * 64, color_delay) elif sys.argv[i] == "3": tiles.set_tile_colors(i - 1, [b] * 64, color_delay) elif sys.argv[i] == "4": tiles.set_tile_colors(i - 1, [a] * 64, color_delay)
def attempt_setup (): lan = LifxLAN() # lights = lan.get_devices_by_name(our_lights).get_device_list() lights = lan.get_lights() lights = sorted(lights, key=lambda x: int(x.get_label().replace("A", ""))) names = [ l.get_label() for l in lights ] print("Found the following lights:") for name in names: print(f" - {name}") # assert len(lights) == 10, "We need 10 lights" return lights
def get_lights(light_names=None, group=None): num_lights = 6 # Faster discovery, when specified lan = LifxLAN(num_lights) # Select by Name(s) if group is None: lights = [] # Convert to List if type(light_names) is not list: light_names = [light_names] for light in light_names: for _ in range(5): try: light = lan.get_device_by_name(light) lights.append(light) except: print('trying again') continue else: break else: print('cannot get light: %s' % light) return lights # Select by Group else: for _ in range(5): try: lights = lan.get_devices_by_group(group).devices except: print('trying again') continue else: return lights else: print('cannot get lights')
def update_group(group_id, group_list): logger = logging.getLogger(__name__) lifx = LifxLAN() db = Session() group = db.query(Group_d).filter_by(id=group_id).first() is_new = group.id not in group_list is_updated = group.devices_updated if is_new or is_updated: status = [] if is_new: status.append("New") if is_updated: status.append("Updated") new_group = None try: new_group = GroupExt( lifx.get_devices_by_name( [device.name for device in group.devices] ).get_device_list() ) except WorkflowException: logger.warning( "Group failed - WorkflowException", exc_info=True ) if new_group is not None: status_str = ",".join(status) devices_str = ", ".join( [device.name for device in group.devices] ) logger.info( "{} - Group: {}\nDevices: {}" .format(status_str, group.name, devices_str) ) group_list[group.id] = new_group group.devices_updated = False if len(group.devices) != len(new_group.get_device_list()): # just using this as a flag to force it to try again group.devices_updated = True db.commit() db.close()
def __init__(self, duration_secs=0.5, init_color=0): try: self.bulb = LifxLAN().get_lights()[0] #Get bulb except IndexError: raise ValueError("No LIFX bulb detected") return self.colors = [RED, ORANGE, YELLOW, GREEN, CYAN, BLUE, PURPLE, PINK] self.duration_secs = duration_secs if init_color != 0: self.change_colors(seq='one', color_index=init_color) self.original_color = self.bulb.get_color() self.original_power = self.bulb.get_power()
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. lifx = LifxLAN(num_lights) # test power control print("Discovering lights...") original_powers = lifx.get_power_all_lights() original_colors = lifx.get_color_all_lights() half_period_ms = 2500 duration_mins = 20 duration_secs = duration_mins*60 print("Breathing...") try: start_time = time() while True: for bulb in original_colors: color = original_colors[bulb] dim = list(copy(color)) dim[2] = 1900 bulb.set_color(dim, half_period_ms, rapid=True) sleep(half_period_ms/1000.0) for bulb in original_colors: color = original_colors[bulb] bulb.set_color(color, half_period_ms, rapid=True) sleep(half_period_ms/1000.0) if time() - start_time > duration_secs: raise KeyboardInterrupt except KeyboardInterrupt: print("Restoring original color to all lights...") for light in original_colors: color = original_colors[light] light.set_color(color) print("Restoring original power to all lights...") for light in original_powers: power = original_powers[light] light.set_power(power)
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) # get devices devices = lifx.get_lights() bulb = devices[0] print("Selected {}".format(bulb.get_label())) # get original state original_power = bulb.get_power() original_color = bulb.get_color() bulb.set_power("on") sleep(0.2) # to look pretty print("Toggling power...") toggle_device_power(bulb, 0.2) print("Toggling color...") toggle_light_color(bulb, 0.2) # restore original color # color can be restored after the power is turned off as well print("Restoring original color and power...") bulb.set_color(original_color) sleep(1) # to look pretty. # restore original power bulb.set_power(original_power)
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. lifx = LifxLAN(num_lights) # get devices print("Discovering lights...") devices = lifx.get_lights() for d in devices: print("{} ({}) HSBK: {}".format(d.get_label(), d.mac_addr, d.get_color()))
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights,False) # get devices multizone_lights = lifx.get_multizone_lights() if len(multizone_lights) > 0: strip = multizone_lights[0] print("Selecting " + strip.get_label()) all_zones = strip.get_color_zones() original_zones = all_zones dim_zones = [] bright_zones = [] for [h,s,v,k] in all_zones: dim_zones.append((h,s,20000,k)) bright_zones.append((h,s,65535,k)) try: print("Breathing...") while True: strip.set_zone_colors(bright_zones, 2000, True) sleep(2) strip.set_zone_colors(dim_zones, 2000, True) sleep(2) except KeyboardInterrupt: strip.set_zone_colors(original_zones, 1000, True) else: print("No lights with MultiZone capability detected.")
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) # get devices devices = lifx.get_lights() bulb = devices[0] print("Selected {}".format(bulb.get_label())) # get original state print("Turning on all lights...") original_power = bulb.get_power() original_color = bulb.get_color() bulb.set_power("on") sleep(1) # for looks print("Flashy fast rainbow") rainbow(bulb, 0.1) print("Smooth slow rainbow") rainbow(bulb, 1, smooth=True) print("Restoring original power and color...") # restore original power bulb.set_power(original_power) # restore original color sleep(0.5) # for looks bulb.set_color(original_color)
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights, verbose=True) # get devices devices = lifx.get_lights() labels = [] for device in devices: labels.append(device.get_label()) print("Found Bulbs:") for label in labels: print(" " + str(label))
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) # get devices devices = lifx.get_lights() print("\nFound {} light(s):\n".format(len(devices))) for d in devices: try: print(d) except: pass
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. print("Discovering lights...") lifx = LifxLAN(num_lights) original_colors = lifx.get_color_all_lights() original_powers = lifx.get_power_all_lights() print("Turning on all lights...") lifx.set_power_all_lights(True) sleep(1) print("Flashy fast rainbow") rainbow(lifx, 0.1) print("Smooth slow rainbow") rainbow(lifx, 1, smooth=True) print("Restoring original color to all lights...") for light in original_colors: light.set_color(original_colors[light]) sleep(1) print("Restoring original power to all lights...") for light in original_powers: light.set_power(original_powers[light])
def main(): num_lights = None if len(sys.argv) != 2: print("\nDiscovery will go much faster if you provide the number of lights on your LAN:") print(" python {} <number of lights on LAN>\n".format(sys.argv[0])) else: num_lights = int(sys.argv[1]) # instantiate LifxLAN client, num_lights may be None (unknown). # In fact, you don't need to provide LifxLAN with the number of bulbs at all. # lifx = LifxLAN() works just as well. Knowing the number of bulbs in advance # simply makes initial bulb discovery faster. lifx = LifxLAN(num_lights) # test power control print("Discovering lights...") original_powers = lifx.get_power_all_lights() print("Turning lights on...") lifx.set_power_all_lights("on") print("Toggling power of all lights...") toggle_all_lights_power(lifx, 0.2) print("Restoring power to all lights...") for light in original_powers: light.set_power(original_powers[light]) # test color control original_colors = lifx.get_color_all_lights() print("Turning lights on...") lifx.set_power_all_lights("on") print("Toggling color of all lights quickly...") toggle_all_lights_color(lifx, 0.2) print("Toggling color of all lights slowly...") toggle_all_lights_color(lifx, 0.5) print("Restoring original color to all lights...") for light in original_colors: light.set_color(original_colors[light]) sleep(0.2) print("Restoring original power to all lights...") for light in original_powers: light.set_power(original_powers[light])
"cold_white": COLD_WHITE, "warm_white": WARM_WHITE, "gold": GOLD } error_message = """Usage: python set_color_all.py blue python set_color_all.py 43634 65535 65535 3500 The four numbers are HSBK values: Hue (0-65535), Saturation (0-65535), Brightness (0-65535), Kelvin (2500-9000). See get_colors_all.py to read the current HSBK values from your lights. The available predefined colors are: """ + ", ".join(colors.keys()) lifxlan = LifxLAN() color = None if len(sys.argv) == 2: if sys.argv[1].lower() not in colors: print(error_message) sys.exit() else: color = colors[sys.argv[1].lower()] elif len(sys.argv) == 5: color = [] for (i, value) in enumerate(sys.argv[1:]): try: value = int(value) except: print("Problem with {}.".format(value))
from lifxlan import LifxLAN from phue import Bridge from ouimeaux.environment import Environment from myo import Myo import requests from device_listener import DeviceListener from pose_type import PoseType import time import datetime print('Getting light info') #LIFX LIGHTS SECTIOM print("Finding LIFX lights") num_lights = 2 lifx = LifxLAN(num_lights) devices = lifx.get_lights() #USE THE INFO RETURNED FROM THE DEVICES TO PROPERLY NAME THE LIGHTS (EX. 'Bedroom light') if 'Bedroom' in str(devices[1]): bedside_table_light = devices[0] bedroom_light = devices[1] else: bedside_table_light = devices[1] bedroom_light = devices[0] #PHILLIPS HUE LIGHTS SECTION #FIRST GET THE IP OF THE BRIDGE (use $ nmap -sL 192.168.1.1/24) print('Finding Hue lights')
#!/usr/bin/env python # coding=utf-8 from lifxlan import LifxLAN lifxlan = LifxLAN() lifxlan.set_power_all_lights("on", rapid=True)