Example #1
0
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")
Example #2
0
 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)
Example #3
0
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) + " %")
Example #4
0
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")
Example #5
0
    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
Example #6
0
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),
    )
Example #7
0
 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)
Example #8
0
    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"})
Example #9
0
    def __init__(self, host, port=8899, bulbtype='rgbw', wait_duration=25):
        '''Constructor

    host - Wifi bridge host or IP address
    port - Wifi bridge port number
    bulbtype - Can be rgbw, rgb, or white
    wait_duration - Interval between sending commands in milliseconds
    '''
        self._host = host
        self._port = port
        self._bulbtype = bulbtype

        self._currentWorkingThread = None

        self._controller = milight.MiLight(
            {
                'host': self._host,
                'port': self._port
            },
            wait_duration=wait_duration / 1000.0)
        self._light = MilightBulb(self._bulbtype)

        self._lights = [None, None, None, None]  # four groups maximum
Example #10
0
    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"})
Example #11
0
 def test_default_constructor(self):
     led = milight.MiLight({'host': '127.0.0.1'})
     self.assertEqual(led._hosts, ({'host': "127.0.0.1", 'port': 8899}, ))
     self.assertEqual(led._wait, 0.025)
Example #12
0
                           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()
Example #13
0
 def test_changing_pause(self):
     led = milight.MiLight({'host': '127.0.0.1'}, wait_duration=0.8)
     self.assertEqual(led._wait, 0.8)
Example #14
0
 def test_changing_port(self):
     led = milight.MiLight({'host': "127.0.0.1", 'port': 50000})
     self.assertEqual(led._hosts, ({'host': "127.0.0.1", 'port': 50000}, ))
Example #15
0
 def __init__(self, host):        
     self.controller = milight.MiLight({'host':host, 'port':8899}, wait_duration=0)
     self.group = milight.LightBulb(['rgbw'])
Example #16
0
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)
Example #17
0
 def setUp(self):
     self.led = milight.MiLight("127.0.0.1", wait_duration=0)
     self.bulb = milight.LightBulb('white')
Example #18
0
#light sensor funcs
def convertToNumber(data):
    return ((data[1] + (256 * data[0])) / 1.2)


def readLight(addr=DEVICE):
    data = bus.read_i2c_block_data(addr, ONE_TIME_HIGH_RES_MODE_1)
    return convertToNumber(data)


#connect to milight
print mobile_ip + " " + milight_ip + " " + str(milight_port) + " " + str(
    milight_group)
controller = milight.MiLight({
    'host': milight_ip,
    'port': milight_port
},
                             wait_duration=0)
light = milight.LightBulb(['rgbw'])  # Can specify which types of bulbs to use
last_mobile_status = True

# main loop
while True:
    # check if the mobile is out of the network 3 times
    count = 0
    while True:
        if count > 80:
            break
        r = pyping.ping(mobile_ip)
        mobile_status = (r.ret_code == 0)
        print str(count) + " Mobile:" + str(mobile_status)
Example #19
0
#!/usr/bin/python
import milight
import sys
import time

ipController = "192.168.10.20"
portController = 8899

#print 'Number of arguments:', len(sys.argv), 'arguments.'
#print 'Argument List:', str(sys.argv)
#print 'Argument 1:', sys.argv[1]
#print 'Argument 2:', sys.argv[2]

controller = milight.MiLight({'host': ipController, 'port': portController}, wait_duration=0) #Create a controller with 0 wait between commands
light = milight.LightBulb(['rgbw', 'white', 'rgb']) #Can specify which types of bulbs to use

controller.send(light.brightness(int(sys.argv[1]),int(sys.argv[2]))) # brightness param 1 for group param 2
time.sleep(.1)
controller.send(light.brightness(int(sys.argv[1]),int(sys.argv[2]))) # brightness param 1 for group param 2 
time.sleep(.1)
controller.send(light.brightness(int(sys.argv[1]),int(sys.argv[2]))) # brightness param 1 for group param 2 

sys.exit(0)



Example #20
0
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)


Example #21
0
#!/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))