def rain_theme(request):

    userIP = AddDevice.objects.get(owner=request.user).ip
    bulb = Bulb(userIP)

    duration = 1000
    brightness = 100

    transitions = [
    RGBTransition(23, 80, 91, duration=duration, brightness=brightness),
    RGBTransition(11, 64, 87, duration=duration, brightness=brightness),
    RGBTransition(5, 52, 85, duration=duration, brightness=brightness),
    RGBTransition(0, 38, 79, duration=duration, brightness=brightness),
    RGBTransition(0, 25, 78, duration=duration, brightness=brightness),
    RGBTransition(0, 38, 79, duration=duration, brightness=brightness),
    RGBTransition(5, 52, 85, duration=duration, brightness=brightness),
    RGBTransition(11, 64, 87, duration=duration, brightness=brightness),
    ]

    flow = Flow(
    count=50,
    action=Flow.actions.recover,
    transitions=transitions
    )

    bulb.start_flow(flow)

    return redirect('lightthemes:lighthome')
Beispiel #2
0
def light_on(request):
    userIP = AddDevice.objects.get(owner=request.user).ip
    bulb = Bulb(userIP)

    bulb.turn_on()

    return redirect('lightthemes:lighthome')
def fire_theme(request):

    userIP = AddDevice.objects.get(owner=request.user).ip
    bulb = Bulb(userIP)

    duration = 1000
    brightness = 100

    transitions = [
    RGBTransition(255,0,0, duration=duration, brightness=brightness),
    RGBTransition(255,90,0, duration=duration, brightness=brightness),
    RGBTransition(255,154,0, duration=duration, brightness=brightness),
    RGBTransition(255,206,0, duration=duration, brightness=brightness),
    RGBTransition(255,232,8, duration=duration, brightness=brightness),
    RGBTransition(255,206,0, duration=duration, brightness=brightness),
    RGBTransition(255,154,0, duration=duration, brightness=brightness),
    RGBTransition(255,90,0, duration=duration, brightness=brightness),
    RGBTransition(255,0,0, duration=duration, brightness=brightness),
    ]

    flow = Flow(
    count=50,
    action=Flow.actions.recover,
    transitions=transitions
    )

    bulb.start_flow(flow)

    return redirect('lightthemes:lighthome')
Beispiel #4
0
def disco():
    """
    Color changes to the beat.
    :param int bpm: The beats per minute to pulse to.
    :returns: A list of transitions.
    :rtype: list
    """
    bpm = tempo()
    duration = int(60000 / bpm)
    transitions = [
        HSVTransition(0, 100, duration=duration, brightness=100),
        HSVTransition(0, 100, duration=duration, brightness=1),
        HSVTransition(90, 100, duration=duration, brightness=100),
        HSVTransition(90, 100, duration=duration, brightness=1),
        HSVTransition(180, 100, duration=duration, brightness=100),
        HSVTransition(180, 100, duration=duration, brightness=1),
        HSVTransition(270, 100, duration=duration, brightness=100),
        HSVTransition(270, 100, duration=duration, brightness=1),
    ]
    bulb = Bulb(ip)
    flow = Flow(
        count=0,  # Cycle forever.
        transitions=transitions)

    bulb.start_flow(flow)

    return jsonify({'status': 'OK'})
Beispiel #5
0
 def __init__(self, name, ip, support, model, power):
     self.name = name
     self.ip = ip
     self.support = support
     self.model = model
     self.power = power
     self.bulb = Bulb(self.ip, auto_on=True)
def sun_theme(request):

    userIP = AddDevice.objects.get(owner=request.user).ip
    bulb = Bulb(userIP)

    duration = 1000
    brightness = 100

    transitions = [
    RGBTransition(100, 96, 48, duration=duration, brightness=brightness),
    RGBTransition(100, 89, 41, duration=duration, brightness=brightness),
    RGBTransition(100, 80, 32, duration=duration, brightness=brightness),
    RGBTransition(99, 69, 20, duration=duration, brightness=brightness),
    RGBTransition(98, 59, 11, duration=duration, brightness=brightness),
    RGBTransition(98, 53, 3, duration=duration, brightness=brightness),
    ]

    flow = Flow(
    count=50,
    action=Flow.actions.recover,
    transitions=transitions
    )

    bulb.start_flow(flow)

    return redirect('lightthemes:lighthome')
Beispiel #7
0
class ColorBulb(WhiteBulb):
    def __init__(self, ip):
        super()
        self.bulb = Bulb(ip)

    def color_red(self):
        self.bulb.set_rgb(255, 0, 0)
        print("Setting the light to red...")

    def color_green(self):
        self.bulb.set_rgb(0, 255, 0)
        print("Setting the light to green...")

    def color_blue(self):
        self.bulb.set_rgb(0, 0, 255)
        print("Setting the light to blue...")

    def color_white(self):
        self.bulb.set_color_temp(4000)
        print("Setting the light to white...")

    def color_hex(self, hex):
        hex = hex.lstrip('#')
        red, green, blue = tuple(int(hex[i:i + 2], 16) for i in (0, 2, 4))
        self.bulb.set_rgb(red, green, blue)
        print("Setting the light to RGB(", str(red), str(green), str(blue),
              ")...")
