def action(self, action, timeout=None): action = action.lower() try: settings.plugins.lights[self.room] except Exception: return try: self.isOpen(80) except Exception: return if not self.post.ack(): return if eval(os.environ['DEBUG']): debug = "[{}] ".format(device_name) else: debug = "" room_name = self.room.capitalize() if room_name.endswith('s'): room_name = room_name[:-1] + "'" + room_name[-1:] chat.post(":bulb: {}Switching {} light {}.".format( debug, room_name, action)) lifxlight = lifxlan.Light( settings.plugins.lights[self.room]['macaddr'], settings.plugins.lights[self.room]['ipaddr']) lifxlight.set_power(action) if timeout is not None: sleep(float(timeout) * 60) lifxlight.set_power('off') self.post.unack()
def toggle(self): try: settings.plugins.lights[self.room] except Exception: return try: self.isOpen(80) except Exception: return if not self.post.ack(): return if eval(os.environ['DEBUG']): debug = "[{}] ".format(device_name) else: debug = "" lifxlight = lifxlan.Light( settings.plugins.lights[self.room]['macaddr'], settings.plugins.lights[self.room]['ipaddr']) if lifxlight.get_power() == 0: action = "on" else: action = "off" room_name = self.room.capitalize() if room_name.endswith('s'): room_name = room_name[:-1] + "'" + room_name[-1:] chat.post(":bulb: {}Switching {} light {}.".format( debug, room_name, action)) lifxlight.set_power(action) self.post.unack()
def get_colour(self): self.__update_local_lights() _light = lifxlan.Light(self.mac, self.ip) hue, saturation, brightness, kelvin = tuple(_light.get_color()) hue = colour_to_float(hue) saturation = colour_to_float(saturation) brightness = colour_to_float(brightness) kelvin = colour_to_float(kelvin, int_min=2500, int_max=9000) return (hue, saturation, brightness, kelvin)
def set_colour(self, hue, saturation, brightness, kelvin): hue = colour_to_int(hue) saturation = colour_to_int(saturation) brightness = colour_to_int(brightness) kelvin = colour_to_int(kelvin, int_min=2500, int_max=9000) colour = [hue, saturation, brightness, kelvin] self.__update_local_lights() _light = lifxlan.Light(self.mac, self.ip) _light.set_color(colour, duration=self.transition_ms)
def status(self): try: settings.plugins.lights[self.room] except Exception: return if eval(os.environ['DEBUG']): debug = "[{}] ".format(device_name) else: debug = "" lifxlight = lifxlan.Light( settings.plugins.lights[self.room]['macaddr'], settings.plugins.lights[self.room]['ipaddr']) room_name = self.room.capitalize() if room_name.endswith('s'): room_name = room_name[:-1] + "'" + room_name[-1:] if lifxlight.get_power() == 0: chat.post(":bulb: {}{} light is off.".format(debug, room_name)) else: chat.post(":bulb: {}{} light is on.".format(debug, room_name))
app.setEntry("Scene 1", config["Scene 1"], callFunction=False) if 'Scene 2' in config: app.setEntry("Scene 2", config["Scene 2"], callFunction=False) if 'Scene 3' in config: app.setEntry("Scene 3", config["Scene 3"], callFunction=False) #print("config['bulbs']:",config['bulbs']) #print("type(config['bulbs']):",type(config['bulbs'])) if os.path.exists(PICKLE): bulbPickle = pkl.load(open(PICKLE, "rb")) #this reads the pickle #print (bulbPickle) bulbList.clear() bulbList.append("-Select Bulb-") for i, bulb in enumerate(bulbPickle): #print ("mac:",bulb['mac']); light = lifxlan.Light(bulb['mac'], bulb['ip']) light.label = bulb['label'] bulbs.append(light) bulbList.append(bulb['label']) if len(bulbs) > 0: app.clearOptionBox("LIFX Bulbs", callFunction=False) app.changeOptionBox("LIFX Bulbs", bulbList, callFunction=False) app.setLabelBg("lbl2", mygreen) app.hideLabel("f1") app.setLabel("lbl2", "Recalled " + str(len(bulbs)) + " bulbs") app.setCheckBox("Select All") #light = Light("12:34:56:78:9a:bc", "192.168.1.42") #print("bulbs:",bulbs) lan = lifxlan.LifxLAN()
def turnOffLampWithLifx(): bulb = lifxlan.Light(MAC, IP) bulb.set_power("off")
def turnOnLampWithLifx(lifxcolor): bulb = lifxlan.Light(MAC, IP) bulb.set_color(lifxcolor) bulb.set_power("on")
from datetime import datetime, timedelta from scipy import signal from multiprocessing import Process, Value import lifxlan import numpy as np FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 BUFFER = 512 light = lifxlan.Light("D0:73:D5:58:62:32", "192.168.2.239") click_min_gap = .1 click_max_gap = .6 def try_action(click, my, actual): time.sleep(click_max_gap) if my != actual.value: return cur = click.value click.value = 0 is_on = light.get_power() if cur == 2: light.set_power(65535 - is_on, 500, True) if cur == 3: if is_on > 0: light.set_power(65535, 0, True)
# LAN import lifxlan light = lifxlan.Light("d0:73:d5:57:cd:ea", "192.168.20.28") light.set_brightness(50000)
import lifxlan as ll import sys """ A small script to control the LIFX light in my room and display it's brightness on the i3blocks bar Arguments: 1. mode: 'get', 'set', 'change' 2. mode (required for set) """ MAX_BRIGHTNESS = 2**16 - 1 lights = { 'Office': ll.Light('D0:73:D5:22:C0:78', '192.168.1.50'), 'Bedroom': ll.Light('D0:73:D5:01:14:BF', '192.168.1.51'), 'Hall': ll.Light('D0:73:D5:2D:5A:D3', '192.168.1.52'), 'Kitchen': ll.Light('D0:73:D5:2D:66:F4', '192.168.1.53'), 'TV': ll.Light('D0:73:D5:25:55:E4', '192.168.1.54'), 'Dining': ll.Light('D0:73:D5:2D:15:AB', '192.168.1.55'), } def set_brightness(level, cur_color, light): """ Sets the brightness of the light to the corresponding value using a range of [0, 100] """ new_brightness = level_to_brightness(level) new_color = (cur_color[0], cur_color[1], new_brightness, cur_color[3])
def make_light(net: dict) -> lifxlan.Light: '''This function builds a lifx light object from a dict containing the mac and ip address of a light''' return lifxlan.Light(net['mac'], net['ip'])
def turn_off(self): self.__update_local_lights() _light = lifxlan.Light(self.mac, self.ip) _light.set_power('off', duration=self.transition_ms)