36
python-yeelight Documentation Release 0.5.4 Stavros Korokithakis Oct 10, 2020

Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight DocumentationRelease 0.5.4

Stavros Korokithakis

Oct 10, 2020

Page 2: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original
Page 3: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

Contents

1 Installation 3

2 Usage 5

3 Effects 9

4 Notifications 114.1 Working with Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 yeelight package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.3 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Python Module Index 29

Index 31

i

Page 4: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

ii

Page 5: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

The YeeLight Python library is a small library that lets you control your YeeLight RGB LED bulbs over WiFi. Thelatest version can be found at:

https://gitlab.com/stavros/python-yeelight

To see a real-world usage example, have a look at yeecli, a command-line YeeLight utility that uses this library.

yeelight currently does not support some features of the YeeLight API, such as discovery, but is mostly otherwisecomplete.

Contents 1

Page 6: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

2 Contents

Page 7: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

CHAPTER 1

Installation

To install yeelight, you can use pip:

pip install yeelight

That’s all that’s required to install the library.

3

Page 8: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

4 Chapter 1. Installation

Page 9: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

CHAPTER 2

Usage

First of all, you need to discover your bulb’s IP. If you already know it, you can skip to the next section.

Discovering all the devices on your network and their capabilities is easy with discover_bulbs:

>>> from yeelight import discover_bulbs>>> discover_bulbs()[{'capabilities': {'bright': '50',

'color_mode': '1','ct': '2700','fw_ver': '45','hue': '359','id': '0x0000000002dfb19a','model': 'color','name': 'bedroom','power': 'off','rgb': '16711935','sat': '100','support': 'get_prop set_default set_power toggle '

'set_bright start_cf stop_cf set_scene cron_add ''cron_get cron_del set_ct_abx set_rgb set_hsv ''set_adjust set_music set_name'},

'ip': '192.168.0.19','port': 55443},{'capabilities': {'bright': '50',

'color_mode': '1','ct': '2700','fw_ver': '45','hue': '359','id': '0x0000000002dfb2f1','model': 'color','name': 'livingroom','power': 'off','rgb': '16711935','sat': '100','support': 'get_prop set_default set_power toggle '

(continues on next page)

5

Page 10: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

(continued from previous page)

'set_bright start_cf stop_cf set_scene cron_add ''cron_get cron_del set_ct_abx set_rgb set_hsv ''set_adjust set_music set_name'},

'ip': '192.168.0.23','port': 55443}]

That’s it, now you know the addresses of all the bulbs on your local network.

Now that you’ve discovered your bulb’s IP, it’s time to instantiate a new Bulb:

>>> from yeelight import Bulb>>> bulb = Bulb("192.168.0.19")

# Turn the bulb on.>>> bulb.turn_on()

# Turn the bulb off.>>> bulb.turn_off()

# Toggle power.>>> bulb.toggle()

# Set brightness to 50%.>>> bulb.set_brightness(50)

# Set brightness of the background light to 50%, if your# light supports it.>>> from yeelight import LightType>>> bulb.set_brightness(50, light_type=LightType.Ambient)

# Set RGB value.>>> bulb.set_rgb(255, 0, 0)

# Set HSV value.>>> bulb.set_hsv(320, 100, 50)

# Set hue and saturation, but keep value (brightness) the same.>>> bulb.set_hsv(320, 100)

# Set color temperature.>>> bulb.set_color_temp(4700)

# Save this setting as default.>>> bulb.set_default()

For efficiency, yeelight will use a single TCP connection for all the above commands. However, this means that,if there’s an error, a command could raise a socket.error exception and need to be retried. Note that YeeLightconnections are rate-limited to 60 per minute. If you need your connection to not have a limit, you need to use Musicmode.

For a complete list of the commands you can issue, see the API reference.

By default, yeelight will refuse to make any changes to the bulb if it’s off:

>>> bulb.set_brightness(10)AssertionError: Commands have no effect when the bulb is off.

You can check the bulb’s state by reading its properties:

6 Chapter 2. Usage

Page 11: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

>>> bulb.get_properties(){'bright': u'10','color_mode': u'2','ct': u'2700','delayoff': u'0','flowing': u'0','hue': u'300','music_on': u'0','name': u'My light','power': u'off','rgb': u'16737280','sat': u'100'}

Notice that the properties don’t include flow_params by default, as that causes problems. If you want that, specifyit as an argument to get_properties().

If you want to always turn the bulb on before running a command, set auto_on to True. This will refresh the bulb’sproperties before most calls, and will cost you an extra message per command, so watch out for rate-limiting:

>>> bulb.auto_on = True

# Or, when instantiating:>>> bulb = Bulb("192.168.0.19", auto_on=True)

# This will work even if the bulb is off.>>> bulb.set_brightness(10)

For documentation of the Flow feature, see Working with Flow.

7

Page 12: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

8 Chapter 2. Usage

Page 13: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

CHAPTER 3

Effects

yeelight provides full support for effects. Effects control whether the bulb changes from one state to the otherimmediately or gradually, and how long the gradual change takes.

You can either specify effects to run by default when instantiating, or with each call:

>>> bulb = Bulb("192.168.0.19", effect="smooth", duration=1000)

# This will turn the bulb on gradually within one second:>>> bulb.turn_on()

# This will turn the bulb on immediately:>>> bulb.turn_on(effect="sudden")

# You can easily change the default effect, too:>>> bulb.effect = "sudden"

# This will turn the bulb off immediately:>>> bulb.turn_off()

There are two effect types, "sudden" and "smooth". The "sudden" type ignores the duration parameter.

Keep in mind that the effect and duration parameters must be passed by keyword.

9

Page 14: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

10 Chapter 3. Effects

Page 15: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

CHAPTER 4

Notifications

To get read-time state update notifications, run listen in a Thread:

>>> import threading>>> thread = threading.Thread(target=bulb.listen, args=(callback,))>>> thread.start()

# To stop listening:>>> bulb.stop_listening()

Note that the callback function should take one parameter, which will be a dict containing the new/updated parameters.It will be called when last_properties is updated.

You can also use asyncio event loop:

>>> import asyncio>>> async def main():>>> loop = asyncio.get_running_loop()>>> await loop.run_in_executor(None, bulb.listen, callback)>>> asyncio.run(main())

# To stop listening in an event loop:>>> await loop.run_in_executor(None, bulb.stop_listening)

4.1 Working with Flow

“Flow” is a special mode the bulb can be set to, which is basically a list of transitions to perform in succession. Forexample, a flow can be a constant cycling of colors from one to the next, until it is stopped, or it can be a quick blinkof a certain color.

11

Page 16: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

4.1.1 Usage

To create a flow, we need to instantiate a Flow object and add some transitions to it. The Flow object accepts threeparameters, a count, which is the number of loops to perform (NOT the number of transitions!), an action, whichis what to do at the end of the flow, and transitions, a list of the transitions themselves.

In the original protocol spec, the count argument specifies the number of transitions to perform. For example, if youhave 10 transitions, and count is 5, the bulb will stop transitioning in the middle of your flow and exit. This is rathercounter-intuitive, so the yeelight library changes this to mean “number of loops”. If you want to loop once, nomatter how long your transition list, just specify 1. 0 means “loop forever”.

action can be Flow.actions.recover to return to the original state after this flow is stopped (either throughthe stop_flow method or just because the loop has stopped), Flow.actions.stay to just stay at the last stateof the flow, or Flow.actions.off to turn off afterwards.

transitions is a list of transition instances. There are various transition classes available, which are detailed in theAPI reference. The bulbs seem to be limited to around nine transitions (any more will produce an “invalid command”error).

Let’s see a few examples.

4.1.2 Simple example

A simple example is to cycle the color temperature from 1700 to 6500 twice, with a one-second delay in-between (theexamples assume we have a Bulb instance in bulb), and then return to the previous state:

from yeelight import *transitions = [

TemperatureTransition(1700, duration=1000),SleepTransition(duration=1000),TemperatureTransition(6500, duration=1000)

]

flow = Flow(count=2,action=Flow.actions.recover,transitions=transitions

)

bulb.start_flow(flow)

4.1.3 Infinite color cycle

We can cycle between colors forever like so:

from yeelight import *transitions = [

RGBTransition(255, 0, 255, duration=1000)]

flow = Flow(count=0, # Cycle forever.transitions=transitions

)

bulb.start_flow(flow)

12 Chapter 4. Notifications

Page 17: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

