def __init__( self, jsonable_string, milight_controller=milight.MiLight( { 'host': settings['PIPOTTER_MILIGHT_SERVER'], 'port': settings['PIPOTTER_MILIGHT_PORT'] }, wait_duration=0.025), milight_light=milight.LightBulb( ['rgbw'] ), #TODO Evaluate if makes sense to restrict this to rgbw as we'd need color for the spells time_to_sleep=1): """ The constructor :param jsonable_string: a string that can be turn into a json element. Must be in the form: [ {"group":"1", "command":"command", "payload": "value"}, ..., {"group":"1", "command":"command", "payload": "value"} ] :param milight_controller: a MiLight controller object :param milight_light: a Milight LigthBulb object :param time_to_sleep: int, seconds to wait before the """ super().__init__() logger.info("Creating LightEffect object") self.name = "LightEffect" self.controller = milight_controller self.light = milight_light self.commands = [ ] # This will be overwritten by a milight.Command object later on self.time_to_sleep = time_to_sleep self._read_json(jsonable_string)
def party(ip, port, zone, party_type): controller = milight.MiLight( {"host": ip, "port": int(port)}, wait_duration=0.025 ) # Create a controller with 0 wait between commands light = milight.LightBulb(["rgbw"]) # Can specify which types of bulbs to use controller.send(light.party(party_type, int(zone))) pyotherside.send("result", "[INFO] party type " + party_type + " set")
def setcolorWhite(ip, port, zone): controller = milight.MiLight( {"host": ip, "port": int(port)}, wait_duration=0 ) # Create a controller with 0 wait between commands light = milight.LightBulb(["rgbw"]) # Can specify which types of bulbs to use controller.send(light.white(int(zone))) pyotherside.send("result", "[INFO] white = ON")
def brightness(ip, port, zone, brightness): controller = milight.MiLight( {"host": ip, "port": int(port)}, wait_duration=0 ) # Create a controller with 0 wait between commands light = milight.LightBulb(["rgbw"]) # Can specify which types of bulbs to use controller.send(light.brightness(brightness, int(zone))) pyotherside.send("result", "[INFO] brightness " + str(brightness) + " %")
def __init__(self): super(MilightSkill, self).__init__(name="MilightSkill") self.host = "192.168.1.14" self.port = 8899 self.controller = milight.MiLight( { 'host': self.host, 'port': self.port }, wait_duration=0) self.light = milight.LightBulb(['rgbw', 'white', 'rgb']) #will read zone parameter
def setcolor(ip, port, zone, red, green, blue): red = int(red) green = int(green) blue = int(blue) controller = milight.MiLight( {"host": ip, "port": int(port)}, wait_duration=0.025 ) # Create a controller with 0 wait between commands light = milight.LightBulb(["rgbw"]) # Can specify which types of bulbs to use controller.send(light.color(milight.color_from_rgb(red, green, blue), int(zone))) pyotherside.send( "result", "[INFO] RED=" + str(red) + " GREEN=" + str(green) + " BLUE=" + str(blue), )
def test_bulb_concatenation(self): led = milight.MiLight({'host': '127.0.0.1'}) bulb = milight.LightBulb() commands = bulb.all_on() self.assertTupleEqual( commands, (milight.rgbw.COMMANDS['ON'][0], milight.white.COMMANDS['ON'][0], milight.rgb.COMMANDS['ON'][0])) led.send(commands) commands = bulb.all_off() self.assertTupleEqual( commands, (milight.rgbw.COMMANDS['OFF'][0], milight.white.COMMANDS['OFF'][0], milight.rgb.COMMANDS['OFF'][0])) led.send(commands)
def change_lamp_color(self): try: query = LightModel.Light.query.filter_by(id=self.id).first() controller = milight.MiLight( { 'host': query.identifier, 'port': query.protocol }, wait_duration=0) light = milight.LightBulb(['rgbw', 'white', 'rgb']) controller.send(light.color(milight.color_from_hex(query.color), 1)) logger.info('Device ' + query.name + ' color changed') return json.encode({"status": "success"}) except Exception as e: logger.error('Device color error : ' + str(e)) raise DevicesException(str(e)) return json.encode({"status": "error"})
def change_lamp_state(self): try: query = LightModel.Light.query.filter_by(id=self.id).first() controller = milight.MiLight( { 'host': query.identifier, 'port': query.protocol }, wait_duration=0) light = milight.LightBulb(['rgbw', 'white', 'rgb']) if self.state == "true": controller.send(light.all_on()) elif self.state == "false": controller.send(light.all_off()) logger.info('Device ' + query.name + ' state changed') return json.encode({"status": "success"}) except Exception as e: logger.error('Device state error : ' + str(e)) raise DevicesException(str(e)) return json.encode({"status": "error"})
import RPi.GPIO as GPIO import time import milight import os GPIO.setmode(GPIO.BCM) capteur = 17 etat = 0 GPIO.setup(capteur, GPIO.IN) controller = milight.MiLight({'host': '192.168.1.37', 'port': 8899}, wait_duration=0) #Create a controller with 0 wait between commands light = milight.LightBulb(['rgbw']) #Can specify which types of bulbs to use print "Demarrage du capteur" time.sleep(2) print "Capteur pret a detecte un mouvement" while True: if GPIO.input(capteur): if etat == 1: controller.send(light.all_off()) # Turn off group 1 lights etat = 1 else: controller.send(light.all_on()) # Turn on all lights, equivalent to light.on(0) etat = 0 print "Mouvement detecte" time.sleep(2) time.sleep(0.1)
def setUp(self): self.led = milight.MiLight("127.0.0.1", wait_duration=0) self.bulb = milight.LightBulb('white')
def __init__(self, host): self.controller = milight.MiLight({'host':host, 'port':8899}, wait_duration=0) self.group = milight.LightBulb(['rgbw'])
import milight import time HOST_ADDR = "192.168.0.104" LIGHT_GROUP = 2 controller = milight.MiLight({ 'host': HOST_ADDR, 'port': 8899 }, wait_duration=0) light = milight.LightBulb(['rgbw']) #Lamp type controller.send(light.brightness(0, LIGHT_GROUP)) time.sleep(3) controller.send(light.white(LIGHT_GROUP)) time.sleep(3) for x in xrange(0, 100, 10): controller.send(light.brightness(x, LIGHT_GROUP)) time.sleep(0.5)
config["mqtt"]["keepalive"]) connected = True log.info("mqtt connected to " + config["mqtt"]["host"] + ":" + str(config["mqtt"]["port"]) + " with id: " + cid) except socket.error: log.error("socket.error will try a reconnection in 10 s") sleep(10) return # -------------------- main -------------------- config = cfg.configure_log(__file__) # -------------------- Milight Client -------------------- milight_controllers = {} for device_name, device in config["devices"].items(): milight_controllers[device_name] = milight.MiLight(device) #light = milight.LightBulb(['rgbw','white','rgb']) light = milight.LightBulb(['rgbw']) night_mode = [0xC1, 0xC6, 0xC8, 0xCA, 0xCC] # -------------------- Mqtt Client -------------------- cid = config["mqtt"]["client_id"] + "_" + socket.gethostname() client = mqtt.Client(client_id=cid) client.on_connect = on_connect client.on_message = on_message mqtt_connect_retries(client) client.loop_forever()
#!/usr/bin/env python import milight, datetime controller = milight.MiLight({ 'host': '192.168.42.100', 'port': 8899 }, wait_duration=.01) light = milight.LightBulb(['white']) def dawn(): controller.send(light.brightness(30, 4)) controller.send(light.warmness(70, 4)) controller.send(light.brightness(30, 1)) controller.send(light.warmness(70, 1)) print("%s --- Lights set to dawn." % str(datetime.datetime.now())) def sunrise(): controller.send(light.brightness(100, 4)) controller.send(light.warmness(70, 4)) controller.send(light.brightness(100, 1)) controller.send(light.warmness(70, 1)) print("%s --- Lights set to sunrise." % str(datetime.datetime.now())) def noon(): controller.send(light.brightness(100, 4)) controller.send(light.warmness(30, 4)) controller.send(light.brightness(100, 1))