In this page I provide you with script codes in order to manage Yeelight Smart bulbs. Before using the following codes, please take note that inside the Yeelight App (this is the link to the Android App), you need to select the smart bulb to manage, and then enable the "LAN Control" mode, only in this way you can manage the Smart bulb via the local network.
To manage Yeelight Smart bulbs via the command line, please take note of the following requirements:
To manage the Yeelight Smart bulb, just run the command "yeecli" followed by some parameters. To get a list of available parameters, run the command "yeecli" or "yeecli --help", the following output shows the parameters that can be used with the command "yeecli":
Usage: yeecli [OPTIONS] COMMAND [ARGS]... Easily control the YeeLight RGB LED lightbulb. Options: --version Show the version and exit. --ip IP The bulb's IP address. --port PORT The bulb's port. -e, --effect EFFECT The transition effect. -d, --duration DURATION_MS The transition effect duration. -b, --bulb NAME The name of the bulb in the config file. --auto-on / --no-auto-on Whether to turn the bulb on automatically before a command (on by default). -h, --help Show this message and exit. Commands: brightness Set the brightness of the bulb. hsv Set the HSV value of the bulb. preset Various presets. pulse Pulse the bulb in a specific color. rgb Set the RGB value of the bulb. save Save the current settings as default. status Show the bulb's status. temperature Set the color temperature of the bulb. toggle Toggle the bulb's state on or off. turn Turn the bulb on or off.
Most of the parameters require the IP address of the Smart bulb, for example if the IP address of the Smart bulb is 192.168.1.20, to know the current state of the light bulb just run the command "yeecli --ip=192.168.1.20 status" - the following is its output:
Bulb parameters: * power: on * bright: 1 * ct: 1746 * rgb: #fffb00 * hue: 59 * sat: 100 * color_mode: 1 * flowing: 0 * delayoff: 0 * music_on: 0 * name: None * bg_power: None * bg_flowing: None * bg_ct: None * bg_bright: None * bg_hue: None * bg_sat: None * bg_rgb: None * nl_br: None * active_mode: None * current_brightness: 1
For a list of the various presets usable, just run the command "yeecli --ip=192.168.1.20 preset --help" - the following is its output:
Usage: yeecli preset [OPTIONS] COMMAND [ARGS]... Various presets. Options: -h, --help Show this message and exit. Commands: alarm Flash a red alarm. christmas Christmas lights. disco Party. lsd Color changes to a trippy palette. police Police lights. police2 More police lights. random Random colors. redgreenblue Change from red to green to blue. slowdown Cycle with increasing transition time. stop Stop any currently playing presets and return to the prior... strobe Epilepsy warning. sunrise Simulate sunrise in seconds (default 5min). temp Slowly-changing color temperature.
The following script turns on the Smart bulb, sets the Red color and brightness to 50%, and after 5 seconds sets the Green color and brightness to 100%:
<?php require "Yeelight.class.php"; $yee = new Yeelight("192.168.1.20", 55443); $yee->set_power("on"); // power on $yee->set_rgb(0xFF0000); // color to red $yee->set_bright(50); // brightness to 50% $yee->commit(); // changes are not sent to the bulb before commit() is called sleep(5); $yee->set_rgb(0x00FF00)->set_bright(100)->commit(); // calls return the object for fast chaining of commands $status = $yee->get_prop("power")->commit(); // get current status print_r($status); $yee->disconnect();
The following script turns on the Smart light bulb, sets a custom color flow for 10 seconds, then turns off the color flow and return to the default color:
<?php require "Yeelight.class.php"; $yee = new Yeelight("192.168.1.20", 55443); $status = $yee->set_power(on)->commit(); $status = $yee->start_cf(0,1,"7000,1,10751,100,7000,1,65280,100,7000,1,255,100,7000,1,16776960,100")->commit(); sleep(10); $status = $yee->stop_cf()->commit(); $yee->disconnect();
The following script shows some information about the Smart bulb, turns the bulb on and off, sets the Red color and brightness to 50%, and after 5 seconds sets the Green color and brightness to 100%:
import time, logging from yeelight import Bulb #logging.basicConfig(level=logging.DEBUG) def main(): bulb = Bulb("192.168.1.20") # push method ensure_on to power on the bulb automatically before each operation bulb.auto_on = 1 # Return the specifications (e.g. color temperature min/max) of the bulb. print (bulb.get_model_specs()) print () # Retrieve and return the properties of the bulb. print (bulb.get_properties()) print () # Turn the bulb off + 1 second delay. bulb.turn_off() time.sleep(1) # Turn the bulb on + 1 second delay. bulb.turn_on() time.sleep(1) # Turn the bulb off + 1 second delay. bulb.turn_off() time.sleep(1) # Turn the bulb on if it is off. bulb.ensure_on() # Set RGB color and brightness bulb.set_rgb(255,0,0) bulb.set_brightness(50) # 5 seconds delay. time.sleep(5) # Set RGB color and brightness bulb.set_rgb(0,255,0) bulb.set_brightness(100) # Display if Bulb is on or off. print ("Bulb is " + bulb.get_properties().get("power", "off")) if __name__ == '__main__': main()
The following script turns on the Smart light bulb, sets a custom color flow for 10 seconds, then turns off the color flow and returns to the default color:
import time, logging from yeelight import Bulb, RGBTransition, Flow logging.basicConfig(level=logging.DEBUG) def int_color_to_rgb(color): """Convert a int color string to an RGB tuple.""" try: Blue = color & 255 Green = (color >> 8) & 255 Red = (color >> 16) & 255 except (TypeError, ValueError): print('Unrecognized color...', file=sys.stderr) red, green, blue = (0, 0, 0) return Red, Green, Blue def main(): bulb = Bulb("192.168.1.20") # Turn the bulb on bulb.turn_on() # Start a color flow. red1, green1, blue1 = int_color_to_rgb(10751) red2, green2, blue2 = int_color_to_rgb(65280) red3, green3, blue3 = int_color_to_rgb(255) red4, green4, blue4 = int_color_to_rgb(16776960) duration = 7000 brightness = 100 transitions = [ RGBTransition(red1, green1, blue1, duration=duration, brightness=brightness), RGBTransition(red2, green2, blue2, duration=duration, brightness=brightness), RGBTransition(red3, green3, blue3, duration=duration, brightness=brightness), RGBTransition(red4, green4, blue4, duration=duration, brightness=brightness), ] # count=0 just means infinite loop flow = Flow(count=0, transitions=transitions) bulb.start_flow(flow) # 10 seconds delay time.sleep(10) # Stop color flow bulb.stop_flow(flow) if __name__ == '__main__': main()