This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zigbee light_bulb turns full On(100%) instead of setting to 10% level

Hello All,

I am developing a light control device using Zigbee and Alexa. I am using an nRF52840 device and SDK nRF5_SDK_for_Thread_and_Zigbee_v3.0.0_d310e71.

For my development, I have referred to light_bulb code as per nordic engineer suggestion and made the respected changes to communicate with Alexa.

Till now everything is working perfectly fine without any issue even On dev-kit and my custom hardware so while testing corner cases on my hardware.

I came to know that if I send the "Alexa set 0 percent" command from the Alexa device it turns OFF correctly. But if I give "Alexa Turn ON" then it takes 100 percent (100%) not 10% or 20% which was my previous set level before setting to 0%.

But If I use the "Alexa Turn ON" and "Alexa Turn OFF" command then I get the expected result means example. If I set the level to 20% and then gave the OFF command it turns OFF and If I say "Alexa turn ON" then it turns ON to the set level which is 20%.

Only, If give "Alexa set 0 percentage" and "Alexa Turn ON" I facing this 100% ON instead of the previous level.

This same case happing in SDK's light_bulb code.

So please let me know the reason behind this? And also can we change as per our requirement? If yes, then share the steps so that we can keep command execution identical in all cases.

Thanks and Regards

Rohit R

Parents
  • Hello,

    Have you tried to sniff the connection? I suspect that it is the Alexa that sets the brightness to 100% when it is set to 0, and then toggled on. At least looking at the implementation of the light bulb it looks like it doesn't do as you describe if it receives an "on" and the brightness is set to 0:

    (new level is the previous brightness)

    /**@brief Function for setting the light bulb brightness.
      *
      * @param[in]   new_level   Light bulb brightness value.
     */
    static void level_control_set_value(zb_uint16_t new_level)
    {
        NRF_LOG_INFO("Set level value: %i", new_level);
    
        ZB_ZCL_SET_ATTRIBUTE(HA_DIMMABLE_LIGHT_ENDPOINT,                                       
                             ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL,            
                             ZB_ZCL_CLUSTER_SERVER_ROLE,                 
                             ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, 
                             (zb_uint8_t *)&new_level,                                       
                             ZB_FALSE);                                  
    
        /* According to the table 7.3 of Home Automation Profile Specification v 1.2 rev 29, chapter 7.1.3. */
        if (new_level == 0)
        {
            zb_uint8_t value = ZB_FALSE;
            ZB_ZCL_SET_ATTRIBUTE(HA_DIMMABLE_LIGHT_ENDPOINT, 
                                 ZB_ZCL_CLUSTER_ID_ON_OFF,    
                                 ZB_ZCL_CLUSTER_SERVER_ROLE,  
                                 ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID,
                                 &value,                        
                                 ZB_FALSE);                   
        }
        else
        {
            zb_uint8_t value = ZB_TRUE;
            ZB_ZCL_SET_ATTRIBUTE(HA_DIMMABLE_LIGHT_ENDPOINT, 
                                 ZB_ZCL_CLUSTER_ID_ON_OFF,    
                                 ZB_ZCL_CLUSTER_SERVER_ROLE,  
                                 ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID,
                                 &value,                        
                                 ZB_FALSE);
        }
    
        light_bulb_set_brightness(new_level);
    }

    Which is called from the on_off_set_value():

    /**@brief Function for turning ON/OFF the light bulb.
     *
     * @param[in]   on   Boolean light bulb state.
     */
    static void on_off_set_value(zb_bool_t on)
    {
        NRF_LOG_INFO("Set ON/OFF value: %i", on);
    
        ZB_ZCL_SET_ATTRIBUTE(HA_DIMMABLE_LIGHT_ENDPOINT, 
                             ZB_ZCL_CLUSTER_ID_ON_OFF,    
                             ZB_ZCL_CLUSTER_SERVER_ROLE,  
                             ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID,
                             (zb_uint8_t *)&on,                        
                             ZB_FALSE);
    
        if (on)
        {
            level_control_set_value(m_dev_ctx.level_control_attr.current_level);
        }
        else
        {
            light_bulb_set_brightness(0U);
        }
    }

    Have you either tried to sniff the network or see what the alexa does with other Zigbee light bulbs, such as an IKEA lightbulb (TRÅDFRI) or a Philips Hue?

    BR,

    Edvin

  • Hi Edvin,

    Ya, even I tried to backtrace what is the problem.

    As you said these above 2 function works when On/Off command sends. But strange why it tacking when we send "Alexa turn ON" after setting "Alexa set 0%" instead of previous values.

    Have you either tried to sniff the network or see what the alexa does with other Zigbee light bulbs, such as an IKEA lightbulb (TRÅDFRI) or a Philips Hue?

    - I do not have these devices and for sniffing I need some plug-in devices but due to work from home, I do not have many devices. Only Dev-kit is with me and I am working on it.

    We need to check the reason for this.

    Let me know if you get any lead points. I will also check with the suggested device to manage and test.

    Thanks and Regards

    Rohit R

  • Ok, but when you do the scenario that you describe. dim to 0 % and then turn on (so that it turns to 100%) what event occurs on the light bulb? Turn on? Dim to 100? 

    If you look at the zcl_device_cb() in main.c:

            case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
                cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
                attr_id    = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
    
                if (cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF)
                {
                    uint8_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
    
                    NRF_LOG_INFO("on/off attribute setting to %hd", value);
                    if (attr_id == ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID)
                    {
                        on_off_set_value((zb_bool_t) value);
                    }
                }
                else if (cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL)
                {
                    uint16_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data16;
    
                    NRF_LOG_INFO("level control attribute setting to %hd", value);
                    if (attr_id == ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID)
                    {
                        level_control_set_value(value);
                    }
                }

    What is the cluster_id? Does it set value or dim? Or does it send both sequentially? 

    BR,

    Edvin

