Exemplo n.º 1
0
def lsd(duration):
    """Color changes to a trippy palette."""
    click.echo("Enjoy your trip.")
    transitions = tr.lsd(duration=duration)
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 2
0
def police2():
    """More police lights."""
    click.echo("It's the fuzz again!")
    transitions = tr.police2()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 3
0
def sunrise():
    # Prevent autoset from taking over
    with open(os.getcwd() + '/manualOverride.txt', 'w+') as f:
        f.write(datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'))
    overallDuration = 1200000  # 1200000 == 20 min
    on()
    for i in get_bulbs():
        i.set_brightness(0)
        i.set_rgb(255, 0, 0)
    time.sleep(1)

    transitions = [
        yeelight.HSVTransition(hue=39,
                               saturation=100,
                               duration=overallDuration * 0.5,
                               brightness=80),
        yeelight.TemperatureTransition(degrees=3200,
                                       duration=overallDuration * 0.5,
                                       brightness=80)
    ]

    for i in get_bulbs():
        i.start_flow(
            yeelight.Flow(count=1,
                          action=yeelight.Flow.actions.stay,
                          transitions=transitions))
Exemplo n.º 4
0
def redgreenblue():
    """Change from red to green to blue."""
    click.echo("Pretty colors.")
    transitions = tr.rgb()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 5
0
def random(duration):
    """Random colors."""
    click.echo("Random colors!")
    transitions = tr.randomloop(duration=duration)
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 6
0
def strobe():
    """Epilepsy warning."""
    click.echo("Strobing.")
    transitions = tr.strobe()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 7
0
def slowdown():
    """Cycle with increasing transition time."""
    click.echo("Sloooooowwwwlllyyy..")
    transitions = tr.slowdown()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 8
0
def temp():
    """Slowly-changing color temperature."""
    click.echo("Enjoy.")
    transitions = tr.temp()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 9
0
    def sunrise(self):
        """
        Simulate a sunrise
        """
        writeManualOverride(room=self.name, offset=datetime.timedelta(hours=2))
        self.writeState('day')
        bulbLog.info('Sunrise start')
        overallDuration = 1200000  # 1200000 == 20 min
        self.on()
        try:
            for i in self.bulbs:
                i.set_brightness(0)
                i.set_rgb(255, 0, 0)
            logger.info("Set initial state for sunrise")
            time.sleep(1)
            transitions = [
                yeelight.HSVTransition(hue=39,
                                       saturation=100,
                                       duration=overallDuration * 0.5,
                                       brightness=80),
                yeelight.TemperatureTransition(degrees=3200,
                                               duration=overallDuration * 0.5,
                                               brightness=80)
            ]
            for i in self.bulbs:
                i.start_flow(
                    yeelight.Flow(count=1,
                                  action=yeelight.Flow.actions.stay,
                                  transitions=transitions))
            logger.info('Sunrise Flowing')

        except Exception:
            logger.exception('Got exception during sunrise')
Exemplo n.º 10
0
def sunrise():
    """
    Simulate a sunrise.
    :return:
    """
    # Prevent autoset from taking over
    writeManualOverride(offset=datetime.timedelta(hours=2))
    
    # Write the new state, prevent timing collisions
    global_action('writeState','day')
    
    bulbLog.info('Sunrise start')
    overallDuration = 1200000  # 1200000 == 20 min
    global_action('on')
    try:
        blbs = [blb for room_blbs in ROOMS.values() for blb in room_blbs]
        for bulb in blbs:
            bulb.set_brightness(0)
            bulb.set_rgb(255, 0, 0)

        time.sleep(1)

        transitions = [yeelight.HSVTransition(hue=39, saturation=100,
                                              duration=overallDuration * 0.5, brightness=80),
                       yeelight.TemperatureTransition(degrees=3200,
                                                      duration=overallDuration * 0.5, brightness=80)]

        for bulb in blbs:
            bulb.start_flow(yeelight.Flow(count=1, action=yeelight.Flow.actions.stay, transitions=transitions))

    except Exception:
        logger.exception('Got exception during sunrise')
Exemplo n.º 11
0
def alarm():
    """Flash a red alarm."""
    click.echo("Alarm!")
    transitions = tr.alarm(500)
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 12
0
def christmas():
    """Christmas lights."""
    click.echo("Happy holidays.")
    transitions = tr.christmas()
    flow = yeelight.Flow(count=0, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 13
0
 def set_flow(self, index, flow_preset, count=0):
     bulb = self.get_bulb(index)
     flow = yeelight.Flow(
         count=count,
         transitions=flow_preset,
     )
     result = bulb.start_flow(flow)
     return result
Exemplo n.º 14
0
 def rgb(self, red, green, blue):
     red = int(red)
     green = int(green)
     blue = int(blue)
     transition = yeelight.RGBTransition(red=red, green=green, blue=blue)
     for i in self.bulbs:
         i.start_flow(
             yeelight.Flow(count=1,
                           action=yeelight.Flow.actions.stay,
                           transitions=[transition]))
Exemplo n.º 15
0
 def colorTempFlow(self, temperature=3200, duration=3000, brightness=80):
     # control all lights at once
     # makes things look more condensed
     transition = yeelight.TemperatureTransition(degrees=temperature,
                                                 duration=duration,
                                                 brightness=brightness)
     for i in self.bulbs:
         i.start_flow(
             yeelight.Flow(count=1,
                           action=yeelight.Flow.actions.stay,
                           transitions=[transition]))
Exemplo n.º 16
0
    def start_flow(self, transitions, count=0):
        """Start flow."""
        import yeelight

        try:
            flow = yeelight.Flow(
                count=count,
                transitions=self.transitions_config_parser(transitions))

            self._bulb.start_flow(flow)
        except yeelight.BulbException as ex:
            _LOGGER.error("Unable to set effect: %s", ex)
Exemplo n.º 17
0
    def start_flow(self, transitions, count=0, action=ACTION_RECOVER):
        """Start flow."""
        import yeelight

        try:
            flow = yeelight.Flow(count=count,
                                 action=yeelight.Flow.actions[action],
                                 transitions=transitions)

            self._bulb.start_flow(flow, light_type=self.light_type)
            self.device.update()
        except yeelight.BulbException as ex:
            _LOGGER.error("Unable to set effect: %s", ex)
Exemplo n.º 18
0
def pulse(hex_color, pulses):
    """Pulse the bulb in a specific color."""
    red, green, blue = hex_color_to_rgb(hex_color)
    transitions = tr.pulse(red, green, blue)

    for bulb in BULBS:
        # Get the initial bulb state.
        if bulb.get_properties().get("power", "off") == "off":
            action = yeelight.Flow.actions.off
        else:
            action = yeelight.Flow.actions.recover

        bulb.start_flow(yeelight.Flow(count=pulses, action=action, transitions=transitions))
Exemplo n.º 19
0
def colorTempFlow(temperature=3200, duration=3000, brightness=80):
    # control all lights at once
    # makes things look more condensed
    transition = yeelight.TemperatureTransition(degrees=temperature,
                                                duration=duration,
                                                brightness=brightness)
    for i in get_bulbs():
        try:
            i.start_flow(
                yeelight.Flow(count=1,
                              action=yeelight.Flow.actions.stay,
                              transitions=[transition]))
        except Exception:
            logger.exception('Failed for %s', str(i))
Exemplo n.º 20
0
Arquivo: cli.py Projeto: josky1/yeecli
def sundown(duration):
    """Simulate sunrise in seconds (default 5min)."""
    click.echo("Good night!")
    # We're using seconds for duration because it's a more natural timescale
    # for this preset.
    duration = duration * 1000
    transitions = [
        tr.TemperatureTransition(5000, duration=50, brightness=100),
        tr.TemperatureTransition(2100, duration=duration / 2, brightness=50),
        tr.TemperatureTransition(1700, duration=duration / 2, brightness=1),
    ]
    flow = yeelight.Flow(count=1,
                         action=yeelight.flow.Action.stay,
                         transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 21
0
def sunrise(duration):
    """Simulate sunrise in seconds (default 5min)."""
    click.echo("Good morning!")
    # We're using seconds for duration because it's a more natural timescale
    # for this preset.
    duration = duration * 1000
    transitions = [
        # First set to minimum temperature, low brightness, nearly immediately.
        tr.TemperatureTransition(1700, duration=50, brightness=1),
        # Then slowly transition to higher temperature, max brightness.
        # 5000 is about regular daylight white.
        tr.TemperatureTransition(2100, duration=duration / 2, brightness=50),
        tr.TemperatureTransition(5000, duration=duration / 2, brightness=100),
    ]
    flow = yeelight.Flow(count=1, action=yeelight.flow.Action.stay, transitions=transitions)
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 22
0
def rgbFlow(red=0, green=0, blue=0):
    red = int(red)
    green = int(green)
    blue = int(blue)
    bulbs = get_bulbs()
    bright = bulbs[0].get_properties(['bright'])['bright']

    for i in bulbs:
        i.start_flow(
            yeelight.Flow(count=1,
                          action=yeelight.Flow.actions.stay,
                          transitions=[
                              yeelight.RGBTransition(red,
                                                     green,
                                                     blue,
                                                     brightness=int(bright))
                          ]))
Exemplo n.º 23
0
import yeelight
import yeelight.transitions
import time
import random

bulb = yeelight.Bulb("192.168.1.83")
bulb.start_music()

bulb.set_brightness(random.random() * 100)
flow = yeelight.Flow(count=1,
                     transitions=yeelight.transitions.pulse(red=255,
                                                            blue=0,
                                                            green=255))

bulb.start_flow(flow)
Exemplo n.º 24
0
def on_message(ws, message):
    global lastRGB
    global noteHitRgbToSpike
    global noteHitTimeSinceLastSpike

    event = json.loads(message)
    if event["event"] == "noteCut":
        if config.lightingMode.mode == "Score":
            print("Received event:", event["event"])
            rgb = getScoreRGB(event)
            print("RGB:", rgb)
            if rgb != lastRGB:
                lastRGB = rgb
                changeLightColour(rgb)
        elif config.lightingMode.mode == "Notes":
            print("Note cut, updating lights to:",
                  event["noteCut"]["noteType"][-1:])
            try:
                if (time.time() - noteHitTimeSinceLastSpike) > 0.1:
                    noteHitRgbToSpike = np.array([0, 0, 0])
                    noteHitTimeSinceLastSpike = time.time()
                if event["noteCut"]["noteType"][-1:] == "A":
                    noteHitRgbToSpike = np.add(
                        noteHitRgbToSpike, np.array(config.colours.leftColour))
                elif event["noteCut"]["noteType"][-1:] == "B":
                    noteHitRgbToSpike = np.add(
                        noteHitRgbToSpike,
                        np.array(config.colours.rightColour))
                else:
                    return
                np.clip(noteHitRgbToSpike, 0, 255)
            except Exception as e:
                print(e)
            print("Combined RGB to:", noteHitRgbToSpike)
            #Only flow if 50 mills has passed since last flow
            noteHitFlow = yeelight.Flow(
                count=1,
                action=yeelight.Flow.actions.recover,
                transitions=[
                    yeelight.RGBTransition(
                        noteHitRgbToSpike[0],
                        noteHitRgbToSpike[1],
                        noteHitRgbToSpike[2],
                        brightness=config.colours.spikeBrightness),
                ])
            startLightFlow(noteHitFlow)

        if config.lightingMode.spikeBrightnessOnNoteCut and config.lightingMode.mode != "Notes":
            print("Note cut received, spiking brightness")
            brightnessSpikeFlow = yeelight.Flow(
                count=1,
                action=yeelight.Flow.actions.recover,
                transitions=[
                    yeelight.RGBTransition(
                        lastRGB[0],
                        lastRGB[1],
                        lastRGB[2],
                        brightness=config.colours.spikeBrightness),
                    yeelight.SleepTransition(duration=50),
                    yeelight.RGBTransition(
                        lastRGB[0],
                        lastRGB[1],
                        lastRGB[2],
                        brightness=config.colours.neutralBrightness),
                ])
            startLightFlow(brightnessSpikeFlow)

    elif event["event"] == "beatmapEvent":
        if config.lightingMode.mode == "SongLights":
            rgb = getSongLights(event)
            print("RGB:", rgb)
            if rgb != lastRGB:
                changeLightColour(rgb)
                lastRGB = rgb
    elif event["event"] == "finished":
        changeLightBrightness(config.colours.neutralBrightness)
        changeLightColour(config.colours.neutral)
    elif event["event"] == "failed":
        changeLightBrightness(config.colours.neutralBrightness)
        changeLightColour(config.colours.failedLevel)
        time.sleep(3)
        changeLightColour(config.colours.neutral)
Exemplo n.º 25
0
def disco(bpm):
    """Party!"""
    click.echo("Party mode: activated.")
    flow = yeelight.Flow(count=0, transitions=tr.disco(bpm))
    for bulb in BULBS:
        bulb.start_flow(flow)
Exemplo n.º 26
0
def blink():
    #bulb.set_scene(yeelight.SceneClass.CT, 6500, 100)
    bulb.set_brightness(100)
    time.sleep(1)
    # Turning the bulb off completely will disconnect music mode
    bulb.set_brightness(1)
    #bulb.set_scene(yeelight.SceneClass.CT, 6500, 1)
    time.sleep(1)

blink_transitions = [
    yeelight.TemperatureTransition(duration=50, brightness=100, degrees=6700),
    yeelight.SleepTransition(duration=1000),
    yeelight.TemperatureTransition(duration=50, brightness=0, degrees=6700),
    yeelight.SleepTransition(duration=1000),
]
blink_flow = yeelight.Flow(2, yeelight.Flow.actions.off, blink_transitions)

alarm_transitions = [
    yeelight.TemperatureTransition(duration=50, brightness=100, degrees=6700),
    yeelight.SleepTransition(duration=8000),
    yeelight.TemperatureTransition(duration=50, brightness=0, degrees=1700),
    yeelight.SleepTransition(duration=1000),

    yeelight.TemperatureTransition(duration=50, brightness=100, degrees=6700),
    yeelight.SleepTransition(duration=3000),
    yeelight.TemperatureTransition(duration=50, brightness=0, degrees=1700),
    yeelight.SleepTransition(duration=700),
]
alarm_flow = yeelight.Flow(0, yeelight.Flow.actions.off, alarm_transitions)

def disconnect_bulb(bulb):