def turn_on_lights_in_group( self, group_id: int, set_brightness_percentage: Optional[int] = None) -> None: group = phue.Group(self._hue_bridge, group_id) log.info("Turning lights in group %s on", group_id) # Make sure to turn the lighs on before changing the brightness for the brightness change to have effect group.on = True if set_brightness_percentage is None: group.brightness = MAX_BRIGHTNESS elif set_brightness_percentage: group.brightness = (set_brightness_percentage / 100) * MAX_BRIGHTNESS
def get(self): print(":P") # try: ip = open("ip.txt", "r") ip = ip.readline() bridge = phue.Bridge(ip=ip) bridge.connect() function = self.get_argument("function", True) name = self.get_argument("light", True) value = self.get_argument("value", True) print(name) if isinstance(function, str): function = parse.unquote(function) else: self.render("lights.html", groups=bridge.groups) if isinstance(name, str): name = parse.unquote(name) light = phue.Group(bridge, name) if function == "Turn-on": light.on = True self.redirect_to_main() elif function == "Turn-off": light.on = False self.redirect_to_main() elif function == "Brightness": light.brightness = int(value) self.redirect_to_main()
def set_room_brightness(self, group_id: int, brightness_percentage: int) -> None: group = phue.Group(self._hue_bridge, group_id) on_state = True if brightness_percentage >= 100: brightness = MAX_BRIGHTNESS elif brightness_percentage > 0: brightness = (brightness_percentage / 100) * MAX_BRIGHTNESS else: brightness = 0 on_state = False brightness = int(brightness) log.info("Setting lights in group %s to brightness %s", group_id, brightness) group.on = on_state group.brightness = brightness
def switchPressed(): g1.on = not g1.on #GPIO.output(led , not GPIO.input(led)) print("Lights on: "+str(g1.on)) ky040 = KY040(clk1, dt1, switch1, rotaryChanged, switchPressed) ky040.start(); GPIO.setmode(GPIO.BCM) b = phue.Bridge(ip='192.168.1.78',username='******') #b.connect() g1 = phue.Group(b,1) try: while True: sleep(.01) finally: ky040.stop() GPIO.cleanup()
import logging with open('body_list.json') as json_file: body_list = json.load(json_file) log_file = "hue_control.log" logging.basicConfig(filename=log_file, level=logging.DEBUG, filemode="a+", format="%(asctime)-15s %(levelname)-8s %(message)s") currently = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") b = phue.Bridge('192.168.1.110') allthelights = phue.AllLights() mainroomlights = phue.Group(b, "Main Room") notificationlight = phue.Light(b, "Main Table") def update_bodies(user_id): body_list[user_id]['status'] = 'home' if body_list[user_id][ 'status'] == 'away' else 'away' with open('body_list.json', 'w') as f: f.write(json.dumps(body_list, indent=4, sort_keys=True)) def anybody_home(): for user in body_list.values(): if user['status'] == 'home': return True return False
print( "\nWelcome to irHUE: A small Python application for controlling Phillips Hue lights via iRacing.\nPress Ctrl-C at any time to exit the program\n" ) #Check if a default IP address has been specified in settings.ini if not ip: ip = input( "No default IP specified!\n\nIf this is a first connection, press the blue button\non top of the Hue Bridge during the connection process.\n\nEnter Bridge IP address: " ) while True: try: b = phue.Bridge(ip) b.connect() all_lights = phue.Group(b, light_group).lights print("Bridge found! {} lights from group {} connected.".format( len(all_lights), light_group)) break except phue.PhueRequestTimeout: print( "Could not locate bridge. Check IP address or press link button on top of bridge during connection process" ) except phue.PhueRegistrationException: print( "Link button has not been pressed in the last 30 seconds. Please press the link button on top of the bridge, then press any key to continue connection process." ) input() except LookupError: print( "Default light group unspecified or not found, selecting all lights connected."
def turn_off_lights_in_group(self, group_id: int) -> None: group = phue.Group(self._hue_bridge, group_id) log.info("Turning lights in group %s off", group_id) group.on = False