Reply
  • Ok, but when you do the scenario that you describe. dim to 0 % and then turn on (so that it turns to 100%) what event occurs on the light bulb? Turn on? Dim to 100? 

    If you look at the zcl_device_cb() in main.c:

            case ZB_ZCL_SET_ATTR_VALUE_CB_ID:
                cluster_id = p_device_cb_param->cb_param.set_attr_value_param.cluster_id;
                attr_id    = p_device_cb_param->cb_param.set_attr_value_param.attr_id;
    
                if (cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF)
                {
                    uint8_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data8;
    
                    NRF_LOG_INFO("on/off attribute setting to %hd", value);
                    if (attr_id == ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID)
                    {
                        on_off_set_value((zb_bool_t) value);
                    }
                }
                else if (cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL)
                {
                    uint16_t value = p_device_cb_param->cb_param.set_attr_value_param.values.data16;
    
                    NRF_LOG_INFO("level control attribute setting to %hd", value);
                    if (attr_id == ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID)
                    {
                        level_control_set_value(value);
                    }
                }

    What is the cluster_id? Does it set value or dim? Or does it send both sequentially? 

    BR,

    Edvin

Children
  • Hi Edvin,

    like dim to 0% and turn On scenario,

    first execution when dim 0% command,

    -> it execute cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, level_control_set_value(value); as in call back then

    -> it execute cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF, on_off_set_value((zb_bool_t) value); as in call back.

    when turn On command,

    -> it execute it execute cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF, on_off_set_value((zb_bool_t) value); as in call back then

    ->  it execute cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, level_control_set_value(value); as in call back. - cluster id execute twice.

    value = 99% full On

    This happens in both my code as well as light_bulb code.

    /****************/

    And if just give dim 10% command,

    - ->  it execute cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, level_control_set_value(value);

    Turn Off command,

    - -> it execute it execute cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF, on_off_set_value((zb_bool_t) value); 

    Turn On command,

    -> it execute it execute cluster_id == ZB_ZCL_CLUSTER_ID_ON_OFF, on_off_set_value((zb_bool_t) value); as in call back then

    ->  it execute cluster_id == ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, level_control_set_value(value); as in call back. - cluster id execute once.

    Same things execution in both light_bulb and my code

    /********************/

    Thanks and Regards

    Rohit R

  • What I really wanted to know was the values of on_off_set_value((zb_bool_t) value) and level_control_set_value(value).

    So what input parameters are you seeing in the callbacks that are being used in on_off_set_value() and level_control_set_value()?

  • Hi Edvin

    I am not able to see (value) in the watch window.

    I have managed my variable in light_bulb_onboard_set_brightness(zb_uint8_t brightness_level) function and assigned globle variable to this (brightness_level * 100U) / 255U;

    There I come to know it is giving me 99 value.

    But when the Turn On / Off command value show me in variable 10 or 20 whatever user set.

    And what might be happening is level_control_set_value() cluster_id is executing twice like I said test case in the previous post after command dim 0% to turn On transaction. And only once this cluster executing when we give Turn On/Off command.

    But how to manage or to avoid this twice execution level_control_set_value(value); clustore not understanding.

    This is my test result. I might be wrong.

    Let me know your view.

    Thanks and Regards

    Rohit R

  • Rohit Rajapure said:
    I am not able to see (value) in the watch window.

     Either you need to disable optimization, or you can monitor the log. What does the log say?

  • Hi,

    Ya, I tried to log on Putty but do not know why the log is not printing on putty.

    I tried with 9600 and 115200 baud rates.

    no logs are printing.

    Sorry, but due to urgency in the requirement, I am asking you one more question which not related to this topic.

    I got a new requirement from the hardware team that Using GPIO interrupt can we execute a Soft reset and start from the main function.

    As I am new to this nrf, and as per my study nRF52840 light_bulb example does not use soft devices so I do not know how to soft reset the device using interrupt. 

    Can you please let me know can we perform this action on pin interrupt? if yes, then which all files need to be included and enable the API.

    Sorry, again as a team is preparing the next version of hardware so it is urgent for me to clear the things before they make any changes. So I am asking this question here.

    Please let me know how we can do this.

    Thanks for understanding.

    Thanks and Regards

    Rohit R

Related