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 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 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 count = get_prod_data()
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
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
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
def _get_client(self): hue = Hue(); hue.station_ip = self.config['station_ip'] hue.get_state(); return hue
class HueLight(): def __init__(self,id=-1,ip='192.168.1.99',lig='l1'): self.h = Hue() self.h.station_ip = ip self.h.get_state() self.level=60 self.status=0 self.id=id self.lig=lig self.color=[255,255,255,0,0] self.h.lights[self.lig].rgb(self.color[0],self.color[1],self.color[2]) self.h.lights[self.lig].bri(self.level,1) self.h.lights[self.lig].off() def getId(self): return self.id #returns the ID def getWhoIm(self): print "HueLight" return "Hue Light" #returns what kind of object are def changeStatus(self): if self.status == 0 : self.status=1 self.h.lights[self.lig].on() self.h.lights[self.lig].bri(self.level,1) else : self.h.lights[self.lig].off() self.status=0 #here is going to change the status of the onject, example ON/OF def setIntensity(self,intensity=100): self.h.lights[self.lig].bri(self.level,1) #Intensity it means like a potenciometer, if I have a light is going to be the brignest of the light #de value of the intensity it shoud be between 0 and 255 def setOn(self): self.h.lights[self.lig].on() self.status=1 #Turns on the device def setOff(self): self.h.lights[self.lig].off() self.status=0 #Turns off the device def setParameter(self,parameter=100): self.h.get_state() #This is going to be a caracteristinc, for example the color of the light also a value between 0 and 255 def getParameter(self): self.h.get_state() #retunrs the parameter for example de color if its a light def getStatus(self): return self.status def copy(self): aux=[self.color[0],self.color[1],self.color[2],self.status,self.level] return aux def paste(self,data): if data[3]==1: if self.status==0 : self.setOn() self.status=1 if data[0]!=-1 and data[1]!=-1 and data[2]!=-1: self.color[0]=data[0] self.color[1]=data[1] self.color[2]=data[2] self.color[3]=data[3] self.color[4]=data[4] self.level=data[4] self.updateColor() print "pasting intensity tooo to: "+ str ( self.level) self.setIntensity() print "-------------- I'm pasting----------------\n-------"+str(self.color)+"-------------\n" else : if data[4]!=-1:#audio copy self.level=data[4] self.setIntensity() print "pasting intensity tooo to: "+ str ( self.level) else : self.status=0 self.setOff() def Increase(self,value=40): self.level+=value if self.level > 255 : self.level=255 self.h.lights[self.lig].bri(self.level,1) def Decrease(self,value=40): self.level-=value if self.level <5 : self.level=5 self.h.lights[self.lig].bri(self.level,1) def Param_Increase(self,value=10): self.color[1]+=value self.color[2]-=value if self.color[1] >250 : self.color[1]=0 if self.color[2] <0 : self.color[2]=250 self.updateColor() def Param_Decrease(self,value=10): self.color[2]+=value self.color[1]-=value if self.color[2] >250 : self.color[2]=0 if self.color[1] <0 : self.color[1]=250 self.updateColor() def updateColor(self): try: self.h.lights[self.lig].rgb(self.color[0],self.color[1],self.color[2]) except: print "colooooooooor errorrrr"