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 mainloop(): lan = LifxLAN(NUM_LIGHTS) currently_on = is_master_online() while True: state = is_master_online() if state: print("Master is up!") if not currently_on: print("Turning on all lights.") lan.get_devices_by_group(GROUP_NAME).set_power(True, IN_DURATION) currently_on = state time.sleep(1) else: print("Master is down!") if currently_on: print("Turning off all lights.") lan.get_devices_by_group(GROUP_NAME).set_power(False, OUT_DURATION) currently_on = state
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')
# Default port: if __name__ == '__main__': retry_attempts = 5 retry_count = 0 # Doing developing on the front end while not near a LIFX Bulb? Set this flat to True! NOT_NEAR_BULBS = False print("Starting Impression App") lifx = LifxLAN(20) while True: # get devices try: # if reconnect_to_bulbs(): devices = lifx.get_devices_by_group("Forest") # # previous_state = "default" if devices: print "Operating with {} LIFX Bulbs".format( len(devices.devices)) # These pseudo groups are used because we are unable to create new groups at the theater space single_group = [lifx.get_device_by_name(single_group_name)] for light_name in middle_light_names: middle_group.append(lifx.get_device_by_name(light_name)) active_bulbs = devices.devices setWaveformsOnGroup(active_bulbs, "starkwhite", "all") app.run(use_reloader=False)
try: print("One on!") officeOne.set_power("on", duration=5000) sleep(1) print("Two on!") officeTwo.set_power("on", duration=4000) sleep(1) print("Three on!") officeThree.set_power("on", duration=3000) sleep(1) except: print("Exception ocurred.") lifx = LifxLAN(7) officeLightGroup = lifx.get_devices_by_group("Office") officeLights = officeLightGroup.get_device_list() officeOne = lifx.get_devices_by_name("Office One") officeTwo = lifx.get_devices_by_name("Office Two") officeThree = lifx.get_devices_by_name("Office Three") if len(officeLights) < 3: print(f"Did not discover all office lights! ({len(officeLights)} of 3)") devices = lifx.get_lights() print("\nFound {} light(s):\n".format(len(devices))) for d in devices: try: print(d) except: pass sys.exit(-1)
#Instantiate lifxlan lifxlan = LifxLAN() #Setup for master light for power state polling lightmac1 = "YOU_LIGHT_MAC_ADDRESS_GOES_HERE (AA:AA:AA, etc.)" lightIP1 = "YOUR_LIGHT_IP_ADDRESS_GOES_HERE" #Setup GPIO pins as BCM (Broadcom). Physical pin for PIR sensor input is 16. GPIO.setmode(GPIO.BCM) GPIO.setup(23, GPIO.IN, GPIO.PUD_DOWN) #Set the master light variables required for polling. Called as 'doorlight'. doorlight = Light(lightmac1, lightIP1) #Set the group of lights to control. Other option is to send to all lights, but this affects everyroom on the network. officelights = lifxlan.get_devices_by_group("Office") #This entire thing was hacked together. Ideally I would like it to not check for power so often as to minimize network traffic to the lights. I'm still thinking how to do this. Something maybe like 'Check for motion, if no motion then loop. If motion then turn lights on.' #But then how would the lights get turned off when there's no motion? #Also, I'm not sure if the 'now' and 'dt_string' variables are needed every time before a print. I have a feeling that if they're not then it would read once globally and that would be the value. A possible option is to look into turning the date/time variables into a function and calling that everytime? def Main(): while True: i = GPIO.input(23) if i == 0: #When output from motion sensor is LOW now = datetime.now() dt_string = now.strftime("%m/%d/%Y %H:%M:%S") print dt_string, "No Motion Detected. Pin reads", i while True: try: powerstatus = Light.get_power(doorlight)
Hue = Hue + 1 Hue = int(Hue * 65535) else: Saturation = 0 Hue = 0 #return (Hue, Saturation, int(Brightness), Temperature) # Dynamic brighness return (Hue, Saturation, int(65535 / 8), Temperature) # Fixed brightness print("Initizalizing lights") lifx = LifxLAN(2) #lights = lifx.get_color_lights() #print (lights) g = lifx.get_devices_by_group("Eettafel") # get lights in group #print (g) last = "" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.bind(("", port)) print("waiting on port:", port) try: while True: d = s.recvfrom(3) new = bytearray(d[0]) hsbk = RGBtoHSBK(new) if new != last: #for light in lights: