yeelight package

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

yeelight module

yeelight.discover_bulbs(timeout=2)[source]

Discover all the bulbs in the local network.

Parameters:timeout (int) – How many seconds to wait for replies. Discovery will always take exactly this long to run, as it can’t know when all the bulbs have finished responding.
Returns:A list of dictionaries, containing the ip, port and capabilities of each of the bulbs in the network.
class yeelight.Bulb(ip, port=55443, effect='smooth', duration=300, auto_on=False, power_mode=<PowerMode.LAST: 0>)[source]

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. This is ignored for sudden effects.
  • auto_on (bool) – Whether to call ensure_on() to turn the bulb on automatically before 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 checking with get_properties() or run ensure_on() yourself if you’re worried about rate-limiting.
  • power_mode (yeelight.enums.PowerMode) – The mode for the light set when powering on.
bulb_type

The type of bulb we’re communicating with.

Returns a BulbType describing the bulb type. This can either be Color or White.

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

Return type:yeelight.BulbType
Returns:The bulb’s type.
cron_add(event_type, value)[source]

Add an event to cron.

Example:

>>> bulb.cron_add(CronType.off, 10)
Parameters:event_type (yeelight.enums.CronType) – The type of event. Currently, only CronType.off.
cron_del(event_type)[source]

Remove an event from cron.

Parameters:event_type (yeelight.enums.CronType) – The type of event. Currently, only CronType.off.
cron_get(event_type)[source]

Retrieve an event from cron.

Parameters:event_type (yeelight.enums.CronType) – The type of event. Currently, only CronType.off.
ensure_on()[source]

Turn the bulb on if it is off.

get_properties(requested_properties=['power', 'bright', 'ct', 'rgb', 'hue', 'sat', 'color_mode', 'flowing', 'delayoff', 'music_on', 'name'])[source]

Retrieve and return the properties of the bulb.

This method also updates last_properties when it is called.

Parameters:requested_properties (list) – The list of properties to request from the bulb. By default, this does not include flow_params.
Returns:A dictionary of param: value items.
Return type:dict
last_properties

The 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. To update it, call get_properties.

music_mode

Return whether the music mode is active.

Return type:bool
Returns:True if music mode is on, False otherwise.
send_command(method, params=None)[source]

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)[source]

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 for completeness, 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 color temperature and “color” for color. The only action for “color” can be “circle”. Why? Who knows.
set_brightness(brightness, **kwargs)[source]

Set the bulb’s brightness.

Parameters:brightness (int) – The brightness value to set (1-100).
set_color_temp(degrees, **kwargs)[source]

Set the bulb’s color temperature.

Parameters:degrees (int) – The degrees to set the color temperature to (1700-6500).
set_default()[source]

Set the bulb’s current state as default.

set_hsv(hue, saturation, value=None, **kwargs)[source]

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 the same as before the change.
set_name(name)[source]

Set the bulb’s name.

Parameters:name (str) – The string you want to set as the bulb’s name.
set_power_mode(mode)[source]

Set the light power mode.

If the light is off it will be turned on.

Parameters:mode (yeelight.enums.PowerMode) – The mode to swith to.
set_rgb(red, green, blue, **kwargs)[source]

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).
start_flow(flow)[source]

Start a flow.

Parameters:flow (yeelight.Flow) – The Flow instance to start.
start_music(port=0)[source]

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 old connection. If the bulb cannot connect to the host machine for any reason, bad things will happen (such as library freezes).

Parameters:port (int) – The port to listen on. If none is specified, a random port will be chosen.
stop_flow()[source]

Stop a flow.

stop_music()[source]

Stop music mode.

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

toggle(**kwargs)[source]

Toggle the bulb on or off.

turn_off(**kwargs)[source]

Turn the bulb off.

turn_on(**kwargs)[source]

Turn the bulb on.

class yeelight.BulbException[source]

A generic yeelight exception.

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

class yeelight.BulbType[source]

The bulb’s type.

This is either White or Color, or Unknown if the properties have not been fetched yet.

Color = 1
Unknown = -1
White = 0

Flow objects

class yeelight.Flow(count=0, action=<Action.recover: 0>, transitions=None)[source]

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 the last state, and Flow.actions.off to turn off.
  • transitions (list) – A list of FlowTransition instances that describe the flow transitions to perform.
actions

alias of Action

expression

Return a YeeLight-compatible expression that implements this flow.

Return type:list
class yeelight.HSVTransition(hue, saturation, duration=300, brightness=100)[source]

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)[source]

An RGB transition.

Parameters:
  • 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)[source]

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)[source]

A Sleep transition.

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

Transition presets

Pre-made transitions, for your strobing pleasure.

yeelight.transitions.alarm(duration=250)[source]

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)[source]

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)[source]

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)[source]

Gradual changes to a pleasing, trippy palette.

Parameters:brightness (int) – The brightness of the transition.
Returns:A list of transitions.
Return type:list
yeelight.transitions.police(duration=300, brightness=100)[source]

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)[source]

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)[source]

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.randomloop(duration=750, brightness=100, count=9)[source]

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)[source]

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:

A list of transitions.

Return type:

list

yeelight.transitions.slowdown(duration=2000, brightness=100, count=8)[source]

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:

A list of transitions.

Return type:

list

yeelight.transitions.strobe()[source]

Rapid flashing on and off.

Returns:A list of transitions.
Return type:list
yeelight.transitions.strobe_color(brightness=100)[source]

Rapid flashing colors.

Parameters:brightness (int) – The brightness of the transition.
Returns:A list of transitions.
Return type:list
yeelight.transitions.temp()[source]

Slowly-changing color temperature.

Returns:A list of transitions.
Return type:list

Enums

class yeelight.enums.CronType[source]

Bases: enum.Enum

The type of event in cron.

off = 0
class yeelight.enums.PowerMode[source]

Bases: enum.IntEnum

Power mode of the light.

COLOR_FLOW = 4
HSV = 3
LAST = 0
MOONLIGHT = 5
NORMAL = 1
RGB = 2