def lighting_on(): client = MongoClient("mongodb://ec2-52-89-213-104.us-west-2.compute.amazonaws.com:27017/") db = client["Alfr3d_DB"] devicesCollection = db["devices"] logger.info("looking for devices") for device in devicesCollection.find({"name": "hue"}): logger.info("device found: " + str(device)) logger.info("looking for apikeys") username = config.get("HUE dev", str(device["MAC"]).replace(":", "")) logger.info("found key: " + str(username)) bridge = Bridge(device["IP"], username) logger.info(str(bridge.lights())) lights_data = json.loads(json.dumps(bridge.lights())) for light in lights_data: hue = light_hue() hue.number = light hue.ip = device["IP"] hue.username = username logger.info("all lights on") hue.hue_on()
class HueController: def __init__(self): try: with open('.hueusername') as f: bridge_data = json.loads(f.read()) except: logger.warn("Bridge not authorised, need to press the button!") bridge_data = json.loads( requests.get('https://www.meethue.com/api/nupnp').text)[0] bridge_data['username'] = create_new_username( bridge_data['internalipaddress']) with open('.hueusername', 'w') as f: f.write(json.dumps(bridge_data)) self.bridge = Bridge(bridge_data['internalipaddress'], bridge_data['username']) logger.info("Successfully connected to Hue Bridge {}".format( bridge_data['internalipaddress'])) def print_all_lights(self): rooms = self.bridge.groups() for id, light in self.bridge.lights().items(): room = [r for r in rooms.values() if id in r['lights']] logger.info("[{}]: {} ({}){}".format( id, light['name'], light['type'], " in {}".format(room[0]['name']) if room else "")) def set_light(self, id, *args, **kwargs): self.bridge.lights[id].state(**kwargs) def perform(self, action): self.set_light(action['id'], bri=action['brightness'], hue=action['hue'])
def init_config(): IP = str(input("Please enter your hue bridge IP address: ")) if IP == "": print( 'Visit https://huetips.com/help/how-to-find-my-bridge-ip-address/ to know how to get your bridge IP address' ) sleep(300) username = create_new_username(IP) config = { 'IP': IP, 'username': username, "loops_per_sec": 2.0, "m_sat": 185, "r_sat": 70, "m_bri": 70, "r_bri": 50, "divider": 5, "crop": 1, "bezel": 1 } b = Bridge(config['IP'], config['username']) print('Please enter the number beside the lamp that you want to use :') for lamp in b.lights(): print(lamp, b.lights()[lamp]['name']) print() chosen_light = input() if chosen_light == "": print() print() print( "------- Please enter a number correspond to the desired bulb : -------" ) print() chosen_light = input() print() print() config['chosen_light'] = int(chosen_light) with open(directory + 'config.json', 'w') as fp: json.dump(config, fp)
def lightingOn(): client = MongoClient('mongodb://ec2-52-89-213-104.us-west-2.compute.amazonaws.com:27017/') client.Alfr3d_DB.authenticate(db_user,db_pass) db = client['Alfr3d_DB'] devicesCollection = db['devices'] logger.info("looking for devices") for device in devicesCollection.find({"$and":[ {"type":'lights'}, {"location.name":socket.gethostname()} ]}): logger.info("device found: "+ str(device)) if device['name'].startswith("hue"): logger.info("looking for apikeys") username = config.get("HUE dev", str(device['MAC']).replace(':','')) logger.info("found key: "+ str(username)) bridge = Bridge(device['IP'], username) logger.info(str(bridge.lights())) lights_data = json.loads(json.dumps(bridge.lights())) for light in lights_data: hue = light_hue() hue.number=light hue.ip = device['IP'] hue.username = username logger.info("all lights on") hue.hue_on() elif device['name'].startswith("Lifx"): bulb_label = device['name'] logger.info("looking for apikeys") lifx_token = config.get("Lifx", "token") logger.info("found key: "+ str(lifx_token)) headers = {"Authorization": "Bearer %s" % lifx_token,} response = requests.put('https://api.lifx.com/v1/lights/label:'+bulb_label+'/state', data={"power": "on"}, headers=headers) if response.json()[u'results'][0][u'status'] != u'ok': logger.error("failed to turn off the bulb "+str(bulb_label))
def process(self, inport, msg): hueUser = "******" bridge = Bridge("10.0.0.159", hueUser) converter = Converter() # Convert farbgeber to Hue xy v1xy = converter.rgb_to_xy(msg.data['v1'][0], msg.data['v1'][1], msg.data['v1'][2]) cxy = converter.rgb_to_xy(msg.data['c'][0], msg.data['c'][1], msg.data['c'][2]) contrasted = True # Send to all lights. First light found gets contrast color for lightId in bridge.lights(): if contrasted: bridge.lights[lightId].state(xy=v1xy) contrasted = False else: contrasted = True bridge.lights[lightId].state(xy=cxy) # Send light status out self.send('out', bridge.lights()) self.ack(msg)
class HueLightControler(object): """Class for setting the color of hue bulbs.""" def __init__(self, brige_ip, user): self.bridge = Bridge(brige_ip, user) self.lights = self.bridge.lights() def set_hue_color(self, lightid, red, green, blue): hsv = rgb_to_hsv((red, green, blue)) self.bridge.lights[lightid].state(on=True, hue=round((hsv[0] * 65535) / 360), sat=round(hsv[1] * 255), bri=round(hsv[2] * 255))
class HuePhillipsBridge: def __init__(self, ip, username): self.ipAddress = ip self.username = username self.bridge = Bridge(self.ipAddress, self.username) # Key is the qhue object, value is the HuePhillipsType object self.lights, self.groups, self.zones, self.rooms = {}, {}, {}, {} self.createLights() self.createGroups() def createLights(self): for light in self.bridge.lights().keys(): print(light) self.lights[light] = HuePhillipsLight(self.bridge.lights[light]) def createGroups(self): for group in self.bridge.groups().keys(): realGroup = self.bridge.groups[group] if realGroup()['type'] == 'Zone': self.groups[group] = HuePhillipsZone( realGroup, self.getLightsFromGroup(realGroup)) self.zones[group] = self.groups[group] elif realGroup()['type'] == 'Room': self.groups[group] = HuePhillipsRoom( realGroup, self.getLightsFromGroup(realGroup)) self.rooms[group] = self.groups[group] def getAllLights(self): return list(self.lights.values()) def getLightsFromGroup(self, group): groupLights = [] for light in group()['lights']: groupLights.append(self.lights[light]) return groupLights def getRooms(self): return self.rooms.values() def getZones(self): return self.zones.values() def getGroups(self): return self.groups.values()
class HueController: BRIDGE_IP= '192.168.1.69' username="******" def __init__(self): self.bridge = Bridge(self.BRIDGE_IP, self.username) def setlight(self, lightid='14', on=True, hue=200, bri=128): self.bridge.lights[lightid].state(on=on) if on: self.bridge.lights[lightid].state(bri=bri, hue=hue) def setLightTemp(self, lightid, on=True,ct=300): self.bridge.lights[lightid].state(on=on) if on: self.bridge.lights[lightid].state(ct=ct); def listLights(self): lights = self.bridge.lights() for num, info in lights.items(): if info["state"]["reachable"]: print("{:16} {}".format(info['name'], num))
import sys import os from qhue import Bridge f = open("hue_id.txt", "r") hue_id = f.readlines()[-1].rstrip() f.close() b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP") lights = b.lights command = sys.argv[-1] if (command == 'led_off' or command == 'all_off' or command == 'off'): b.lights(1, 'state', on=False) b.lights(2, 'state', on=False) b.lights(3, 'state', on=False) b.lights(4, 'state', on=False) elif command == 'led_on': b.lights(1, 'state', on=True) b.lights(2, 'state', on=True) b.lights(3, 'state', on=True) b.lights(4, 'state', on=True) elif command == 'dota': b.lights(1, 'state', bri=255, on=True, xy=[0.6065, 0.3095]) b.lights(2, 'state', bri=255, on=True, xy=[0.6883, 0.306]) b.lights(3, 'state', bri=255, on=True, xy=[0.6883, 0.306]) b.lights(4, 'state', bri=255, on=True, xy=[0.6065, 0.3095]) elif command == 'blaze': b.lights(1, 'state', bri=255, on=True, xy=[0.3344, 0.5002])
import os f = open("hue_id.txt", "r") hue_id = f.readlines()[-1].rstrip() f.close() b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP") lights = b.lights brightness = int(sys.argv[-1]) print(int(sys.argv[-1])) if len(sys.argv) < 3: if brightness < 1: b.lights(1, 'state', on=False) b.lights(2, 'state', on=False) b.lights(3, 'state', on=False) b.lights(4, 'state', on=False) else: if brightness > 255: brightness = 255 b.lights(1, 'state', bri=brightness, on=True) b.lights(2, 'state', bri=brightness, on=True) b.lights(3, 'state', bri=brightness, on=True) b.lights(4, 'state', bri=brightness, on=True) else: strip_bri = int(sys.argv[-4]) / 100. * 255 bloom1_bri = int(sys.argv[-3]) / 100. * 255 bloom2_bri = int(sys.argv[-2]) / 100. * 255 strip2_bri = int(sys.argv[-1]) / 100. * 255
class PhilipsHue(object): """docstring for PhilipsHue""" def __init__(self, args, verbose=False): self.verbose = verbose self.bridgeIP = args.get('bridgeIP') self.username = args.get('username') try: from qhue import Bridge except ImportError: exit("For using PhilipsHue is necessary to import it's bibliotec\n\ Please install it with: sudo pip install qhue") self.bridge = Bridge(self.bridgeIP, self.username) self.lights = self.bridge.lights def getNameLights(self): '''A''' # names = [] # for key, values in self.bridge.lights().iteritems(): # names.append(values.get('name')) names = {} for key, values in self.bridge.lights().iteritems(): names[key] = { 'display_name': values.get('name'), 'function': values.get('name') } # names.append(values.get('name')) # { # "4": { # "display_name": "Test", # "display_description": "Testing function", # "function": "test_function" # } # } return names def toggle(self, lightNum): '''A''' if self.verbose: print("\nPhilipsHue.toggle(%s)" % lightNum) if str(lightNum) in self.lights(): if self.verbose: print("PhilipsHue light %s found..." % lightNum) if self.lights[lightNum]().get('state').get('reachable'): if self.verbose: print('light %s reachable...' % lightNum) if self.lights[lightNum]().get('state').get('on'): print('light %s OFF' % lightNum) self.lights[lightNum].state(on=False) else: print('light %s ON' % lightNum) self.lights[lightNum].state(on=True) else: if self.verbose: print('light %s NOT reachable...' % lightNum) else: if self.verbose: print( "ERROR: PhilipsHue with number %s dosen't exist..." % lightNum) def getLightFunctions(self, lightNum): '''A''' if self.verbose: print("PhilipsHue.getLightFunctions(%s)" % lightNum) light = self.lights().get(lightNum) light_functions = ['Toggle', 'On', 'Off'] if light.get('type') == 'Dimmable light': light_functions.append('Dimm Down') light_functions.append('Dimm Up') # I don't have a RGB light, but it should be done here elif light.get('type') == 'Hue': import pdb pdb.set_trace() light_functions.append('Hue Change') else: # TODO import pdb pdb.set_trace() return light_functions
class HueStation: def __init__(self, lights=None, hub=None): self.config = Config().get("hue") self.client = Bridge(self.config["ip"], self.config["username"]) self.light_names = lights self.get_lights() def get_lights(self): if self.light_names is None: self.lights = [ self.client.lights[_id] for _id in self.client.lights().keys() ] elif self.light_names not in self.config["lights"]: available_lights = list(self.config["lights"].keys()) available_lights = " or ".join(available_lights) error_msg = f"Lights could not be found. Maybe you meant {available_lights}?" raise Exception(error_msg) else: self.lights = [ self.client.lights[id] for id in self.config["lights"][self.light_names] ] def change_colour(self, rgb, brightness=100): # brightness [0, 100] -> [0, 255] brightness = round(brightness / 100 * 255) xy = HueStation.rgb_to_xy(rgb) for light in self.lights: light.state(on=True, xy=xy, bri=brightness) def go_green(self, brightness=100): self.change_colour((0, 128, 0), brightness) def go_red(self, brightness=100): self.change_colour((255, 0, 0), brightness) def go_yellow(self, brightness=100): self.change_colour((255, 255, 0), brightness) def turn_off(self): for light in self.lights: light.state(on=False) @staticmethod def rgb_to_xy(rgb): R, G, B = [colour / 255 for colour in rgb] R = math.pow( (R + 0.055) / (1.0 + 0.055), 2.4) if R > 0.04045 else R / 12.92 G = math.pow( (G + 0.055) / (1.0 + 0.055), 2.4) if G > 0.04045 else G / 12.92 B = math.pow( (B + 0.055) / (1.0 + 0.055), 2.4) if B > 0.04045 else B / 12.92 X = R * 0.664511 + G * 0.154324 + B * 0.162028 Y = R * 0.283881 + G * 0.668433 + B * 0.047685 Z = R * 0.000088 + G * 0.072310 + B * 0.986039 x = X / (X + Y + Z) y = Y / (X + Y + Z) return [x, y]
class HueController(BaseController): def init(self, *args, **kwargs): try: with open('.hueusername') as f: bridge_data = json.loads(f.read()) except: self.log("Bridge not authorised, need to press the button!", logging.WARN) bridge_data = json.loads( requests.get('https://www.meethue.com/api/nupnp').text)[0] bridge_data['username'] = create_new_username( bridge_data['internalipaddress']) with open('.hueusername', 'w') as f: f.write(json.dumps(bridge_data)) self.bridge = Bridge(bridge_data['internalipaddress'], bridge_data['username']) self.log("Successfully connected to Hue Bridge {}".format( bridge_data['internalipaddress'])) def print_all(self): self.log("Lights:") for room_id, room in self.bridge.groups().items(): self.log("{} [ID: {}] - {}:".format(room['type'], room_id, room['name'])) for light_id in room['lights']: light = self.bridge.lights()[light_id] self.log(" - [ID: {}]: {} ({})".format(light_id, light['name'], light['type'])) self.log(" ") self.log("Scenes:") for scene in self.bridge.scenes().values(): self.log(" - {}".format(scene['name'])) def set_light(self, id, *args, **kwargs): self.log("Setting light {}: {}".format(id, kwargs)) self.bridge.lights[id].state(**kwargs) def set_room(self, id, *args, **kwargs): self.log("Setting room {}: {}".format(id, kwargs)) self.bridge.groups[id].state(**kwargs) def adjust_light_brightness(self, id, *args, **kwargs): current_amount = self.bridge.lights[id]['brightness'] if kwargs['direction'] == 'up': new_amount = current_amount + kwargs.get('amount', 16) else: new_amount = current_amount - kwargs.get('amount', 16) self.set_light(id, **{'brightness': new_amount}) def set_scene(self, id, *args, **kwargs): scene_id = [ k for k, v in self.bridge.scenes().items() if v['name'] == kwargs['scene'] ] self.bridge.groups[id].state({'scene': scene_id}) def perform(self, action): kwargs = { k: v for k, v in action.items() if k not in ['action', 'id', 'type'] } id, act = action['id'], action['action'] if act == 'set_light': self.set_light(id, **kwargs) elif act == 'set_room': self.set_room(id, **kwargs) elif act == 'adjust_brightness': pass elif act == 'set_scene': self.set_scene(id, **kwargs) @classmethod def help(cls): return """
import sys import os from qhue import Bridge from rgb_cie import Converter f = open("hue_id.txt", "r") hue_id = f.readlines()[-1].rstrip() f.close() b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP") lights = b.lights converter = Converter() b.lights(1, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-4])) b.lights(2, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-3])) b.lights(3, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-2])) b.lights(4, 'state', on=True, xy=converter.hexToCIE1931(sys.argv[-1]))
import sys import time import os from qhue import Bridge f = open("hue_id.txt", "r") hue_id = f.readlines()[-1].rstrip() f.close() b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP") lights = b.lights command = sys.argv[-1] b.lights(1, 'state', bri=255, on=True, xy=[0.6065, 0.3095]) b.lights(2, 'state', bri=255, on=True, xy=[0.6883, 0.306]) b.lights(3, 'state', bri=255, on=True, xy=[0.6883, 0.306]) b.lights(4, 'state', bri=255, on=True, xy=[0.6065, 0.3095]) time.sleep(0.25) b.lights(1, 'state', bri=255, on=True, xy=[0.3344, 0.5002]) b.lights(2, 'state', bri=255, on=True, xy=[0.3254, 0.5028]) b.lights(3, 'state', bri=255, on=True, xy=[0.3239, 0.4932]) b.lights(4, 'state', bri=255, on=True, xy=[0.3344, 0.5002]) time.sleep(0.25) b.lights(1, 'state', bri=255, on=True, xy=[0.3069, 0.3152]) b.lights(2, 'state', bri=255, on=True, xy=[0.3069, 0.3152]) b.lights(3, 'state', bri=255, on=True, xy=[0.3069, 0.3152]) b.lights(4, 'state', bri=255, on=True, xy=[0.3069, 0.3152])
class HueClass: # Hue config MOTION = 1 ON = 2 OFF = 3 def __init__(self, name, timer, config, logger): self.name = name self.config = config self.logger = logger self.mode = HueClass.MOTION self.timer = timer self.lightState = False self.initConfig() self.b = Bridge(self.ip, self.user) self.logger.info('Init Hue OK') def initConfig(self): self.ip = self.config.get("HUE", "bridge_ip") self.user = self.config.get("HUE", "bridge_user") self.lights = self.config.get("HUE", "lamps").split(',') self.followUpDuration = self.config.get("HUE", "followupduration") self.ignoreDaylight = self.config.get("HUE", "ignore_daylight") self.latitude = float(self.config.get("HUE", "latitude")) self.longitude = float(self.config.get("HUE", "longitude")) self.logger.info("self.ignoreDaylight " + self.ignoreDaylight) def isHueEnabled(self): hueEnabled = 1 now = date.today() sunrise, sunset = sun.getSunsetSunrise(now, self.longitude, self.latitude) if sunrise < datetime.now(): self.logger.info("After sunrise " + str(sunrise)) hueEnabled = 0 if sunset < datetime.now(): self.logger.info("After sunset " + str(sunset)) hueEnabled = 1 if self.ignoreDaylight == "on": self.logger.info("Ignore daylight is on ") hueEnabled = 1 return hueEnabled def getLightState(self): return self.lightState def setHueLight(self, state): if (state == True and (self.mode == HueClass.MOTION or self.mode == HueClass.ON)) or ( state == False and (self.mode == HueClass.MOTION or self.mode == HueClass.OFF)): self.lightState = state for light in self.lights: self.logger.info('Switch light ' + light + ' ' + str(state)) self.b.lights(int(light), 'state', on=state) def lightOn(self): if self.isHueEnabled() == 1: self.logger.info('lightOn ' + str(HueClass.MOTION)) if self.mode == HueClass.MOTION: self.logger.info('Switch lights on (MOTION)') self.setHueLight(True) lightOffTime = time.time() + (int(self.followUpDuration) * 60) self.timer.setLightOffTime(lightOffTime) if self.mode == HueClass.ON: self.logger.info('Switch lights on (ON)') self.setHueLight(True) else: self.logger.info('Lights disabled (daylight outside)') def setMode(self, mode): self.logger.info('Hue set mode ' + str(mode)) self.mode = mode if self.mode == HueClass.ON: self.timer.setLightOffTime(0) # Reset timer self.setHueLight(True) else: self.setHueLight(False) def lightOff(self): if self.mode == HueClass.MOTION: self.setHueLight(False) self.logger.info('Light Off done') def quit(self): self.timer.quit()
def lightingInit(): client = MongoClient('mongodb://ec2-52-89-213-104.us-west-2.compute.amazonaws.com:27017/') client.Alfr3d_DB.authenticate(db_user,db_pass) db = client['Alfr3d_DB'] devicesCollection = db['devices'] logger.info("looking for devices") #for device in devicesCollection.find({"name":'hue'}): light_count = devicesCollection.count({"$and":[ {"type":'lights'}, {"state":'online'}, {"user":'******'}, {"location.name":socket.gethostname()} ]}) if light_count != 0: logger.info("found "+str(light_count)+" lights") else: logger.warn("unable to find any lights.. :(") raise Exception("no lights online") for device in devicesCollection.find({"$and":[ {"type":'lights'}, {"location.name":socket.gethostname()} ]}): logger.info("device found: "+ str(device)) if device['name'].startswith("hue"): logger.info("initialising all Hue lights") logger.info("looking for apikeys") username = config.get("HUE dev", str(device['MAC']).replace(':','')) logger.info("found key: "+ str(username)) bridge = Bridge(device['IP'], username) logger.info(str(bridge.lights())) lights_data = json.loads(json.dumps(bridge.lights())) for light in lights_data: hue = light_hue() hue.number=light hue.ip = device['IP'] hue.username = username logger.info("init check; all lights off") hue.hue_off() time.sleep(2) for light in lights_data: logger.info("init check; all lights on") #bridge.lights[light].state(on=True) hue.hue_on() time.sleep(2) for light in lights_data: logger.info("init check; all lights off") #bridge.lights[light].state(on=False) hue.hue_off() if device['name'].startswith("Lifx"): logger.info("initialising all Lifx lights") lifx_token = config.get("Lifx", "token") headers = {"Authorization": "Bearer %s" % lifx_token,} response = requests.get('https://api.lifx.com/v1/lights/all', headers=headers) if response.status_code != 200: logger.error("failed to authenticate with Lifx subsystems") else: logger.info("successfully authenticated with Lifx subsystems") for bulb in response.json(): bulb_label = bulb[u'label'] if bulb[u'connected'] != True: logger.warn("bulb "+str(bulb_label)+" is not online") else: if bulb[u'power'] != u'off': response = requests.put('https://api.lifx.com/v1/lights/label:'+bulb_label+'/state', data={"power": "off"}, headers=headers) if response.json()[u'results'][0][u'status'] != u'ok': logger.error("failed to turn off the bulb "+str(bulb_label)) time.sleep(2) response = requests.put('https://api.lifx.com/v1/lights/label:'+bulb_label+'/state', data={"power": "on"}, headers=headers) if response.json()[u'results'][0][u'status'] != u'ok': logger.error("failed to turn on the bulb "+str(bulb_label)) time.sleep(2) response = requests.put('https://api.lifx.com/v1/lights/label:'+bulb_label+'/state', data={"power": "off"}, headers=headers) if response.json()[u'results'][0][u'status'] != u'ok': logger.error("failed to turn off the bulb "+str(bulb_label))
print pretty_score time.sleep(3) b.lights(1, 'state', bri=255, on=False) b.lights(2, 'state', bri=255, on=False) b.lights(3, 'state', bri=255, on=False) b.lights(4, 'state', bri=255, on=False) time.sleep(1) b.lights(1, 'state', bri=254, on=True, xy=[0.1637, 0.3522]) b.lights(2, 'state', bri=254, on=True, xy=[0.169, 0.1308]) b.lights(3, 'state', bri=254, on=True, xy=[0.1497, 0.1939]) b.lights(4, 'state', bri=254, on=True, xy=[0.2344, 0.5274]) c = C() year, week = nflgame.live.current_year_and_week() b.lights(1, 'state', bri=254, on=True, xy=[0.1637, 0.3522]) b.lights(2, 'state', bri=254, on=True, xy=[0.169, 0.1308]) b.lights(3, 'state', bri=254, on=True, xy=[0.1497, 0.1939]) b.lights(4, 'state', bri=254, on=True, xy=[0.2344, 0.5274]) while game_on: games = nflgame.games(year, week) if len(games) == 0: games = nflgame.games(year, week - 1) plays = nflgame.combine_plays(games) for p in plays: if p.team.encode('ascii', 'ignore') == 'SEA': if len(p.events) > 0: if p.desc.encode('ascii', 'ignore').find('Shotgun') == -1: event_plays.append(p.desc.encode('ascii', 'ignore')) open('nfl_events.html', 'w').close() for ind, item in enumerate(event_plays[-5:]):
#hue_queue.rotate(3) def setlight(lightid='14', on=True, hue=200, bri=128): bridge.lights[lightid].state(on=on) if on: bridge.lights[lightid].state(bri=bri, hue=hue) if username is None: username = create_new_username(BRIDGE_IP) print("New user: {} . Put this in the username variable above.".format( username)) bridge = Bridge(BRIDGE_IP, username) lights = bridge.lights() for num, info in lights.items(): print("{:16} {}".format(info['name'], num)) v = random.randint(0, 255) def work_lights(): for light in hue_order: lightid = str(light) bridge.lights[lightid].state(on=True) bridge.lights[lightid].state(effect="none") bridge.lights[lightid].state(sat=15) bridge.lights[lightid].state(ct=315)
from qhue import Bridge from django.utils import timezone from .models import MonitorLights, MonitorBridge # HUE_BRIDGE_USERNAME='******' # HUE_BRIDGE_IP_ADDRESS='192.168.0.2' import os from dotenv import load_dotenv load_dotenv() HUE_BRIDGE_USERNAME = os.getenv("HUE_BRIDGE_USERNAME") HUE_BRIDGE_IP_ADDRESS = os.getenv("HUE_BRIDGE_IP_ADDRESS") b = Bridge(HUE_BRIDGE_IP_ADDRESS, HUE_BRIDGE_USERNAME) b.connect() # if b is using phue library # get the lights lights = b.lights config_b = b.config() lights = b.lights() import datetime bridge_ins = MonitorBridge(bridge_name=config_b['name'], bridge_ip_address='192.168.0.2', bridge_localtime=datetime.datetime.now(), bridge_timezone='America/Los_Angeles', bridge_unique_id=config_b['bridgeid'])