def main(): module = AnsibleModule( argument_spec = dict( bridge=dict(required=True, type='str'), name=dict(required=True, type='str'), on=dict(default=True, type='bool'), brightness=dict(type='int'), hue=dict(type='int'), saturation=dict(type='int'), xy=dict(type='list'), color_temp=dict(type='int'), rgb=dict(type='str'), alert=dict(type='str', choices=['none', 'select', 'lselect']), effect=dict(type='str', choices=['none', 'colorloop']), transition_time=dict(type='int'), ), mutually_exclusive=(('hue', 'xy', 'color_temp', 'rgb'), ('saturation', 'xy', 'color_temp', 'rgb')), supports_check_mode=True ) if not HUE_AVAILABLE: module.fail_json(msg="The python-hue library is not installed") # Connect to the Hue hub try: h = Hue() h.station_ip = module.params['bridge'] h.get_state() except Exception, e: module.fail_json(msg="Failed to connect to the Hue hub. Make sure you've registered using the hue_register module first. Error was: %s" % str(e))
def _get_client(self): hue = Hue() hue.station_ip = self.config['station_ip'] hue.client_identifier = self.config['client_identifier'] hue.get_state() return hue
def wakemeup(): h = Hue() h.station_ip = '192.168.42.89' h.get_state() minutes = 15 transition = minutes * 60 * 10 h.lights['l1'].off() h.lights['l1'].set_state({ "on": True, "bri": 255, "transitiontime": transition })
def main(): module = AnsibleModule( argument_spec = dict( bridge=dict(required=True, type='str'), ), supports_check_mode=False, ) if not HUE_AVAILABLE: module.fail_json(msg="The python-hue library is not installed") # Connect and authenticate to the Hue hub try: h = Hue() h.station_ip = module.params['bridge'] h.authenticate() except Exception, e: module.fail_json(msg="Failed to authenticate to the Hue hub. Make sure you've pushed the button on the hub recently. Error was: %s" % str(e))
def main(): module = AnsibleModule( argument_spec=dict(bridge=dict(required=True, type='str'), ), supports_check_mode=False, ) if not HUE_AVAILABLE: module.fail_json(msg="The python-hue library is not installed") # Connect and authenticate to the Hue hub try: h = Hue() h.station_ip = module.params['bridge'] h.authenticate() except Exception, e: module.fail_json( msg= "Failed to authenticate to the Hue hub. Make sure you've pushed the button on the hub recently. Error was: %s" % str(e))
def sleepytime(): h = Hue() h.station_ip = '192.168.42.89' h.get_state() minutes = 30 transition = minutes * 60 * 10 h.lights['l3'].off() h.lights['l3'].set_state({ "bri": 50, "colormode": "xy", "xy": [0.5, 0.4], "transitiontime": transition, }) h.lights['l1'].off() h.lights['l1'].set_state({ "bri": 50, "colormode": "xy", "xy": [0.5, 0.4] "transitiontime": transition })
import sys, time sys.path.append( '/Users/huynh/Desktop/livebyte_webserver/lib/python-hue' ); from hue import Hue; h = Hue(); # Initialize the class h.station_ip = "192.168.1.101" # Your base station IP h.client_identifier = "newdeveloper" # h.authenticate state = h.get_state(); # Authenticate, bootstrap your lighting system li = h.lights for key, element in li.items(): print key, element l = h.lights.get('l1') # get bulb #1 while 1: ts = time.time() print ts # l.alert() # short alert # time.sleep(0.1) # l.alert() # short alert # time.sleep(0.1) # l.set_state({"bri": 220, "alert": "select","transitiontime":1}) # Complex send # time.sleep(0.1) # l.alert() # short alert # time.sleep(0.1) # l.alert() # short alert # l.set_state({"bri": 230, "xy":[0.3,0.322],"sat":255}) # Complex send # l.set_state({"bri": 230, "xy":[0.3,0.322],"sat":255}) # Complex send l.rgb(255, 255, 240,transitiontime=1) time.sleep(0.1) l.rgb(255,255,255,transitiontime=1) # l.set_state({"bri": 255, "xy":[0.3,0.322],"sat":255}) # Complex send
import random import requests import os import json from hue import Hue app = Flask(__name__, static_folder='static', static_url_path='/static') app.config['SECRET_KEY'] = 'secret!' app.debug = True socketio = SocketIO(app) resp = requests.get('https://www.meethue.com/api/nupnp') ip = json.loads(resp.content)[0]["internalipaddress"] h = Hue() h.station_ip = ip h.get_state() @app.route('/') def index(): return render_template('index.html') @socketio.on('update_light', namespace='/lights') def message(message): print message h.lights[message["light"]].set_state(message["state"]) h.get_state() emit('state', {'data': h.state}, broadcast=True)
import time import math import random as rand from hue import Hue from rgb_cie import Converter from detect_object import detect_object from detect_object import get_rgb from detect_rectangle import detect_rectangle h = Hue() h.station_ip = '172.20.11.203' h.get_state() l = h.lights.get('l2') l.set_state({ "on": True, "sat": 254, "bri": 140, "xy": [0.3127,0.329] # Reset to White }) def main(): center = detect_object() target_rgb = get_pics(center) target_lab = convert(target_rgb) vled = [127,127,127] # White now_rgb = [255, 255, 255] now_lab = [255, 255, 255]
from hue import Hue import requests import json import time import logging h = Hue() resp = requests.get('https://www.meethue.com/api/nupnp') ip = json.loads(resp.content)[0]["internalipaddress"] h = Hue() h.station_ip = ip h.get_state() logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger('scratch') SECS_PER_FRAME = 6 frames = [ { # Frame 1 "l1": {"on": True, "xy": [0.21, 0.04], "bri": 255}, "l2": {"on": True, "xy": [0.21, 0.04], "bri": 255}, "l3": {"on": True, "xy": [0.21, 0.04], "bri": 255}, "l4": {"on": True, "xy": [0.21, 0.04], "bri": 255}, "l5": {"on": True, "xy": [0.21, 0.04], "bri": 255}, "l6": {"on": True, "xy": [0.21, 0.04], "bri": 255}, },{ # Frame 2
from flask import Flask from flask import render_template from hue import Hue h = Hue() h.station_ip = "192.168.1.100" h.get_state() l = h.lights.get("l1") # l.on() # l.bri(255) app = Flask(__name__) @app.route("/") def hello(name=None): return render_template("jshtml.html") @app.route("/changecolor/<int:red>/<int:green>/<int:blue>") def changecolor(red, green, blue): l.rgb(red, green, blue) return "pray" if __name__ == "__main__": app.run(host="0.0.0.0", debug=False, port=80)
def _get_client(self): hue = Hue(); hue.station_ip = self.config['station_ip'] hue.get_state(); return hue
from hue import Hue; # Initialize the class h = Hue() # Your base station IP h.station_ip = "192.168.1.142" # Authenticate, bootstrap your lighting system h.get_state() # get bulb l1 = h.lights.get('l1') l2 = h.lights.get('l2') l3 = h.lights.get('l3') # toggle light l1.toggle() l2.toggle() l3.toggle()
from hue import Hue h = Hue() # Initialize the class h.station_ip = "192.168.1.222" # Your base station IP h.get_state() # Authenticate, bootstrap your lighting system l = h.lights.get('l3') # get bulb number 3 l.bri(0) # Dimmest l.bri(255) # Brightest l.rgb(120, 120, 0) # [0-255 rgb values] l.rgb("#9af703") # Hex string l.on() time.sleep(1) l.off() l.toggle() l.alert() # short alert l.alert("lselect") # long alert l.setState({"bri": 220, "alert": "select"}) # Complex send
#!/root/tony/python/bin/python from hue import Hue import time, datetime import ConfigParser p = ConfigParser.SafeConfigParser() p.readfp(open("./light_runner.conf", "r")) config_ip_address = p.get("config", "ip_address") config_light_number = p.get("config", "light_number") config_feedback_url = p.get("config", "feedback_url") h = Hue() h.station_ip = config_ip_address # TC: 201602?? # the get_state will hang the program if the button is needed to be pressed # we need a way to timeout this command # if it has not come back in 15 write a log message and kill the program res = h.get_state() light2 = h.lights.get(config_light_number) import requests from requests.auth import HTTPBasicAuth def get_prod_data(): r = requests.get(config_feedback_url, auth=HTTPBasicAuth("cbtadmin", "_w9y8ZdVtF")) return r.text
from hue import Hue; h = Hue(); # Initialize the class h.station_ip = "192.168.2.169" # Your base station IP h.get_state(); # Authenticate, bootstrap your lighting system l = h.lights.get('l5') # get bulb #5 #l.bri(0) # Dimmest l.bri(255) # Brightest #l.rgb(120, 120, 0) # [0-255 rgb values] #l.rgb("#9af703") # Hex string l.on() #l.off() #l.toggle() #l.alert() # short alert #l.alert("lselect") # long alert #l.setState({"bri": 220, "alert": "select"}) # Complex send def handleUserMessage(command): #TODO parse the user string. command.split(" ") print command #TODO get the set of nodes to work on from the device setOfLightsToOperateOn = ['l5'] #TODO which function should I apply? funcToApply = ExtendedColorLight for light in setOfLightsToOperateOn: pass