To stop the flow (and return to the previous state, because of the default Flow.actions.recover action, youcan use stop_flow :

bulb.stop_flow()

4.1.4 Quick pulse

If you want to connect the bulb to a notification system, you can fire off a quick pulse. For example, to pulse the bulbgreen twice when there is a WhatsApp message and return, we can do:

from yeelight import *transitions = [HSVTransition(hue, 100, duration=500)

for hue in range(0, 359, 40)]

flow = Flow(count=2,transitions=transitions

)

bulb.start_flow(flow)

Pretty easy!

4.1.5 Transition presets

The library includes some preset transitions in the yeelight.transitions module, to make it easy for you tostart.

You can use the transitions simply by calling the preset:

from yeelight.transitions import *from yeelight import Flow

flow = Flow(count=10,transitions=disco(), # Call the transition preset to get the

# transitions you like.)

bulb.start_flow(flow)

Remember that the transition presets are functions, so you need to call them. That’s because some of them takeparameters.

4.1.6 Flow presets

The library includes some flow transitions in the yeelight.flows module, to make it easy for you to start.

You can use the flows simply by calling the preset:

from yeelight.flows import *

christmas().start_flow(flow)

4.1. Working with Flow 13

Page 18: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

4.2 yeelight package

This is the autogenerated API documentation. Use it as a reference to the public API of the project.

4.2.1 yeelight module

yeelight.discover_bulbs(timeout=2, interface=False)Discover all the bulbs in the local network.

Parameters

• timeout (int) – How many seconds to wait for replies. Discovery will always takeexactly this long to run, as it can’t know when all the bulbs have finished responding.

• interface (string) – The interface that should be used for multicast packets. Note: ithas to have a valid IPv4 address. IPv6-only interfaces are not supported (at the moment).The default one will be used if this is not specified.

Returns A list of dictionaries, containing the ip, port and capabilities of each of the bulbs in thenetwork.

class yeelight.Bulb(ip, port=55443, effect=’smooth’, duration=300, auto_on=False,power_mode=<PowerMode.LAST: 0>, model=None)

The main controller class of a physical YeeLight bulb.

Parameters

• ip (str) – The IP of the bulb.

• port (int) – The port to connect to on the bulb.

• effect (str) – The type of effect. Can be “smooth” or “sudden”.

• duration (int) – The duration of the effect, in milliseconds. The minimum is 30. Thisis ignored for sudden effects.

• auto_on (bool) – Whether to call ensure_on() to turn the bulb on automaticallybefore each operation, if it is off. This renews the properties of the bulb before each message,costing you one extra message per command. Turn this off and do your own checkingwith get_properties() or run ensure_on() yourself if you’re worried about rate-limiting.

• power_mode (yeelight.PowerMode) – The mode for the light set when poweringon.

• model (str) – The model name of the yeelight (e.g. “color”, “mono”, etc). The setting isused to enable model specific features (e.g. a particular color temperature range).

bulb_typeThe type of bulb we’re communicating with.

Returns a BulbType describing the bulb type.

When trying to access before properties are known, the bulb type is unknown.

Return type yeelight.BulbType

Returns The bulb’s type.

capabilitiesCapabilities obtained via SSDP Discovery.

They will be empty, unless updated via: get_capabilities.

14 Chapter 4. Notifications

Page 19: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Returns Capabilities dict returned by get_capabilities().

cron_add(event_type, value, **kwargs)Add an event to cron.

Example:

>>> bulb.cron_add(CronType.off, 10)

Parameters event_type (yeelight.CronType) – The type of event. Currently, onlyCronType.off.

cron_del(event_type, **kwargs)Remove an event from cron.

Parameters event_type (yeelight.CronType) – The type of event. Currently, onlyCronType.off.

cron_get(event_type, **kwargs)Retrieve an event from cron.

Parameters event_type (yeelight.CronType) – The type of event. Currently, onlyCronType.off.

dev_toggle(**kwargs)Toggle the main light and the ambient on or off.

ensure_on()Turn the bulb on if it is off.

get_capabilities(timeout=2)Get the bulb’s capabilities using the discovery protocol.

Parameters timeout (int) – How many seconds to wait for replies. Discovery will alwaystake exactly this long to run, as it can’t know when all the bulbs have finished responding.

Returns Dictionary, containing the ip, port and capabilities. For example: { ‘id’:‘0x0000000002eb9f61’, ‘model’: ‘ceiling3’, ‘fw_ver’: ‘43’, ‘support’: ‘get_propset_default set_power toggle set_bright set_scene cron_add cron_get cron_del start_cfstop_cf set_ct_abx set_name set_adjust adjust_bright adjust_ct’, ‘power’: ‘on’, ‘bright’:‘99’, ‘color_mode’: ‘2’, ‘ct’: ‘3802’, ‘rgb’: ‘0’, ‘hue’: ‘0’, ‘sat’: ‘0’, ‘name’: ‘’ }

get_model_specs(**kwargs)Return the specifications (e.g. color temperature min/max) of the bulb.

get_properties(requested_properties=[’power’, ’bright’, ’ct’, ’rgb’, ’hue’, ’sat’, ’color_mode’,’flowing’, ’delayoff’, ’music_on’, ’name’, ’bg_power’, ’bg_flowing’, ’bg_ct’,’bg_bright’, ’bg_hue’, ’bg_sat’, ’bg_rgb’, ’nl_br’, ’active_mode’])

Retrieve and return the properties of the bulb.

This method also updates last_properties when it is called.

The current_brightness property is calculated by the library (i.e. not returned by the bulb), andindicates the current brightness of the lamp, aware of night light mode. It is 0 if the lamp is off, and Noneif it is unknown.

Parameters requested_properties (list) – The list of properties to request from thebulb. By default, this does not include flow_params.

Returns A dictionary of param: value items.

Return type dict

4.2. yeelight package 15

Page 20: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

last_propertiesThe last properties we’ve seen the bulb have.

This might potentially be out of date, as there’s no background listener for the bulb’s notifications. Toupdate it, call get_properties.

listen(callback)Listen to state update notifications.

This function is blocking until a socket error occurred or being stopped by stop_listening. It shouldbe run in a Thread or asyncio event loop.

The callback function should take one parameter, containing the new/updates properties. It will be calledwhen last_properties is updated.

Parameters callback (callable) – A callback function to receive state update notification.

modelReturn declared model / model discovered via SSDP Discovery or None.

Returns Device model

music_modeReturn whether the music mode is active.

Return type bool

Returns True if music mode is on, False otherwise.

send_command(method, params=None)Send a command to the bulb.

Parameters

• method (str) – The name of the method to send.

• params (list) – The list of parameters for the method.

Raises BulbException – When the bulb indicates an error condition.

Returns The response from the bulb.

set_adjust(action, prop, **kwargs)Adjust a parameter.

I don’t know what this is good for. I don’t know how to use it, or why. I’m just including it here forcompleteness, and because it was easy, but it won’t get any particular love.

Parameters

• action (str) – The direction of adjustment. Can be “increase”, “decrease” or “circle”.

• prop (str) – The property to adjust. Can be “bright” for brightness, “ct” for colortemperature and “color” for color. The only action for “color” can be “circle”. Why? Whoknows.

set_brightness(brightness, light_type=<LightType.Main: 0>, **kwargs)Set the bulb’s brightness.

Parameters

• brightness (int) – The brightness value to set (1-100).

• light_type (yeelight.LightType) – Light type to control.

set_color_temp(degrees, light_type=<LightType.Main: 0>, **kwargs)Set the bulb’s color temperature.

16 Chapter 4. Notifications

Page 21: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Parameters

• degrees (int) – The degrees to set the color temperature to (min/max are specified bythe model’s capabilities, or 1700-6500).

• light_type (yeelight.LightType) – Light type to control.

set_default(light_type=<LightType.Main: 0>, **kwargs)Set the bulb’s current state as the default, which is what the bulb will be set to on power on.

If you get a “general error” setting this, yet the bulb reports as supporting set_default during discov-ery, disable “auto save settings” in the YeeLight app.

Parameters light_type (yeelight.LightType) – Light type to control.

set_hsv(hue, saturation, value=None, light_type=<LightType.Main: 0>, **kwargs)Set the bulb’s HSV value.

Parameters

• hue (int) – The hue to set (0-359).

• saturation (int) – The saturation to set (0-100).

• value (int) – The value to set (0-100). If omitted, the bulb’s brightness will remain thesame as before the change.

• light_type (yeelight.LightType) – Light type to control.

set_name(name, **kwargs)Set the bulb’s name.

Parameters name (str) – The string you want to set as the bulb’s name.

set_power_mode(mode)Set the light power mode.

If the light is off it will be turned on.

Parameters mode (yeelight.PowerMode) – The mode to switch to.

set_rgb(red, green, blue, light_type=<LightType.Main: 0>, **kwargs)Set the bulb’s RGB value.

Parameters

• red (int) – The red value to set (0-255).

• green (int) – The green value to set (0-255).

• blue (int) – The blue value to set (0-255).

• light_type (yeelight.LightType) – Light type to control.

set_scene(scene_class, *args, **kwargs)Set the light directly to the specified state.

If the light is off, it will first be turned on.

Parameters scene_class (yeelight.SceneClass) – The YeeLight scene class to use.

• COLOR changes the light to the specified RGB color and brightness.

Arguments: * red (int) – The red value to set (0-255). * green (int) – The green value toset (0-255). * blue (int) – The blue value to set (0-255). * brightness (int) – The brightnessvalue to set (1-100).

4.2. yeelight package 17

Page 22: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

• HSV changes the light to the specified HSV color and brightness.

Arguments: * hue (int) – The hue to set (0-359). * saturation (int) – The saturation to set(0-100). * brightness (int) – The brightness value to set (1-100).

• CT changes the light to the specified color temperature.

Arguments: * degrees (int) – The degrees to set the color temperature to (min/max are spec-ified by the model’s capabilities, or 1700-6500). * brightness (int) – The brightness value toset (1-100).

• CF starts a color flow.

Arguments: * flow (yeelight.Flow) – The Flow instance to start.

• AUTO_DELAY_OFF turns the light on to the specified brightness and sets a timer to turn it back offafter the given number of minutes.

Arguments: * brightness (int) – The brightness value to set (1-100). * minutes (int) – Theminutes to wait before automatically turning the light off.

Parameters light_type (yeelight.LightType) – Light type to control.

start_flow(flow, light_type=<LightType.Main: 0>, **kwargs)Start a flow.

Parameters flow (yeelight.Flow) – The Flow instance to start.

start_music(port=0, ip=None)Start music mode.

Music mode essentially upgrades the existing connection to a reverse one (the bulb connects to the library),removing all limits and allowing you to send commands without being rate-limited.

Starting music mode will start a new listening socket, tell the bulb to connect to that, and then close the oldconnection. If the bulb cannot connect to the host machine for any reason, bad things will happen (such aslibrary freezes).

Parameters

• port (int) – The port to listen on. If none is specified, a random port will be chosen.

• ip (str) – The IP address of the host this library is running on. Will be discoveredautomatically if not provided.

stop_flow(light_type=<LightType.Main: 0>, **kwargs)Stop a flow.

Parameters light_type (yeelight.LightType) – Light type to control.

stop_listening()Stop listening to notifications.

stop_music(**kwargs)Stop music mode.

Stopping music mode will close the previous connection. Calling stop_music more than once, or whilenot in music mode, is safe.

toggle(light_type=<LightType.Main: 0>, **kwargs)Toggle the bulb on or off.

Parameters light_type (yeelight.LightType) – Light type to control.

18 Chapter 4. Notifications

Page 23: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

turn_off(light_type=<LightType.Main: 0>, **kwargs)Turn the bulb off.

Parameters light_type (yeelight.LightType) – Light type to control.

turn_on(light_type=<LightType.Main: 0>, **kwargs)Turn the bulb on.

Parameters light_type (yeelight.LightType) – Light type to control.

class yeelight.BulbExceptionA generic yeelight exception.

This exception is raised when bulb informs about errors, e.g., when trying to issue unsupported commands tothe bulb.

4.2.2 Flow objects

class yeelight.Flow(count=0, action=<Action.recover: 0>, transitions=None)A complete flow, consisting of one or multiple transitions.

Example: >>> transitions = [RGBTransition(255, 0, 0), SleepTransition(400)] >>> Flow(3,Flow.actions.recover, transitions)

Parameters

• count (int) – The number of times to run this flow (0 to run forever).

• action (action) – The action to take after the flow stops. Can be Flow.actions.recover to go back to the state before the flow, Flow.actions.stay to stay at thelast state, and Flow.actions.off to turn off.

• transitions (list) – A list of FlowTransition instances that describe the flowtransitions to perform.

actionsalias of Action

as_start_flow_paramsReturn a YeeLight start_cf compatible params.

Return type list

expressionReturn a YeeLight-compatible expression that implements this flow.

Return type list

class yeelight.HSVTransition(hue, saturation, duration=300, brightness=100)An HSV transition.

Parameters

• hue (int) – The color hue to transition to (0-359).

• saturation (int) – The color saturation to transition to (0-100).

• duration (int) – The duration of the effect, in milliseconds. The minimum is 50.

• brightness (int) – The brightness value to transition to (1-100).

class yeelight.RGBTransition(red, green, blue, duration=300, brightness=100)An RGB transition.

Parameters

4.2. yeelight package 19

Page 24: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

• red (int) – The value of red (0-255).

• green (int) – The value of green (0-255).

• blue (int) – The value of blue (0-255).

• duration (int) – The duration of the effect, in milliseconds. The minimum is 50.

• brightness (int) – The brightness value to transition to (1-100).

class yeelight.TemperatureTransition(degrees, duration=300, brightness=100)A Color Temperature transition.

Parameters

• degrees (int) – The degrees to set the color temperature to (1700-6500).

• duration (int) – The duration of the effect, in milliseconds. The minimum is 50.

• brightness (int) – The brightness value to transition to (1-100).

class yeelight.SleepTransition(duration=300)A Sleep transition.

Parameters duration (int) – The duration of the effect, in milliseconds. The minimum is 50.

4.2.3 Transition presets

Pre-made transitions, for your strobing pleasure.

yeelight.transitions.alarm(duration=250)Red alarm; flashing bright red to dark red.

Parameters duration (int) – The duration between hi/lo brightness,in milliseconds.

Returns A list of transitions.

Return type list

yeelight.transitions.christmas(duration=250, brightness=100, sleep=3000)Color changes from red to green, like christmas lights.

Parameters

• duration (int) – The duration between red and green, in milliseconds.

• brightness (int) – The brightness of the transition.

• sleep (int) – The time to sleep between colors, in milliseconds.

Returns A list of transitions.

Return type list

yeelight.transitions.disco(bpm=120)Color changes to the beat.

Parameters bpm (int) – The beats per minute to pulse to.

Returns A list of transitions.

Return type list

yeelight.transitions.lsd(duration=3000, brightness=100)Gradual changes to a pleasing, trippy palette.

Parameters

20 Chapter 4. Notifications

Page 25: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns A list of transitions.

Return type list

yeelight.transitions.police(duration=300, brightness=100)Color changes from red to blue, like police lights.

Parameters

• duration (int) – The duration between red and blue, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns A list of transitions.

Return type list

yeelight.transitions.police2(duration=250, brightness=100)Color flashes red and then blue, like urgent police lights.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns A list of transitions.

Return type list

yeelight.transitions.pulse(red, green, blue, duration=250, brightness=100)Pulse a single color once (mainly to be used for notifications).

Parameters

• red (int) – The red color component to pulse (0-255).

• green (int) – The green color component to pulse (0-255).

• blue (int) – The blue color component to pulse (0-255).

• duration (int) – The duration to pulse for, in milliseconds.

• brightness (int) – The brightness to pulse at (1-100).

Returns A list of transitions.

Return type list

yeelight.transitions.random_loop(duration=750, brightness=100, count=9)Color changes between count randomly chosen colors.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• count (int) – The number of random chosen colors in transition.

Returns A list of transitions.

Return type list

yeelight.transitions.rgb(duration=250, brightness=100, sleep=3000)Color changes from red to green to blue.

4.2. yeelight package 21

Page 26: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• sleep (int) – The time to sleep between colors, in milliseconds

Returns A list of transitions.

Return type list

yeelight.transitions.slowdown(duration=2000, brightness=100, count=8)Change between count random chosen colors with increasing transition time.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• count (int) – The number of random chosen colors in transition.

Returns A list of transitions.

Return type list

yeelight.transitions.strobe()Rapid flashing on and off.

Returns A list of transitions.

Return type list

yeelight.transitions.strobe_color(brightness=100)Rapid flashing colors.

Parameters brightness (int) – The brightness of the transition.

Returns A list of transitions.

Return type list

yeelight.transitions.temp()Slowly-changing color temperature.

Returns A list of transitions.

Return type list

4.2.4 Flow presets

Built-in flows which the vendor ships in their app and pre-made transitions, for your strobing pleasure.

yeelight.flows.alarm(duration=250)Red alarm; flashing bright red to dark red.

Parameters duration (int) – The duration between hi/lo brightness,in milliseconds.

Returns An infinite Flow consisting of 2 transitions.

Return type Flow

yeelight.flows.candle_flicker()Simulate candle flicker.

Returns An infinite Flow consisting of 9 transitions.

22 Chapter 4. Notifications

Page 27: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Return type Flow

yeelight.flows.christmas(duration=250, brightness=100, sleep=3000)Color changes from red to green, like christmas lights.

Parameters

• duration (int) – The duration between red and green, in milliseconds.

• brightness (int) – The brightness of the transition.

• sleep (int) – The time to sleep between colors, in milliseconds.

Returns An infinite Flow consisting of 4 transitions.

Return type Flow

yeelight.flows.date_night(duration=500, brightness=50)Dim the lights to a cozy orange.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 1 transition.

Return type Flow

yeelight.flows.disco(bpm=120)Color changes to the beat.

Parameters bpm (int) – The beats per minute to pulse to.

Returns An infinite Flow consisting of 8 transitions.

Return type Flow

yeelight.flows.happy_birthday()Happy Birthday lights.

Returns An infinite Flow consisting of 3 transitions.

Return type Flow

yeelight.flows.home(duration=500, brightness=80)Simulate daylight.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 1 transition.

Return type Flow

yeelight.flows.lsd(duration=3000, brightness=100)Gradual changes to a pleasing, trippy palette.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 5 transitions.

4.2. yeelight package 23

Page 28: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Return type Flow

yeelight.flows.movie(duration=500, brightness=50)Dim the lights to a comfy purple.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 1 transition.

Return type Flow

yeelight.flows.night_mode(duration=500, brightness=1)Dim the lights to a dark red, pleasant for the eyes at night.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 1 transition.

Return type Flow

yeelight.flows.police(duration=300, brightness=100)Color changes from red to blue, like police lights.

Parameters

• duration (int) – The duration between red and blue, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 2 transitions.

Return type Flow

yeelight.flows.police2(duration=250, brightness=100)Color flashes red and then blue, like urgent police lights.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 8 transitions.

Return type Flow

yeelight.flows.pulse(red, green, blue, duration=250, brightness=100)Pulse a single color once (mainly to be used for notifications).

Parameters

• red (int) – The red color component to pulse (0-255).

• green (int) – The green color component to pulse (0-255).

• blue (int) – The blue color component to pulse (0-255).

• duration (int) – The duration to pulse for, in milliseconds.

• brightness (int) – The brightness to pulse at (1-100).

Returns A Flow consisting of 2 transitions, after which the bulb returns to its previous state.

24 Chapter 4. Notifications

Page 29: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Return type Flow

yeelight.flows.random_loop(duration=750, brightness=100, count=9)Color changes between count randomly chosen colors.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• count (int) – The number of random chosen colors in transition.

Returns An infinite Flow consisting of up to 9 transitions.

Return type Flow

yeelight.flows.rgb(duration=250, brightness=100, sleep=3000)Color changes from red to green to blue.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• sleep (int) – The time to sleep between colors, in milliseconds

Returns An infinite Flow consisting of 6 transitions.

Return type Flow

yeelight.flows.romance()Romantic lights.

Returns An infinite Flow consisting of 2 transitions.

Return type Flow

yeelight.flows.slowdown(duration=2000, brightness=100, count=8)Changes between count random chosen colors with increasing transition time.

Parameters

• duration (int) – The duration to fade to next color, in milliseconds.

• brightness (int) – The brightness of the transition.

• count (int) – The number of random chosen colors in transition.

Returns An infinite Flow consisting of up to 8 transitions.

Return type Flow

yeelight.flows.strobe()Rapid flashing on and off.

Returns An infinite Flow consisting of 2 transitions.

Return type Flow

yeelight.flows.strobe_color(brightness=100)Rapid flashing colors.

Parameters brightness (int) – The brightness of the transition.

Returns An infinite Flow consisting of 6 transitions.

Return type Flow

4.2. yeelight package 25

Page 30: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

yeelight.flows.sunrise()Simulate a natural and gentle sunrise in 15 minutes.

Returns A Flow consisting of 3 transitions, after which the bulb stays on.

Return type Flow

yeelight.flows.sunset()Simulate a natural sunset and offering relaxing dimming to help you sleep in 10 minutes.

Returns A Flow consisting of 3 transitions, after which the bulb turns off.

Return type Flow

yeelight.flows.temp()Slowly-changing color temperature.

Returns An infinite Flow consisting of 2 transitions.

Return type Flow

4.2.5 Enums

class yeelight.BulbTypeThe bulb’s type.

This is either White (for monochrome bulbs), Color (for color bulbs), WhiteTemp (for white bulbs withconfigurable color temperature), WhiteTempMood for white bulbs with mood lighting (like the JIAOYUE 650LED ceiling light), or Unknown if the properties have not been fetched yet.

Color = 1

Unknown = -1

White = 0

WhiteTemp = 2

WhiteTempMood = 3

class yeelight.CronTypeThe type of event in cron.

off = 0

class yeelight.LightTypeType of light to control.

Ambient = 1

Main = 0

class yeelight.PowerModePower mode of the light.

COLOR_FLOW = 4

HSV = 3

LAST = 0

MOONLIGHT = 5

NORMAL = 1

RGB = 2

26 Chapter 4. Notifications

Page 31: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

class yeelight.SceneClassThe scene class to use.

The scene class (as named in Yeelight docs) specifies how the Bulb.set_scene method should act.

COLOR changes the light to the specified RGB color and brightness.HSV changes the light to the specified HSV color and brightness.CT changes the light to the specified color temperature.CF starts a color flow.AUTO_DELAY_OFF turns the light on and sets a timer to turn it back off after the given number of minutes.

AUTO_DELAY_OFF = 4

CF = 3

COLOR = 0

CT = 2

HSV = 1

4.3 Index

4.3. Index 27

Page 32: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

28 Chapter 4. Notifications

Page 33: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

Python Module Index

yyeelight.flows, 22yeelight.transitions, 20

29

Page 34: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

30 Python Module Index

Page 35: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

Index

Aactions (yeelight.Flow attribute), 19alarm() (in module yeelight.flows), 22alarm() (in module yeelight.transitions), 20Ambient (yeelight.LightType attribute), 26as_start_flow_params (yeelight.Flow attribute),

19AUTO_DELAY_OFF (yeelight.SceneClass attribute), 27

BBulb (class in yeelight), 14bulb_type (yeelight.Bulb attribute), 14BulbException (class in yeelight), 19BulbType (class in yeelight), 26

Ccandle_flicker() (in module yeelight.flows), 22capabilities (yeelight.Bulb attribute), 14CF (yeelight.SceneClass attribute), 27christmas() (in module yeelight.flows), 23christmas() (in module yeelight.transitions), 20Color (yeelight.BulbType attribute), 26COLOR (yeelight.SceneClass attribute), 27COLOR_FLOW (yeelight.PowerMode attribute), 26cron_add() (yeelight.Bulb method), 15cron_del() (yeelight.Bulb method), 15cron_get() (yeelight.Bulb method), 15CronType (class in yeelight), 26CT (yeelight.SceneClass attribute), 27

Ddate_night() (in module yeelight.flows), 23dev_toggle() (yeelight.Bulb method), 15disco() (in module yeelight.flows), 23disco() (in module yeelight.transitions), 20discover_bulbs() (in module yeelight), 14

Eensure_on() (yeelight.Bulb method), 15

expression (yeelight.Flow attribute), 19

FFlow (class in yeelight), 19

Gget_capabilities() (yeelight.Bulb method), 15get_model_specs() (yeelight.Bulb method), 15get_properties() (yeelight.Bulb method), 15

Hhappy_birthday() (in module yeelight.flows), 23home() (in module yeelight.flows), 23HSV (yeelight.PowerMode attribute), 26HSV (yeelight.SceneClass attribute), 27HSVTransition (class in yeelight), 19

LLAST (yeelight.PowerMode attribute), 26last_properties (yeelight.Bulb attribute), 15LightType (class in yeelight), 26listen() (yeelight.Bulb method), 16lsd() (in module yeelight.flows), 23lsd() (in module yeelight.transitions), 20

MMain (yeelight.LightType attribute), 26model (yeelight.Bulb attribute), 16MOONLIGHT (yeelight.PowerMode attribute), 26movie() (in module yeelight.flows), 24music_mode (yeelight.Bulb attribute), 16

Nnight_mode() (in module yeelight.flows), 24NORMAL (yeelight.PowerMode attribute), 26

Ooff (yeelight.CronType attribute), 26

31

Page 36: Release 0.5.2 Stavros Korokithakis · matter how long your transition list, just specify 1. 0 means “loop forever”. actioncan be Flow.actions.recoverto return to the original

python-yeelight Documentation, Release 0.5.4

Ppolice() (in module yeelight.flows), 24police() (in module yeelight.transitions), 21police2() (in module yeelight.flows), 24police2() (in module yeelight.transitions), 21PowerMode (class in yeelight), 26pulse() (in module yeelight.flows), 24pulse() (in module yeelight.transitions), 21

Rrandom_loop() (in module yeelight.flows), 25random_loop() (in module yeelight.transitions), 21RGB (yeelight.PowerMode attribute), 26rgb() (in module yeelight.flows), 25rgb() (in module yeelight.transitions), 21RGBTransition (class in yeelight), 19romance() (in module yeelight.flows), 25

SSceneClass (class in yeelight), 26send_command() (yeelight.Bulb method), 16set_adjust() (yeelight.Bulb method), 16set_brightness() (yeelight.Bulb method), 16set_color_temp() (yeelight.Bulb method), 16set_default() (yeelight.Bulb method), 17set_hsv() (yeelight.Bulb method), 17set_name() (yeelight.Bulb method), 17set_power_mode() (yeelight.Bulb method), 17set_rgb() (yeelight.Bulb method), 17set_scene() (yeelight.Bulb method), 17SleepTransition (class in yeelight), 20slowdown() (in module yeelight.flows), 25slowdown() (in module yeelight.transitions), 22start_flow() (yeelight.Bulb method), 18start_music() (yeelight.Bulb method), 18stop_flow() (yeelight.Bulb method), 18stop_listening() (yeelight.Bulb method), 18stop_music() (yeelight.Bulb method), 18strobe() (in module yeelight.flows), 25strobe() (in module yeelight.transitions), 22strobe_color() (in module yeelight.flows), 25strobe_color() (in module yeelight.transitions), 22sunrise() (in module yeelight.flows), 25sunset() (in module yeelight.flows), 26

Ttemp() (in module yeelight.flows), 26temp() (in module yeelight.transitions), 22TemperatureTransition (class in yeelight), 20toggle() (yeelight.Bulb method), 18turn_off() (yeelight.Bulb method), 18turn_on() (yeelight.Bulb method), 19

UUnknown (yeelight.BulbType attribute), 26

WWhite (yeelight.BulbType attribute), 26WhiteTemp (yeelight.BulbType attribute), 26WhiteTempMood (yeelight.BulbType attribute), 26

Yyeelight.flows (module), 22yeelight.transitions (module), 20

32 Index