Start_cf command supports Color Mode 3 (HSV Mode)?

Hi,

I’m working on implementing the yeelights in my home environment. So far so good and I love the quality of the bulbs and the light they produce. I make very often use of the start_cf mode of the API.
However I’m not successful in getting the following command to work:

{“id”:1, “method”:“start_cf”, “params”:[1,1,“30000,3,39,17,42”]}

I would expect (from the documentation)
1 - active state
1 - smart Led will stay at the state when the flow stopped
30000 - 30 sec Duration
3 - Color Mode 3, means HSV mode
39 - Hue
17 - Saturation
42 - brightness

But I get an error. I hope someone can help me to point out what is wrong with this command?

The start_cf can only contain following three modes: RGB, CT or PAUSE mode, that is 1, 2 or 7. We didn’t add HSV mode yet. Please refer to following section in the spec.

Method: start_cf
Usage: This method is used to start a color flow. Color flow is a series of smart
LED visible state changing. It can be brightness changing, color changing or color
temperature changing.This is the most powerful command. All our recommended scenes,
e.g. Sunrise/Sunset effect is implemented using this method. With the flow expression, user
can actually “program” the light effect.
Parameters: 3.
“count” is the total number of visible state changing before color flow
stopped. 0 means infinite loop on the state changing.
“action” is the action taken after the flow is stopped.
0 means smart LED recover to the state before the color flow started.
1 means smart LED stay at the state when the flow is stopped.
2 means turn off the smart LED after the flow is stopped.
“flow_expression” is the expression of the state changing series.
Request Example: {“id”:1,“method”:“start_cf”,“params”:[ 4, 2, “1000, 2, 2700, 100, 500, 1,
255, 10, 5000, 7, 0,0, 500, 2, 5000, 1”]
Response Example: {“id”:1, “result”:[“ok”]}
NOTE: Each visible state changing is defined to be a flow tuple that contains 4
elements: [duration, mode, value, brightness]. A flow expression is a series of flow tuples.
So for above request example, it means: change CT to 2700K & maximum brightness
gradually in 1000ms, then change color to red & 10% brightness gradually in 500ms, then
stay at this state for 5 seconds, then change CT to 5000K & minimum brightness gradually in
500ms. After 4 changes reached, stopped the flow and power off the smart LED.

[duration, mode, value, brightness]:
Duration: Gradual change time or sleep time, in milliseconds,
minimum value 50.
Mode: 1 – color, 2 – color temperature, 7 – sleep.
Value: RGB value when mode is 1, CT value when mode is 2,
Ignored when mode is 7.
Brightness: Brightness value, 1 ~ 100. Ignored when mode is 7.
Only accepted if the smart LED is currently in “on” state.
The logic can be expressed in following pseudo code.
+start_cf:
cnt = 0
while true:
if flow_cnt != 0 and cnt >= flow_cnt:
take_stop_action(flow_action)
break
tuple = get_next_flow_tuple() # flow tuple will be put in a circular list
apply_effect(tuple) # change RGB/CT gradually or sleep

Thanks for your quick, kind and clear reaction.
I hope that the HSV method will be implemented in the color flow also.
Till that moment I will wait for this option and program my lights in a bit different way.

Do you perhaps have a formula for me what I can use to transpose the Hue, Saturation en Brightness Value to the color code used by the Yeelight Api? That would help me a lot to implement my software.

many thanks in advance
Bert

1 Like

Hi, bertbigb

For HSV to RGB, Here is a reference:
https://en.wikipedia.org/wiki/HSL_and_HSV

and here is a tool of hsv-to-rgb.
http://www.freecodeformat.com/hsv-to-rgb.php

Here is a demo code base on C as a reference, and as a bulb, the saturation should be 1.

typedef struct{
    uint16 hue;
    float sat;
    uint8 brightness;
}hsv_mode_t;
typedef struct{
    uint8 r;
    uint8 g;
    uint8 b;
    uint8 brightness;
}rgb_mode_t;
rgb_mode_t color_hsv_to_rgb(hsv_mode_t hsv)
{
    uint8 hue_tmp;
    uint8 p, q, t, v;
    float f, p_tmp, q_tmp, t_tmp, v_tmp;
    uint8 r, g, b;
    rgb_mode_t rgb;

    if (hsv.hue > 360) {
        hsv.hue = 360;
    } 
    if (hsv.sat > 1) {
        hsv.sat = 1;
    } else if (hsv.sat < 0) {
        hsv.sat = 0;
    }

    //trans hsv to rgb mode, v is set to 1
    v = 1;
    //hue belong to [0,360), and in order to not be out of range
    hue_tmp = (c_uint8)((c_uint16)(hsv.hue % 360) / 60 % 6);
    f = (float)(hsv.hue % 360) / 60.0 - (float)(hue_tmp);

    p_tmp = 255.0 * (1.0 - hsv.sat);
    q_tmp = 255.0 * (1.0 - f * hsv.sat);
    t_tmp = 255.0 * (1.0 - (1.0 - f) * hsv.sat);

    p = (c_uint8)(255.0 * (1.0 - hsv.sat));
    q = (c_uint8)(255.0 * (1.0 - f * hsv.sat));
    t = (c_uint8)(255.0 * (1.0 - (1.0 - f) * hsv.sat));
    v = v * 255;

    if ((p_tmp - p) >= 0.5) {
        p++;
    }
    if ((q_tmp - q) >= 0.5) {
        q++;
    }
    if ((t_tmp - t) >= 0.5) {
        t++;
    }
    switch (hue_tmp) { case 0:
        r = v;
        g = t;
        b = p;
        break;
    case 1:
        r = q;
        g = v;
        b = p;
        break;
    case 2:
        r = p;
        g = v;
        b = t;
        break;
    case 3:
        r = p;
        g = q;
        b = v;
        break;
    case 4:
        r = t;
        g = p;
        b = v;
        break;
    case 5:
        r = v;
        g = p;
        b = q;
        break;
    default:
        break;
    } 

    rgb.r = r;
    rgb.g = g;
    rgb.b = b;
    rgb.brightness = hsv.brightness;

    return rgb;
}

Thanks for all the information. I can continue with all this.

Many thanks for all your help.

Best regards,
Bert

I could continue with my application for now.

May I kindly ask to adopt the HSV mode in the start color flow so that something like this:

{“id”:1, “method”:“start_cf”, “params”:[1,1,“30000,3,39,17,42”]}

I would expect (from the documentation)
1 - active state
1 - smart Led will stay at the state when the flow stopped
30000 - 30 sec Duration
3 - Color Mode 3, means HSV mode
39 - Hue
17 - Saturation
42 - brightness

in the future will work?