Beispiel #8
0
class YeelightSkill(MycroftSkill):

    # The constructor of the skill, which calls MycroftSkill's constructor
    def __init__(self):
        super(YeelightSkill, self).__init__(name="YeelightSkill")

        # Check and then monitor for credential changes
        self.settings.set_changed_callback(self.on_websettings_changed)

        # Initialize working variables used within the skill.
        self.bulb = Bulb(self.settings.get("yeelight_bulb_ip", ""))
        self.philips_lamp = miio.device(self.settings.get("philips_lamp_ip", ""), self.settings.get("philips_lamp_token", ""))
        self.vacuum_cleaner = miio.device(self.settings.get("vacuum_cleaner_ip", ""), self.settings.get("vacuum_cleaner_token", ""))

    def on_websettings_changed(self):
        self.bulb = Bulb(self.settings.get("yeelight_bulb_ip", ""))
        self.philips_lamp = miio.device(self.settings.get("philips_lamp_ip", ""), self.settings.get("philips_lamp_token", ""))
        self.vacuum_cleaner = miio.device(self.settings.get("vacuum_cleaner_ip", ""), self.settings.get("vacuum_cleaner_token", ""))


    # The "handle_xxxx_intent" function is triggered by Mycroft when the
    # skill's intent is matched.  The intent is defined by the IntentBuilder()
    # pieces, and is triggered when the user's utterance matches the pattern
    # defined by the keywords.  In this case, the match occurs when one word
    # is found from each of the files:
    #    vocab/en-us/Hello.voc
    #    vocab/en-us/World.voc
    # In this example that means it would match on utterances like:
    #   'Hello world'
    #   'Howdy you great big world'
    #   'Greetings planet earth'
    @intent_handler(IntentBuilder("YeelightBulb").require("Switch").require("Bulb").require("State"))
    def handle_switch_yeelight_bulb(self, message):

        if message.data["State"] == "on":
            self.bulb.turn_on()
            self.speak_dialog("bulb.switch", data={"state": "on"})

        elif message.data["State"] == "off":
            self.bulb.turn_off()
            self.speak_dialog("bulb.switch", data={"state": "off"})


    @intent_handler(IntentBuilder("PhilipsLamp").require("Switch").require("Bedroom").require("Bulb").require("State"))
    def handle_switch_philips_lamp(self, message):

        if message.data["State"] == "on":
            self.philips_lamp.send('set_power', ['on'])
            self.speak_dialog("bulb.switch", data={"state": "on"})

        elif message.data["State"] == "off":
            self.philips_lamp.send('set_power', ['off'])
            self.speak_dialog("bulb.switch", data={"state": "off"})

    @intent_handler(IntentBuilder("CleanHouse").require("Clean"))
    def handle_clean_house(self, message):

        self.vacuum_cleaner.send("app_start")
        self.speak_dialog("clean.started")
Beispiel #9
0
 def test_ip(i):
     try:
         ip = f'192.168.1.{i}'
         b = Bulb(ip)
         print(b.get_properties())
         return ip
     except BulbException as e:
         return None
Beispiel #10
0
 def toggle_bulb(self, bulb):
     bulb_obj = Bulb(bulb['ip'])
     response = bulb_obj.toggle()
     if response == 'ok':
         logger.info(f'Toggled {bulb["hostname"]} at {bulb["ip"]}')
     else:
         logger.error(
             f'Toggle error for {bulb["hostname"]} at {bulb["ip"]}')
Beispiel #11
0
def turnBulbOn() -> None:
    loop = asyncio.get_event_loop()
    bulbStatusAndIp: BulbModel = loop.run_until_complete(discoverLocalBulbs())
    #loop.close()

    bulb = Bulb(bulbStatusAndIp.ip)

    bulb.turn_on()
Beispiel #12
0
async def toggleBulbStatus() -> None:
    loop = asyncio.get_event_loop()
    bulbStatusAndIp: BulbModel = loop.run_until_complete(discoverLocalBulbs())
    loop.close()

    bulb = Bulb(bulbStatusAndIp.ip)

    bulb.turn_off() if bulbStatusAndIp.status == "on" else bulb.turn_on()
Beispiel #13
0
 def turnOn(self):
     if not self.treeview.focus():
         messagebox.showwarning('Ops..', 'No item selected')
     else:
         select_bulb = self.treeview.focus()
         res = self.treeview.item(select_bulb)
         ip = res['values'][1]
         bulb = Bulb(ip)
         bulb.turn_on()
