Ejemplo n.º 1
0
def setup():
    """
    Connect and setup
    :return: None
    """
    log("[ ] Setting up Hue bridge at " + str(bridge_ip))
    global bridge, group
    bridge = Bridge(bridge_ip)
    # bridge.connect()
    group = bridge.get_group_id_by_name(room)
Ejemplo n.º 2
0
sleep(2)
test_light.brightness = 254
# color = [1, 6000, 12000, 18000, 24000, 30000, 36000, 42000, 48000, 52000]

# test_light.on = False
# sleep(2)
# test_light.on = True
# sleep(2)
# test_light.on = False
# sleep(2)
print(b.groups)

nb_group = b.groups
#print(len(nb_group))

print(b.get_group_id_by_name('control_group'))

#print(b.lights)

#b.create_group('control_group', [3, 4, 5])
b.set_group(group_id='control_group', parameter='lights', value=[5])

gr0 = Group(b, 'control_group')
gr0.on = True
gr0.brightness = 254
gr0.colortemp_k = 3500
sleep(3)
gr0.on = False
b.set_group(group_id='control_group', parameter='lights', value=[3, 4])

gr0 = Group(b, 'control_group')
Ejemplo n.º 3
0
from phue import Bridge

def get_light_state(light):
    command = {
        'transitiontime': light.transitiontime,
        'on': light.on,
        'effect': light.effect,
        'saturation': light.saturation,
        'brightness': light.brightness,
        'xy': light.xy
    }
    return command
bridge = Bridge(BRIDGE_IP)
bridge.connect()
GROUP_ID = bridge.get_group_id_by_name(GROUP_NAME)

bedroom_light_ids = bridge.get_group(GROUP_NAME,'lights')
lights = bridge.get_light_objects('id')
print("Getting Lights")
backup_lights = []
for x in bedroom_light_ids:
    light_id = int(x)
    id_command = (light_id, get_light_state(lights[light_id]))
    print("Backing up: " + str(light_id))
    backup_lights.append(id_command)
time.sleep(1)
print("Turning off lights")
bridge.set_group(1, 'on', False)
time.sleep(3)
print("Restoring lights")
Ejemplo n.º 4
0
from phue import Bridge
import sys

group_name, action = sys.argv[1:]

# TODO: env var?
b = Bridge('192.168.1.119')

b.connect()
b.get_api()

group_id = b.get_group_id_by_name(group_name)
light_ids = b.get_group(group_name, "lights")
lights = b.get_light_objects('id')

for light_id in light_ids:
    light_id = int(light_id)
    if action.lower() == 'on':
        lights[light_id].on = True
    elif action.lower() == 'off':
        lights[light_id].on = False
    elif action.lower() == 'toggle':
        lights[light_id].on = not lights[light_id].on
    else:
        print(f"Invalid action: {action}")
        break
Ejemplo n.º 5
0
        while not resolved:
            ready = select.select([resolve_sdRef], [], [], timeout)
            if resolve_sdRef not in ready[0]:
                print 'Resolve timed out'
                break
            pybonjour.DNSServiceProcessResult(resolve_sdRef)
        else:
            resolved.pop()
    finally:
        resolve_sdRef.close()


bridge = Bridge()
bridge.get_ip_address(True)

groupId = bridge.get_group_id_by_name(room)

browse_sdRef = pybonjour.DNSServiceBrowse(regtype = regtype,
                                          callBack = browse_callback)

try:
    try:
        while True:
            ready = select.select([browse_sdRef], [], [])
            if browse_sdRef in ready[0]:
                pybonjour.DNSServiceProcessResult(browse_sdRef)
    except KeyboardInterrupt:
        pass
finally:
    browse_sdRef.close()