def get_lights_data(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) config = ConfigParser.RawConfigParser() config.read(utility.get_config_path()) all_lights = config.get('Light Settings', 'all_lights') all_lights = [int(i) for i in all_lights.split(',')] active_bulbs = config.get('Light Settings', 'active') active_bulbs = [int(i) for i in active_bulbs.split(',')] lights = [] for counter, light in enumerate(all_lights): resource = { 'which': light } result = bridge.light.get(resource) # Skip unavailable lights if type(result['resource']) is dict: state = result['resource']['state']['on'] light_name = result['resource']['name'] light_data = [light, state, light_name, int(active_bulbs[counter])] lights.append(light_data) return lights
def get_bridge(options): def create_config(): created = False print 'Press the button on the Hue bridge' while not created: resource = {'user': {'devicetype': HUESERNAME, 'name': HUESERNAME}} response = bridge.config.create(resource)['resource'] if 'error' in response[0]: if response[0]['error']['type'] != 101: print 'Unhandled error creating configuration on the Hue' sys.exit(response) else: created = True probe_bridge = lambda: bridge.config.get(dict(which="system"))['resource'] bridge_device = dict(ip=options.bridge) bridge_user = dict(name=HUESERNAME) bridge = Bridge(device=bridge_device, user=bridge_user) probe_response = probe_bridge() if 'lights' in probe_response: print "Connected to bridge" else: if probe_response[0]['error']['type'] == 1: create_config() bridge = get_bridge(options) return bridge
def connect(host, user): if not user: print "please press the button on your hue bridge" time.sleep(2) bridge = Bridge(device={'ip': host}, user={"name": user}) return (user, bridge)
def thunder(): #Play random thunder Sounds thunderfnames = ["thunder", "thunder_strike_2", "thunder_strike_3"] winsound.PlaySound('resources/%s.wav' % random.choice(thunderfnames), winsound.SND_ASYNC) print "In Thunder Method" bridge = Bridge(device={'ip': '192.168.1.5'}, user={'name': 'newdeveloper'}) for _ in range(4): resource = { 'which': 2, 'data': { 'state': { 'on': True, "ct": 153, 'bri': 255, 'alert': 'select' } } } bridge.light.update(resource) resource = { 'which': 3, 'data': { 'state': { 'on': True, "ct": 153, 'bri': 255, 'alert': 'select' } } } bridge.light.update(resource) resource = { 'which': 2, 'data': { 'state': { 'on': True, "hue": 46920, "sat": 255, 'bri': 10 } } } bridge.light.update(resource) resource = { 'which': 3, 'data': { 'state': { 'on': True, "hue": 46920, "sat": 255, 'bri': 10 } } } bridge.light.update(resource)
def update_lamp(self, lamp, d): #IP: Philips Hue Bridge (the small curcular device that connects to the lamps) IP bridge = Bridge( device={'ip': self.light_ip}, user={'name': 'go3D6jUyb3yLQFP0tcPmJ3xzNPIC507T1SL2pnir'}) resource = {'which': lamp, 'data': {'state': d}} bridge.light.update(resource) pass
def __init__(self, light, light_ip='192.168.0.87'): self.bridge = Bridge( device={'ip': light_ip}, user={'name': 'go3D6jUyb3yLQFP0tcPmJ3xzNPIC507T1SL2pnir'}) self.light = light self.set_state() self.set_sat(254)
def drone(soundfname): bridge = Bridge(device={'ip':'192.168.1.5'}, user={'name':'newdeveloper'}) lights = bridge.light.get({'which':'all'}) #Play the Sound print "In Drone Method" winsound.PlaySound('resources/%s.wav' % soundfname, winsound.SND_ASYNC) for _ in range(24): time.sleep(1) for light in lights['resource']: resource = {'which':light['id'],'data':{'state':{'on':True, 'hue':25500 ,'sat':180, "alert":"select"}}} bridge.light.update(resource)
def initialize(): config = ConfigParser.RawConfigParser() config.read(utility.get_config_path()) ip = config.get('Configuration', 'hue_ip') username = config.get('Configuration', 'username') bridge = Bridge(device={'ip': ip}, user={'name': username}) max_bri = config.get('Light Settings', 'max_bri') min_bri = config.get('Light Settings', 'min_bri') active_lights = config.get('Light Settings', 'active') active_lights = [int(i) for i in active_lights.split(',')] all_lights = config.get('Light Settings', 'all_lights') all_lights = [int(i) for i in all_lights.split(',')] # Check selected bulbs vs all known bulbs bulb_list = [] for counter, bulb in enumerate(all_lights): try: if active_lights[counter]: bulb_list.append(bulb) else: bulb_list.append(0) except IndexError: bulb_list.append(0) bulb_settings = json.loads(config.get('Light Settings', 'bulb_settings')) update = config.get('Light Settings', 'update') update_buffer = config.get('Light Settings', 'update_buffer') default = config.get('Light Settings', 'default').split(',') default = (int(default[0]), int(default[1]), int(default[2])) zones = config.get('Light Settings', 'zones') zones = ast.literal_eval(zones) zone_state = config.getboolean('Light Settings', 'zone_state') party_mode = config.getboolean('Party Mode', 'running') black_rgb = config.get('Light Settings', 'black_rgb').split(',') black_rgb = (int(black_rgb[0]), int(black_rgb[1]), int(black_rgb[2])) display_index = config.get('Light Settings', 'display_index') color_mode = config.get('Light Settings', 'color_mode') return bridge, ip, username, bulb_list, bulb_settings, default, default, \ update, update_buffer, max_bri, min_bri, zones, zone_state, color_mode, \ black_rgb, display_index, party_mode
def __init__(self, deviceIP, username, _id, data,\ *args, **kwargs): self.deviceIP = deviceIP self.username = username self.data = data self.ligth_id = _id #print(self.deviceIP, self.username, self.data, self.ligth_id) self.bridge = Bridge(device={'ip': self.deviceIP}, \ user={'name': self.username} )
def heart(): #Play random thunder Sounds currfname = "heartbeat" winsound.PlaySound('resources/%s.wav' % currfname, winsound.SND_ASYNC) print "In heartbeat Method" bridge = Bridge(device={'ip':'192.168.1.5'}, user={'name':'newdeveloper'}) for _ in range(20): resource = {'which':2,'data':{'state':{'on':True, 'hue':65280, 'sat':255, 'bri':255}}} bridge.light.update(resource) resource = {'which':2,'data':{'state':{'on':False}}} bridge.light.update(resource) time.sleep(1)
def __createBridge(self, config): bridge = Bridge(device={'ip': config['bridgeip']}, user={ 'name': config['username']}) resource = {'which': 'system'} response = bridge.config.get(resource)['resource'] if 'lights' in response: # user is authorized return bridge elif 'error' in response[0]: # user is not authorized error = response[0]['error'] if error['type'] == 1: self.__createConfig(bridge, config) return bridge
def demon(): #Play random thunder Sounds currfname = "scary_demon_haunting" winsound.PlaySound('resources/%s.wav' % currfname, winsound.SND_ASYNC) print "In demon Method" bridge = Bridge(device={'ip': '192.168.1.5'}, user={'name': 'newdeveloper'}) resource = { 'which': 1, 'data': { 'state': { 'on': True, 'hue': 65280, 'sat': 255, 'bri': 255, 'transitiontime': 300 } } } bridge.light.update(resource) resource = { 'which': 2, 'data': { 'state': { 'on': True, 'hue': 25500, 'sat': 255, 'bri': 255, 'transitiontime': 300 } } } bridge.light.update(resource) resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 65280, 'sat': 255, 'bri': 255, 'transitiontime': 300 } } } bridge.light.update(resource) time.sleep(30)
def get_lights_list(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) resource = {'which': 'all'} lights = bridge.light.get(resource) lights = lights['resource'] lights_list = [] for light in lights: try: lights_list.append(str(light['id'])) except Exception as e: print '\nWhooooops!' print light print e return lights_list
def get_light_diagnostic_data(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) config = utility.get_config_dict() all_lights = [int(i) for i in config['all_lights'].split(',')] lights = {} for counter, light in enumerate(all_lights): resource = { 'which': light } result = bridge.light.get(resource) lights[light] = result return lights
def initialize(): config = ConfigParser.RawConfigParser() config.read(config_path + '\\screenbloom_config.cfg') ip = config.get('Configuration', 'hue_ip') username = config.get('Configuration', 'username') bridge = Bridge(device={'ip': ip}, user={'name': username}) max_bri = config.get('Light Settings', 'max_bri') min_bri = config.get('Light Settings', 'min_bri') active_lights = config.get('Light Settings', 'active') active_lights = [int(i) for i in active_lights.split(',')] all_lights = config.get('Light Settings', 'all_lights') all_lights = [int(i) for i in all_lights.split(',')] # Check selected bulbs vs all known bulbs bulb_list = [] for counter, bulb in enumerate(all_lights): try: if active_lights[counter]: bulb_list.append(bulb) else: bulb_list.append(0) except IndexError: bulb_list.append(0) update = config.get('Light Settings', 'update') default = config.get('Light Settings', 'default').split(',') default = (int(default[0]), int(default[1]), int(default[2])) zones = config.get('Light Settings', 'zones') zones = ast.literal_eval(zones) zone_state = config.getboolean('Light Settings', 'zone_state') # mode = 'dominant' mode = 'standard' black_rgb = config.get('Light Settings', 'black_rgb').split(',') black_rgb = (int(black_rgb[0]), int(black_rgb[1]), int(black_rgb[2])) color_buffer = [] return bridge, ip, username, bulb_list, default, default, \ update, max_bri, min_bri, zones, zone_state, mode,\ black_rgb, color_buffer
def setbasecolors(): huelist = [46920, 50000, 46920] bridge = Bridge(device={'ip': '192.168.1.5'}, user={'name': 'newdeveloper'}) lights = bridge.light.get({'which': 'all'}) for light in lights['resource']: resource = { 'which': light['id'], 'data': { 'state': { 'on': True, 'hue': huelist[light['id'] - 1], 'sat': 255, 'bri': 50 } } } bridge.light.update(resource)
def get_lights_list(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) resource = { 'which': 'all' } lights = bridge.light.get(resource) lights = lights['resource'] lights_list = [] for light in lights: # Skip "lights" that don't have a bri property # Probably a Hue light switch or a non-Hue brand product try: bri = light['state']['bri'] lights_list.append(str(light['id'])) except KeyError: continue return lights_list
def initialize(): config_dict = utility.get_config_dict() ip = config_dict['ip'] username = config_dict['username'] bridge = Bridge(device={'ip': ip}, user={'name': username}) max_bri = config_dict['max_bri'] min_bri = config_dict['min_bri'] active_lights = [int(i) for i in config_dict['active'].split(',')] all_lights = [int(i) for i in config_dict['all_lights'].split(',')] # Check selected bulbs vs all known bulbs bulb_list = [] for counter, bulb in enumerate(all_lights): if active_lights[counter]: bulb_list.append(active_lights[counter]) else: bulb_list.append(0) bulb_settings = json.loads(config_dict['bulb_settings']) update = config_dict['update'] update_buffer = config_dict['update_buffer'] default = [int(i) for i in config_dict['default'].split(',')] black_rgb = [int(i) for i in config_dict['black_rgb'].split(',')] zones = ast.literal_eval(config_dict['zones']) zone_state = bool(config_dict['zone_state']) party_mode = bool(config_dict['party_mode']) display_index = config_dict['display_index'] color_mode_enabled = config_dict['color_mode_enabled'] color_mode = config_dict['color_mode'] return bridge, ip, username, bulb_list, bulb_settings, default, default, \ update, update_buffer, max_bri, min_bri, zones, zone_state, color_mode, \ black_rgb, display_index, party_mode, color_mode_enabled
def chains(soundfname): bridge = Bridge(device={'ip': '192.168.1.5'}, user={'name': 'newdeveloper'}) lights = bridge.light.get({'which': 'all'}) #Play the Sound print "In Chains Method" winsound.PlaySound('resources/%s.wav' % soundfname, winsound.SND_ASYNC) for _ in range(70): resource = { 'which': 2, 'data': { 'state': { 'on': True, 'hue': 56100, 'sat': 255, 'alert': 'select' } } } bridge.light.update(resource)
def get_lights_data(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) config = utility.get_config_dict() all_lights = [int(i) for i in config['all_lights'].split(',')] active_bulbs = [int(i) for i in config['active'].split(',')] lights = [] for counter, light in enumerate(all_lights): resource = { 'which': light } result = bridge.light.get(resource) if type(result['resource']) is dict: # Skip unavailable lights state = result['resource']['state']['on'] light_name = result['resource']['name'] model_id = result['resource']['modelid'] bri = result['resource']['state']['bri'] # Setting defaults for non-color bulbs try: colormode = result['resource']['state']['colormode'] except KeyError: colormode = None try: xy = result['resource']['state']['xy'] except KeyError: xy = [] active = light if int(light) in active_bulbs else 0 light_data = [light, state, light_name, active, model_id, bri, xy, colormode] lights.append(light_data) return lights
def get_lights_data(hue_ip, username): bridge = Bridge(device={'ip': hue_ip}, user={'name': username}) config = utility.get_config_dict() all_lights = [int(i) for i in config['all_lights'].split(',')] active_bulbs = [int(i) for i in config['active'].split(',')] lights = [] for counter, light in enumerate(all_lights): resource = {'which': light} result = bridge.light.get(resource) # Skip unavailable lights if type(result['resource']) is dict: state = result['resource']['state']['on'] light_name = result['resource']['name'] model_id = result['resource']['modelid'] active = light if int(light) in active_bulbs else 0 light_data = [light, state, light_name, active, model_id] lights.append(light_data) return lights
import time import settings from beautifulhue.api import Bridge import RPi.GPIO as GPIO # for button presses import adafruit_ads1x15.ads1015 as ADS # Import the ADS1x15 module. # Setting Up Button GPIO GPIO.setmode(GPIO.BCM) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Using GPIO 18 for button input BRIDGE = Bridge(device={'ip': '192.168.0.34'}, user={'name': settings.HUE_API_KEY}) # Philips Hue Information # create an ADS1015 ADC (12-bit) instance. # Choose a gain of 1 for reading voltages from 0 to 4.09V. # Or pick a different gain to change the range of voltages that are read: # - 2/3 = +/-6.144V # - 1 = +/-4.096V # - 2 = +/-2.048V # - 4 = +/-1.024V # - 8 = +/-0.512V # - 16 = +/-0.256V # See table 3 in the ADS1015/ADS1115 datasheet for more info on gain. ADC = ADS.ADS1015() GAIN = 1 ON_TOGGLE = True LIGHTS_TO_UPDATE = [settings.ROOM_LIGHT] # Room lights are 5 and 6 LAST_BUTTON_STATE = False BUTTON_STATE = True LAST_HUE_ANALOG = 0
def __init__(self, user_id, bridge_ip): self.user_id = user_id self.bridge_ip = bridge_ip self.bridge = Bridge(device={'ip': bridge_ip}, user={'name': user_id})
def test123(): print('running ' + strftime("%Y-%m-%d %H:%M:%S", gmtime())) sleep(0.5) if __name__ == '__main__': conf = [] if (os.path.isfile(CONF_PATH)): with open(CONF_PATH, 'r') as conf_data: conf = yaml.load(conf_data.read()) print conf hc1Server = HC1_Server(conf['server']['port'], serverCallBack) hc1Server.start() bridge = Bridge(device={'ip': conf['hue']['ip']}, user={'name': conf['hue']['user']}) try: while (True): lights = bridge.light.get({'which':'all'}) #print lights for light in lights['resource']: print (light['id'], light['name'], light['state']['on'], light['state']['bri']) test123() except KeyboardInterrupt: print('SigTerm received, shutting down') sys.exit(0)
__author__ = 'Arjun' import re import PyEcho import time import twitter from beautifulhue.api import Bridge bridge = Bridge(device={'ip': '192.168.2.xx'}, user={'name': 'xxxxxxxxx'}) Blue1 = {'which': 1, 'data': {'state': {'on': True, 'hue': 46920, 'bri': 100}}} Blue2 = {'which': 2, 'data': {'state': {'on': True, 'hue': 46920, 'bri': 100}}} Blue3 = {'which': 3, 'data': {'state': {'on': True, 'hue': 46920, 'bri': 100}}} Red1 = {'which': 1, 'data': {'state': {'on': True, 'hue': 65280, 'bri': 100}}} Red2 = {'which': 2, 'data': {'state': {'on': True, 'hue': 65280, 'bri': 100}}} Red3 = {'which': 3, 'data': {'state': {'on': True, 'hue': 65280, 'bri': 100}}} Green1 = { 'which': 1, 'data': { 'state': { 'on': True, 'hue': 25500, 'bri': 100 } }
#!/usr/bin/python from beautifulhue.api import Bridge bridge = Bridge(device={'ip': '192.168.1.80'}, user={'name': '12345'}) resource = {'which': 'all', 'verbose': True} bridge.light.get(resource)
from beautifulhue.api import Bridge import time from random import choice import config import flask import threading config_dict = config.get_dict_of_params() bridge = Bridge(device={'ip': config_dict['hue_ip']}, user={'name': config_dict['hue_user']}) # bridge = pyhue.Bridge('192.168.1.211', '3330f3b32f409f0f303cbeab3da6e87') # resource = {'which':'all', 'verbose':True} # print bridge.light.get(resource) def blue_party(): while True: # val = choice([(0,0),(.25,0),(.1,.1),(.5,.3),(.7,.7),(.25,0),(.167,.04)]) brightness = choice([150, 255]) resource = { 'which': 4, 'data': { 'state': { 'on': True, 'xy': choice([(0, 0), (.25, 0), (.1, .1), (.5, .3), (.7, .7), (.25, 0), (.167, .04)]), # val, # 'sat':
from beautifulhue.api import Bridge bridge = Bridge(device={'ip':'10.0.1.15'}, user={'name':'newdeveloper'}) resource = {'which':'all'}} bridge.light.get(resource)
from beautifulhue.api import Bridge bridge = Bridge(device={'ip': '192.168.0.100'}, user={'name': 'pxkuGTBuWvmmCt1fZBQCoo7nrArEoSP-NV4aG4am'}) # Get light number 2. from beautifulhue.api import Bridge bridge = Bridge(device={'ip': '192.168.0.100'}, user={'name': 'pxkuGTBuWvmmCt1fZBQCoo7nrArEoSP-NV4aG4am'}) resource = {'which': 2} bridge.light.get(resource) # Update light #2's state. from beautifulhue.api import Bridge bridge = Bridge(device={'ip': '192.168.0.100'}, user={'name': 'pxkuGTBuWvmmCt1fZBQCoo7nrArEoSP-NV4aG4am'}) resource = {'which': 2, 'data': {'state': {'on': false}}} bridge.light.update(resource)
def witch(): #Play random thunder Sounds witchfnames = ["witch", "cat"] currfname = random.choice(witchfnames) winsound.PlaySound('resources/%s.wav' % currfname, winsound.SND_ASYNC) print "In witch Method" bridge = Bridge(device={'ip': '192.168.1.5'}, user={'name': 'newdeveloper'}) if currfname == "witch": for _ in range(5): resource = { 'which': 1, 'data': { 'state': { 'on': True, 'hue': 25500, 'bri': 255, 'alert': 'select' } } } bridge.light.update(resource) for _ in range(5): resource = { 'which': 1, 'data': { 'state': { 'on': True, 'hue': 54000, 'bri': 255, 'alert': 'select' } } } bridge.light.update(resource) if currfname == "cat": for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 36210, 'alert': 'select' } } } bridge.light.update(resource) for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 46920, 'alert': 'select' } } } bridge.light.update(resource) time.sleep(4) for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 65280, 'alert': 'select' } } } bridge.light.update(resource) for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 46920, 'alert': 'select' } } } bridge.light.update(resource) time.sleep(1) for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 65280, 'alert': 'select' } } } bridge.light.update(resource) for _ in range(5): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 46920, 'alert': 'select' } } } bridge.light.update(resource) time.sleep(1) for _ in range(15): resource = { 'which': 3, 'data': { 'state': { 'on': True, 'hue': 46920, 'alert': 'select' } } } bridge.light.update(resource)