How to use qhue - 10 common examples

To help you get started, we’ve selected a few qhue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jbonachera / hue-dimmers-poller / server.py View on Github external
def main():
    """
    main
    """
    hue_bridge = qhue.Bridge(os.environ.get('HUE_BRIDGE'),
                             os.environ.get('HUE_USERNAME'))
    if not hue_bridge:
        print("Oops")
        sys.exit(1)
    sensors = hue_bridge.sensors
    for _, sensor in sensors().items():
        if sensor.get('type') == 'ZLLSwitch':
            __memory__[sensor['uniqueid']] = sensor['state']['lastupdated']
    print("Started")
    sleep_time = os.environ.get('SLEEP_TIME', 0.3)
    while True:
        try:
            for _, sensor in sensors().items():
                if sensor.get('type') == 'ZLLSwitch':
                    check_change((sensor))
            time.sleep(sleep_time)
github GammaGames / kano-wand-demos / hue.py View on Github external
"flipendo": {"hue": 37445, "bri": 150, "sat": 140},
            "expelliarmus": {"hue": 1547, "bri": 200, "sat": 200},
            "incendio": {"hue": 7063, "bri": 200, "sat": 250},
            "lumos": {"hue": 0, "bri": 204, "sat": 0},
            "locomotor": {"hue": 12324, "bri": 100, "sat": 140},
            "engorgio": {"hue": 32275, "bri": 125, "sat": 120},
            "aguamenti": {"hue": 32275, "bri": 180, "sat": 200},
            "avis": {"hue": 37445, "bri": 150, "sat": 130},
            "reducto": {"hue": 37445, "bri": 180, "sat": 200}
        }
        self.current = self.color_values[None]
        # Bridge api values
        self.bridge_ip = "192.168.1.22"
        self.username = "dBHN8d6Qkw6EJMqzEI2oI0zXJGiOdvyE2lRzFha8"
        # Bridge object and lights
        self.bridge = Bridge(self.bridge_ip, self.username)
        self.light_ids = ["1"]
        self.light_states = {}

        for id in self.light_ids:
            # Backup the state of all the lights
            light = self.bridge.lights[id]
            state = {"on": True, **self.color_values[None]}
            s = light()['state']
            for key in state:
                state[key] = s.get(key)
            self.light_states[id] = state
            # Set the default state for the bulb
            light.state(on=True, **self.color_values[None])
github midorineko / rpi_automation / current_hue_status.py View on Github external
import sys
from qhue import Bridge
from rgb_cie import Converter
import os

converter = Converter()

f = open("hue_id.txt", "r")
hue_id = f.readlines()[-1].rstrip()
f.close()

b = Bridge(hue_id, "elbLovRPUcHaqss904iEJMH9LZrRwsvFeOKSfvOP")


strip_bri   = b.lights[1]()['state']['bri']
bloom_1_bri = b.lights[2]()['state']['bri']
bloom_2_bri = b.lights[3]()['state']['bri']
strip_2_bri = b.lights[4]()['state']['bri']

strip_xy   = b.lights[1]()['state']['xy']
bloom_1_xy = b.lights[2]()['state']['xy']
bloom_2_xy = b.lights[3]()['state']['xy']
strip_2_xy = b.lights[4]()['state']['xy']

strip_hex   = converter.CIE1931ToHex(strip_xy[0], strip_xy[1], bri=(strip_bri/254.0))
bloom_1_hex = converter.CIE1931ToHex(bloom_1_xy[0], bloom_1_xy[1], bri=(bloom_1_bri/254.0))
bloom_2_hex = converter.CIE1931ToHex(bloom_2_xy[0], bloom_2_xy[1], bri=(bloom_2_bri/254.0))
strip_2_hex = converter.CIE1931ToHex(strip_2_xy[0], strip_2_xy[1], bri=(strip_2_bri/254.0))
github trevorprater / sleep-at-night / sleep_at_night.py View on Github external
def __init__(
            self,
            portfolio_balance,
            bridge_ip=os.getenv('HUE_BRIDGE_IP'),
            down_color='red',
            up_color='green',
            light_ids=[],
            num_colors_in_range=100,
            performance_thresh=0.02):

        self.bridge = Bridge(bridge_ip, username=os.getenv('HUE_BRIDGE_USER'))
        self.light_ids = light_ids
        self._color_map = {
            'red': 0, 'yellow': 12750, 'green': 25500,
            'blue': 46920, 'violet': 56100, 'max': 65280
        }
        self.down_color = self._color_map[down_color]
        self.up_color = self._color_map[up_color]
        self.num_colors_in_range = num_colors_in_range

        # (color is scaled between -n% and +n%)
        self.performance_thresh = performance_thresh
        self.start_balance = portfolio_balance
github midorineko / rpi_automation / scene_color_set.py View on Github external
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]))
github midorineko / rpi_automation / brightness.py View on Github external
import sys
from qhue import Bridge
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
github cryzed / Amby / amby / cli.py View on Github external
def main_(arguments):
    username = arguments.username or get_saved_username()
    if not username:
        username = prompt_create_username(arguments.bridge_address)
        if not username:
            return FAILURE_EXIT_CODE
        save_username(username)
    bridge = qhue.Bridge(arguments.bridge_address, username)

    initial_states = {}
    for light in arguments.lights:
        state = bridge.lights[light]()['state']
        initial_states[light] = state
        if arguments.enable and not state['on']:
            bridge.lights[light].state(on=True)

    if arguments.restore_state:
        def restore_state():
            for light, state in initial_states.items():
                change_light_state(bridge, light, state)

        atexit.register(restore_state)

    previous_color = None
github hasegaw / IkaLog / ikalog / outputs / hue.py View on Github external
def __init__(self, host=None, user=None):
        self.enabled = (not host is None)
        if not (host and user):
            self.hue_bridge = None
            return None

        self.check_import()

        import qhue
        try:
            self.hue_bridge = qhue.Bridge(host, user)
        except:
            IkaUtils.dprint('%s: Exception.' % self)
            IkaUtils.dprint(traceback.format_exc())
github cryzed / Amby / amby / cli.py View on Github external
def prompt_create_username(bridge_address):
    choice = input('No username specified, do you want to create one now? [Y/n]: ')
    if choice.lower() in {'', 'y', 'yes'}:
        try:
            return qhue.create_new_username(bridge_address)
        except QhueException as exception:
            stderr(f'Exception occurred while creating the username: {exception}')
github fredley / raspi-turntouch / controllers / hue_controller.py View on Github external
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']))

qhue

Qhue: python wrapper for Philips Hue API

GPL-2.0
Latest version published 3 years ago

Package Health Score

39 / 100
Full package analysis