def __init__(self): self.log = logging.getLogger(type(self).__name__) self.log.debug("Initiating Hue located at %s" % self.bridge_ip) self.bridge = pyhue.Bridge(self.bridge_ip, self.bridge_user) self.lights = self.bridge.lights self.groups = self.bridge.groups self.status = True
def __init__(self, hue_ip, hue_username, hue_rooms): self.bridge = pyhue.Bridge(hue_ip, hue_username) self.rooms = \ [room for room in self.bridge.groups if room.name in hue_rooms] self.tests = 0.0 self.run_tests = 0.0 self.passed_tests = 0.0 self.failed_tests = 0.0 self.skipped_tests = 0.0
def getBridge(): b = None l = None while b == None: try: b = pyhue.Bridge('192.168.1.82', 'JaiTE2tcfSTd2l7A3FKvn1O8sskGYlbxf9fr5dRi') if (b is not None): l = b.lights except Exception as e: print e return l
def bart_hue(station_name, destination, bridge_ip, light_name, poll_interval): ''' Grab all the objects we need and start the loop ''' logging.info("BARTHue is starting up (pid: %s) ..." % os.getpid()) bart = BART(BART_API_KEY) logging.info("Connecting to Hue bridge at: %s" % bridge_ip) bridge = pyhue.Bridge(bridge_ip, HUE_USERNAME) lights = filter(lambda light: light.name == light_name, bridge.lights) if len(lights): logging.info("Found light with name '%s'" % light_name) bart_hue_loop(bart, station_name, destination, lights[0], poll_interval) else: logging.fatal("Could not find light '%s'" % light_name) os._exit(1)
def main(): """ Executes this one-time 'program' that shows the home-owner a hint about the outside-temperature with a predefined color on a predefined offset. Want to influence this? Create your own settings.py, based on settings_base """ bridge = pyhue.Bridge(settings.HUE_BRIDGE_IP, settings.HUE_BRIDGE_USER, settings.HUE_BRIDGE_PORT) light = services.hue.get_light_by_id(bridge, settings.HUE_LIGHT_ID) # If Hue Light is off, you cannot set/get any attributes except for 'on' if not light.on: light.on = True light.bri = 1 # Store this, so we can restore it after we are done original_color_setting = light.xy # Retrieve the colorset current_temperature = services.buienradar.get_station_temperature( settings.BUIENRADAR_WEATHER_STATION, settings.BUIENRADAR_MEASUREMENT) for max_temperature in settings.TEMPERATURE_COLORS: if current_temperature < max_temperature: color_set = settings.TEMPERATURE_COLORS[max_temperature] # Set the correct color to the light light.xy = pyhue.rgb2xy(color_set[0], color_set[1], color_set[2]) for i in range(4, 254, 50): light.bri = i time.sleep(60) # Since it took 5 minutes to start up, we only want to wait if the total duration exceeds 5 minutes if settings.TOTAL_DURATION_MINUTES > 5: time.sleep((settings.TOTAL_DURATION_MINUTES-5)*60) light.xy = original_color_setting light.on = False
def hue_weather_loop(api_key, state, city, bridge_ip, light_names, poll): """ Main loop, queries the WU API, and updates lights """ logging.debug("Logging into bridge at: %s" % bridge_ip) bridge = pyhue.Bridge(bridge_ip, HUE_USERNAME) lights = filter(lambda light: light.name in light_names, bridge.lights) if not len(lights): raise ValueError("No lights found with names: %s" % light_names) logging.debug("Starting main loop...") errors = 0 while True: try: if MAX_ERRORS < errors: os._exit(1) url = get_weather_url(api_key, state, city) conditions = requests.get(url).json() weather = conditions["current_observation"]["weather"] for light in lights: light.on = True light.xy = get_color_for(weather) except: errors += 1 finally: time.sleep(poll)
def onInit(self): address, username = self.getBridgeConfig() self.location = self.config.get('location') self.bridge = pyhue.Bridge(address, username) self.sendStartupEvents()
import pyhue bridge = pyhue.Bridge('192.168.1.82', 'JaiTE2tcfSTd2l7A3FKvn1O8sskGYlbxf9fr5dRi') for light in bridge.lights: light.on = False
def send_hue(self, recipient, state, light_state): """Sends a hue event to the specified light. Args: state: New status to set. """ if self.hue_bridge is None: self.logger.info("Initializing Hue") if cfg.HUE_BRIDGE_ADDRESS == '' or cfg.HUE_USER_ID == '': self.logger.error( "Hue Bridge Address or User ID not specified - unable to send Hue command!" ) else: self.hue_bridge = pyhue.Bridge(cfg.HUE_BRIDGE_ADDRESS, cfg.HUE_USER_ID) if self.hue_bridge != None: self.logger.info("Sending %s message to %s", state, recipient) try: self.hue_sent = False if light_state == "on": for group in self.hue_bridge.groups: if group.name == recipient: if group.on == False: group.on = True self.logger.info( "Message sent to turn %s group %s", light_state, recipient) self.hue_sent = True if self.hue_sent == False: for light in self.hue_bridge.lights: if light.name == recipient: if recipient == cfg.HUE_LIGHT_NAME: self.hue_status = light.on self.hue_hue = light.hue self.hue_sat = light.sat self.hue_bri = light.bri if light.on == False: light.on = True if recipient == cfg.HUE_LIGHT_NAME: light.hue = cfg.HUE_LIGHT_HUE light.sat = cfg.HUE_LIGHT_SAT light.bri = cfg.HUE_LIGHT_BRI self.logger.info( "Message sent to turn %s light %s", light_state, recipient) if light_state == "off": for group in self.hue_bridge.groups: if group.name == recipient: if group.on == True: group.on = False self.logger.info( "Message sent to turn %s group %s", light_state, recipient) self.hue_sent = True if self.hue_sent == False: for light in self.hue_bridge.lights: if light.name == recipient: if light.on == True: if recipient == cfg.HUE_LIGHT_NAME and self.hue_hue != None and self.hue_sat != None and self.hue_bri != None and self.hue_status != None: light.hue = self.hue_hue light.sat = self.hue_sat light.bri = self.hue_bri light.on = self.hue_status else: light.on = False self.logger.info( "Message sent to turn %s light %s", light_state, recipient) except: self.logger.error("Exception sending Hue event: %s", sys.exc_info()[0])
#!/usr/bin/python import pyhue import sys import cgi print "Content-Type: text/html\n\r" print "\n\r" form = cgi.FieldStorage() lightstate = form.getvalue("onoff") print lightstate bridge = pyhue.Bridge("192.168.0.10", "fkEGsDaVfOk745iChwLTQlMNYpAE8uhN2Nb-diMP") for light in bridge.lights: if lightstate == "false": light.on = False if lightstate == "true": light.on = True print "<a href='/'> home </a>"
def connect(self): self.bridge = pyhue.Bridge(self.config['bridge'], self.config['username']) on_state = json.dumps({"on": True, "bri": 255}) for light_id in self.config['lights']: self.bridge.setState(light_id, on_state)
''' import sys import datetime from twisted.internet import defer from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor from twisted.python import log import txthings.resource as resource import txthings.coap as coap import pyhue bridge = pyhue.Bridge("10.1.174.9", "WU9GE-SxacSwEgg1S1SzWN81hlcsuVBpZf8wBOsC") class CoreResource(resource.CoAPResource): """ Example Resource that provides list of links hosted by a server. Normally it should be hosted at /.well-known/core Resource should be initialized with "root" resource, which can be used to generate the list of links. For the response, an option "Content-Format" is set to value 40, meaning "application/link-format". Without it most clients won't be able to automatically interpret the link format. Notice that self.visible is not set - that means that resource won't
import pyhue bridge = pyhue.Bridge('192.168.7.39', 'GA9vM13aYHH3HZ5QkWpTWzdwTmTUwP9jmBUYWWD6') #for light in bridge.lights: # print(light.id) # print(light.name) # print(light.xy) # print(light.swversion) lights = bridge.lights for group in bridge.groups: print(group.name) for light in group.lights: print(' %s' % lights[int(light)-1].name) print('')
def setUp(self): MockHTTPConnection.requests = [] self.bridge = pyhue.Bridge('0.0.0.0', 'username')