Commandline API for Yeelight Xiaomi Mi Bedside Lamp 2 MJCTD01YL

The Yeelight Bedside Lamp is an WiFi RGB lamp. You can control it with an App on your mobile phone. But it also have an API. It accepts JSON-formatted commands. On Linux it is realy simple to send them to your lamp.

To start using this API i give you a few examples. The usage of the API is explained in this document: https://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf

Here are some basic examples

Switch lamp on and off
printf '{"id":1,"method":"set_power","params":["on"]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443
printf '{"id":1,"method":"set_power","params":["off"]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443
Setting colors:

The yeelight using an decimal integer instead of the classic hex colors. You have to convert the hex value to decimal.

Here are a few examples:
Blue #0000FF -> 255

printf '{"id":1,"method":"set_rgb","params":[255]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

Red #FF0000 -> 16711680

printf '{"id":1,"method":"set_rgb","params":[16711680]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

A few more color examples:
Pink #FE2EF7 -> 16658167
Green #00FF00 -> 65280
Yellow #FFFF00 -> 16776960
Orange #FFBF00 -> 16760576
White #FFFFFF -> 16777215

I will only use this colors in my examples.

“set_rgb” has 2 more parameters which are optional. The second is the effect.
Currently only one effect “smooth” is available. You can use it with the third parameter “duration” (milliseconds) to change the color slowly to the next color.

Set color to white and than change it slowly to red:

printf '{"id":1,"method":"set_rgb","params":[16777215]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443
printf '{"id":1,"method":"set_rgb","params":[16711680,"smooth",6000]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

Maybe you want create a little bit more different color changes. You can use “start_cf” to create a color flow on your lamp.
This method has 3 arguments. “count”, “action”, and the “flow expression”.
With “count” you can define how often your effect should loop. With “0” you create an infinite loop.
The “action” parameter has three settings which defines what your lamp should do after the effect.

0 Lamp recover to the state before the color flow started
1 Lamp stay at the state when the flow is stopped
2 turns off the Lamp after the flow is stopped

Now to the flow expression. Each one has this format: [duration, mode, value, brightness]
I think i don’t have to explain “duration” and “brightness”.

The mode “7” for “sleep” is easy. It ignores the “value” and “brightness” and does nothing.
With [5000,7,0,0] your lamp sleep for 5000 milliseconds.

The mode “1” set your lamp to a specific color.
With [500, 1, 255, 50] you set your lamp to blue for 500ms with 50% brightness.

The mode “2” set your lamp to a specific color temperature.
With [500, 2, 2700, 100] your lamp sets to 2700K & maximum brightness.

First example infinite loop red->green->blue

printf '{"id":1,"method":"start_cf","params":[0,0, "5000, 1, 16711680, 100, 5000, 1, 65280, 100, 5000, 1, 255, 100"]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

Blink blue and switch back to the Program:

printf '{"id":1,"method":"start_cf","params":[10,0, "300, 1, 255, 10, 300, 1, 255, 100"]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

It sets color to blue with 10% brightness for 300ms and than for 300ms the brightness to 100% for 10 times.

Send commands to the lamp if it is off

This commands above work only if the lamp is “on”.

The method “set_scene” is used to set the smart LED directly to specified state. If the smart LED is off, then it will turn on the smart LED firstly and then apply the specified command.

Here is an example to let the lamp blick blue if it is off or on.

printf '{"id":1, "method":"set_scene","params":["cf",10,0,"300, 1, 255, 10, 300, 1, 255, 100"]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

If your lamp was off it will be off again after this command.

This sets the lamp to red with 100% brightness:

printf '{"id":1,"method":"set_scene", "params": ["color", 16711680, 100]}\r\n' > /dev/tcp/YOUR_LAMP_IP/55443

For more look at the offical documentation: https://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf

Schreibe einen Kommentar

eMail-Benachrichtigung bei weiteren Kommentaren.
Auch möglich: Abo ohne Kommentar.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.