Beispiel #14
0
def color_option():
    global Host 
    command = "'" + Host + "'" +  " , auto_on=True"
    print ('command: ',command)
    #bulb = Bulb(Host, auto_on=True)
    #bulb = Bulb(str(command))
    bulb = Bulb('192.168.1.207', auto_on=True)
    bulb.start_flow(flow)
    time.sleep(10)
    bulb.turn_off()
Beispiel #15
0
 def start(self):
     print(2)
     #print(discover_bulbs())
     bulb = Bulb("192.168.0.101")
     for r in range(1, 256, 40):
         for g in range(1, 256, 40):
             for b in range(1, 256, 40):
                 print('{} {} {}'.format(r, g, b))
                 bulb.set_rgb(r, g, b)
                 time.sleep(1)
Beispiel #16
0
    def __init__(self):
        super(YeelightSkill, self).__init__(name="YeelightSkill")

        # Check and then monitor for credential changes
        self.settings.set_changed_callback(self.on_websettings_changed)

        # Initialize working variables used within the skill.
        self.bulb = Bulb(self.settings.get("yeelight_bulb_ip", ""))
        self.philips_lamp = miio.device(self.settings.get("philips_lamp_ip", ""), self.settings.get("philips_lamp_token", ""))
        self.vacuum_cleaner = miio.device(self.settings.get("vacuum_cleaner_ip", ""), self.settings.get("vacuum_cleaner_token", ""))
    def __init__(self, name, ipAddrOrName=None):
        if ipAddrOrName is None:
            ipAddrOrName = name

        self.bulb = Bulb(ipAddrOrName)
        self.name = name
        try:
            self.bulb.set_name(name)
        except Exception as exc:
            print "Caught exception socket.error : %s" % exc
Beispiel #18
0
 def turn_off_bulbs(self):
     logger.info("Turning off bulbs...")
     for bulb in self.bulbs:
         bulb_obj = Bulb(bulb['ip'])
         response = bulb_obj.turn_off()
         if response == 'ok':
             logger.info(f'{bulb["hostname"]} turned off at {bulb["ip"]}')
         else:
             logger.error(
                 f'Turn off error for {bulb["hostname"]} at {bulb["ip"]}')
Beispiel #19
0
def main(args):
    bulb = Bulb(args.BULB_IP)
    stockSymbol = args.STOCK_SYMBOL
    lighterModeFactor = 50 if args.lighter_mode else 0
    previousPrice = getPreviousPrice(stockSymbol)
    currentPrice = getCurrentPrice(stockSymbol)
    if previousPrice != currentPrice:
        setBulbColor(bulb, previousPrice, currentPrice, lighterModeFactor)
        storeCurrentPrice(stockSymbol, currentPrice)
    else:
        bulb.set_power_mode(PowerMode.NORMAL)
Beispiel #20
0
def control_yeelight(status):
    # 当前局域网存在灯设备
    if len(discover_bulbs()):
        # 连接到yeelight
        bulb = Bulb(bulb_ip)
        dic = bulb.get_properties()
        # {'sat': '100', 'color_mode': '2', 'ct': '6500', 'delayoff': '0', 'power': 'on', 'rgb': '16711680', 'hue': '359', 'music_on': '0', 'bright': '82', 'name': None, 'flowing': '0'}
        if dic.has_key('power'):
			power = dic.get('power')
			if bulb and status == True and power == 'off':
            	bulb.turn_on()
	    	else:
        		print("未找到灯")
Beispiel #21
0
def off():

  if ip is None:
      return jsonify({'status': 'error', 'message': 'no bulb found'})

  bulb = Bulb(ip)

  try:
      bulb.turn_off()
  except:
      return jsonify({'status': 'error', 'message': 'could not turn off bulb'})

  return jsonify({'status': 'OK'})
Beispiel #22
0
def keep_on():
    io.setmode(io.BOARD)
    pin = 7
    io.setup(pin, io.IN)

    light_ip = "192.168.178.31"
    bulb = Bulb(light_ip)
    bulb.turn_off()

    delay = 30 * 8
    # delay = 5
    last_activation = -1.

    while True:
        activation = io.input(pin)

        if activation == 1:
            try:
                if last_activation < 0:
                    bulb.turn_on()
                last_activation = time.time()
            except BulbException:
                pass

        if last_activation >= 0. and time.time() - last_activation >= delay:
            try:
                bulb.turn_off()
                last_activation = -1.
            except BulbException:
                pass

        print(activation)

        time.sleep(.1)
