Skip to content

vrachieru/xiaomi-yeelight-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Version Version
Xiaomi Yeelight Smart Bulb API wrapper

About Xiaomi Yeelight Smart Bulb

  • Xiaomi Yeelight Smart Bulb are light bulbs that can be turned on/off and their color/brightness changed remotely via an app
  • Can be operated either via cloud or lan

Features

  • Query device information
  • Change bulb state
  • Set RGB color
  • Set custom flow

Install

$ pip3 install git+https://github.com/vrachieru/xiaomi-yeelight-api.git

or

$ git clone https://github.com/vrachieru/xiaomi-yeelight-api.git
$ pip3 install ./xiaomi-yeelight-api

Usage

Reading device information

from yeelight import SmartBulb

bulb = SmartBulb('192.168.xxx.xxx')

print('Name: %s' % bulb.name)
$ python3 info.py
Name: Bedroom Floor Lamp

Change state

from yeelight import SmartBulb

bulb = SmartBulb('192.168.xxx.xxx')

if bulb.is_on:
    bulb.power_off()
    print('Bulb powered off')
else:
    bulb.power_on()
    print('Bulb powered on')
$ python3 toggle.py
Bulb powered off

$ python3 toggle.py
Bulb powered on

Set custom flow

The following will transition between the colors RED, GREEN, BLUE at 100% brightness with a transition duration of 1s and 1s delay between transitions.

from yeelight import SmartBulb, Flow, RGBTransition, SleepTransition

RED   = [255, 0, 0]
GREEN = [0, 255, 0]
BLUE  = [0, 0, 255]

flow = Flow(
    10,
    Flow.actions.recover,
    [
        RGBTransition(*RED, 1000, 100),
        SleepTransition(1000),
        RGBTransition(*GREEN, 1000, 100),
        SleepTransition(1000),
        RGBTransition(*BLUE, 1000, 100),
        SleepTransition(1000)
    ]
)

bulb = SmartBulb('192.168.xxx.xxxx')
bulb.start_flow(flow)

License

MIT