Beispiel #23
0
    def initializeBulb(self):   
        try:
            self.bulb = Bulb(self.ip, effect="smooth", duration=1000)
            print("Initialized bulb successfully")
        except:
            print("Bulb initializatio failed")

        try:
            self.bulb.start_music()
            print("Started music mode successfully")
        except:
            print("Music mode failed")

        threading.Timer(self.reconnectInterval, self.initializeBulb).start()
Beispiel #24
0
def brightness():

   if ip is None:
       return jsonify({'status': 'error', 'message': 'no bulb found'})

   bulb = Bulb(ip)

   try:
       bulb.set_brightness(10)

   except:
       return jsonify({'status': 'error', 'message': 'could not adjust brightness'})


   return jsonify({'status': 'OK'})
Beispiel #25
0
def fire_theme(request):

    userIP = AddDevice.objects.get(owner=request.user).ip
    bulb = Bulb(userIP)

    transitions = [
        TemperatureTransition(1700, duration=4000),
        TemperatureTransition(6500, duration=4000)
    ]

    flow = Flow(count=50, action=Flow.actions.recover, transitions=transitions)

    bulb.start_flow(flow)

    return redirect('lightthemes:lighthome')
    def __init__(self, rms_th=300, monitor_type='Live', *args, **kwargs):
        print('Search for light bulb...')
        self.conf_rms_threshold = rms_th
        self.monitor_type = monitor_type
        print('conf_rms_threshold set as: "' + str(self.conf_rms_threshold) +
              '"')
        bulbs_data = discover_bulbs()
        print(bulbs_data)
        ip = bulbs_data[0]["ip"]
        print(ip)
        self.bulb = Bulb(ip, effect="smooth", duration=1000)
        self.bulb.turn_on()
        self.bulb.set_rgb(255, 255, 255)

        super(Monitor, self).__init__(*args, **kwargs)
Beispiel #27
0
    def initialize(self):
        bulb_ip = self.settings.get('bulb_ip', "192.168.0.129")
        bulb = Bulb(bulb_ip, auto_on=True)

        yeelight_on_intent = IntentBuilder('OnIntent').require(
            'lightKeyword').require('onKeyword').build()
        self.register_intent(yeelight_on_intent,
                             self.handle_yeelight_on_intent)

        yeelight_off_intent = IntentBuilder('OffIntent').require(
            'lightKeyword').require('offKeyword').build()
        self.register_intent(yeelight_off_intent,
                             self.handle_yeelight_off_intent)

        yeelight_dim_intent = IntentBuilder('dimIntent').require(
            'lightKeyword').require('dimKeyword').build()
        self.register_intent(yeelight_dim_intent,
                             self.handle_yeelight_dim_intent)

        yeelight_bright_intent = IntentBuilder('brightIntent').require(
            'lightKeyword').require('brightKeyword').build()
        self.register_intent(yeelight_bright_intent,
                             self.handle_yeelight_bright_intent)

        yeelight_night_intent = IntentBuilder('nightIntent').require(
            'lightKeyword').require('nightKeyword').build()
        self.register_intent(yeelight_night_intent,
                             self.handle_yeelight_night_intent)
Beispiel #28
0
    def detect_lights(self):
        discovered_lights = discover_bulbs()

        for light in discovered_lights:
            # Check light compatibility
            if 'capabilities' in light and 'model' in light['capabilities'] \
                    and light['capabilities']['model'] not in ['mono', 'color', 'stripe', 'bslamp', 'ceiling']:
                continue

            # Check reply consistency
            if 'ip' not in light:
                continue

            # Set device name
            device_name = light['capabilities']['name']

            # Check if device has a name
            if device_name == "":
                device_name = set_light_name(light['ip'],
                                             light['capabilities']['model'],
                                             light['capabilities']['id'])
                if device_name == "":
                    continue

            # Add usable light to list
            self.lights[device_name] = Bulb(light['ip'])

            # Turn off light
            try:
                self.lights[device_name].turn_off()
            except:
                print("Communication failed with Yeelight {}, light disabled".
                      format(device_name))
                del self.lights[device_name]
                continue
Beispiel #29
0
 def test_on_off(self):
     from yeelight import Bulb
     with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
         self.get_component().send(state='ON')
         self.bulb_mock.return_value.turn_on.assert_called_once()
         self.get_component().send(state='OFF')
         self.bulb_mock.return_value.turn_off.assert_called_once()
Beispiel #30
0
 def test_toggle(self):
     from yeelight import Bulb
     with patch('yeelight.discover_bulbs', return_value=[Bulb('')]):
         self.bulb_mock.return_value.get_properties = Mock(
             return_value={'power': 'on'})
         self.get_component().send(state='TOGGLE')
         self.bulb_mock.return_value.turn_off.assert_called_once()
Beispiel #31
0
def disco (ip, 120):


    if ip is None:
        return jsonify({'status': 'error', 'message': 'no bulb found'})

    bulb = Bulb(ip)