Zigbee Color temperature light

doctor567
Posts: 3
Joined: Fri Oct 20, 2023 4:59 pm

Zigbee Color temperature light

Postby doctor567 » Fri Oct 20, 2023 5:23 pm

I am new to ESP-IDF and ESP-Zigbee SDK. I am trying to create a color-temperature-adjustable, dimmable light using ESP-IDF 5.1 on ESP32-H2. Specifically, I am trying to modify the HA Color Dimmable Light example to accept color temperature adjustment (MIRED) instead of RGB (x and y coordinates). I just want to successfully log the command and values message, am not worried about the hardware side at all yet. I have modified the color mode and color capabilities successfully so the device is correctly recognized as such by the controller. It joins the network, and I can control on/off and level fine. However, not so when I send a color temp value (cluster 0x300, attribute 0x0a) from the client controller. When my device receives this packet, the ESP32 immediately crashes and reboots. This happens before any interaction with my attribute handler or even the action handler, so this has nothing to do with the LED driver.

I believe the issue is with something specific to esp_zb_color_dimmable_light_ep_create(), and/or the color cluster configuration I am passing to it. Here's what it looks like:

.color_cfg = \
{ \
.current_x = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_X_DEF_VALUE, \
.current_y = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_Y_DEF_VALUE, \
.color_mode = 0x0002, \
.options = ESP_ZB_ZCL_COLOR_CONTROL_OPTIONS_DEFAULT_VALUE, \
.enhanced_color_mode = ESP_ZB_ZCL_COLOR_CONTROL_ENHANCED_COLOR_MODE_DEFAULT_VALUE, \
.color_capabilities = 0x0010, \
},

Because there is nothing that addresses anything to do with color temperature values in this config, I suspect the ESP Zigbee device or task is trying to write to an invalid address. As I said, I don't really want X and Y coordinate control at all, I only care about handling the command move_to_color_temperature (value in MIRED). But I don't know how to handle this in the color cluster configuration.

Has anyone successfully made a color temperature/dimmable light using ESP Zigbee SDK? Anything someone can tell me that might point me in the right direction is appreciated.

doctor567
Posts: 3
Joined: Fri Oct 20, 2023 4:59 pm

Re: Zigbee Color temperature light

Postby doctor567 » Thu Nov 02, 2023 3:22 am

In case anyone is trying to do the same thing, I figured it out and here's what I ended up doing.

In esp_zb_task(), I stopped trying to create the cluster using esp_zb_color_control_cluster_create(), and instead I just do esp_zb_zcl_attr_list_create(), and then a bunch of esp_zb_color_control_cluster_add_attr() calls - one for each attribute needed. This includes the color mode and color capabilities. It's also necessary to specify the color temp MIN and MAX, and provide valid default values. FWIW, I think it's necessary to provide a default value for every single attribute (I just used 0 for most of them, AKA "test_attr")

Code: Select all

// // Add the color control cluster and necessary attributes
uint16_t color_attr = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_DEF_VALUE;
uint16_t min_temp = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_DEFAULT_VALUE;
uint16_t max_temp = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_DEFAULT_VALUE;

uint8_t test_attr, test_attr2, color_mode, color_capabilities;
test_attr = 0;
test_attr2 = 3;
color_mode = 0x0002;  // ColorTemperatureMireds
color_capabilities = 0x0010; // Color temperature supported
    
    
/* basic cluster create with fully customized */
esp_zb_attribute_list_t *esp_zb_basic_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_BASIC);
esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, &test_attr);
esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, &test_attr);
esp_zb_cluster_update_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, &test_attr2);

/* identify cluster create with fully customized */
esp_zb_attribute_list_t *esp_zb_identify_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_IDENTIFY);
esp_zb_identify_cluster_add_attr(esp_zb_identify_cluster, ESP_ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID, &test_attr);

/* group cluster create with fully customized */
esp_zb_attribute_list_t *esp_zb_groups_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_GROUPS);
esp_zb_groups_cluster_add_attr(esp_zb_groups_cluster, ESP_ZB_ZCL_ATTR_GROUPS_NAME_SUPPORT_ID, &test_attr);

/* scenes cluster create with standard cluster + customized */
esp_zb_attribute_list_t *esp_zb_scenes_cluster = esp_zb_scenes_cluster_create(NULL);
esp_zb_cluster_update_attr(esp_zb_scenes_cluster, ESP_ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID, &test_attr);

/* on-off cluster create with standard cluster config*/
esp_zb_on_off_cluster_cfg_t on_off_cfg;
on_off_cfg.on_off = ESP_ZB_ZCL_ON_OFF_ON_OFF_DEFAULT_VALUE;
esp_zb_attribute_list_t *esp_zb_on_off_cluster = esp_zb_on_off_cluster_create(&on_off_cfg);

 /* level control cluster, fully customized */
esp_zb_attribute_list_t *esp_zb_level_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL);
esp_zb_level_cluster_add_attr(esp_zb_level_cluster, ESP_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, &test_attr);

/* color control cluster create, fully customized */
esp_zb_attribute_list_t *esp_zb_color_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL);
esp_zb_color_control_cluster_add_attr(esp_zb_color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_MODE_ID, &color_mode);
esp_zb_color_control_cluster_add_attr(esp_zb_color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID, &color_capabilities);
esp_zb_color_control_cluster_add_attr(esp_zb_color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID, &color_attr);
esp_zb_color_control_cluster_add_attr(esp_zb_color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_ID, &min_temp);
esp_zb_color_control_cluster_add_attr(esp_zb_color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_ID, &max_temp);

/* create cluster lists for this endpoint */
esp_zb_cluster_list_t *esp_zb_cluster_list = esp_zb_zcl_cluster_list_create();

/* Add the basic cluster */
esp_zb_cluster_list_add_basic_cluster(esp_zb_cluster_list, esp_zb_basic_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);

/* update basic cluster in the existed cluster list, based on example code; not sure why this is done separately  */
esp_zb_cluster_list_update_basic_cluster(esp_zb_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);

/* adding the other (non-basic) clusters */
esp_zb_cluster_list_add_identify_cluster(esp_zb_cluster_list, esp_zb_identify_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_groups_cluster(esp_zb_cluster_list, esp_zb_groups_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_scenes_cluster(esp_zb_cluster_list, esp_zb_scenes_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_on_off_cluster(esp_zb_cluster_list, esp_zb_on_off_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_level_cluster(esp_zb_cluster_list, esp_zb_level_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
esp_zb_cluster_list_add_color_control_cluster(esp_zb_cluster_list, esp_zb_color_cluster, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);

esp_zb_ep_list_t *esp_zb_ep_list = esp_zb_ep_list_create();
/* add created endpoint (cluster_list) to endpoint list */
esp_zb_ep_list_add_ep(esp_zb_ep_list, esp_zb_cluster_list, HA_COLOR_DIMMABLE_LIGHT_ENDPOINT, ESP_ZB_AF_HA_PROFILE_ID, ESP_ZB_HA_ON_OFF_LIGHT_DEVICE_ID);
esp_zb_device_register(esp_zb_ep_list);
esp_zb_core_action_handler_register(zb_action_handler);
esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);
ESP_ERROR_CHECK(esp_zb_start(false));

esp_zb_main_loop_iteration();

With the above code, my device is receiving color temp control messages to cluster id 0x300, and not crashing/rebooting. It still has on/off, scenes, level control, and everything else. Once you are at this point, you can go ahead and start handling messages in the attribute_handler for cluster ID 0x300 (ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL), attribute 0x0007 (ColorTemperatureMireds)

olli100
Posts: 2
Joined: Fri Mar 15, 2024 4:02 pm

Re: Zigbee Color temperature light

Postby olli100 » Fri Mar 15, 2024 4:19 pm

Hi doctor567,

I was searching for some hints how to configure a color temperature light correctly to work with the zigbee-sdk and found your post (actually nothing else but your post). Thanks for sharing. The original example HA_color_dimmable_light worked well. In esp_zb_task() I commented the lines:

Code: Select all

//esp_zb_color_dimmable_light_cfg_t light_cfg = ESP_ZB_COLOR_TUNABLE_LIGHT_CONFIG();
    //esp_zb_ep_list_t *esp_zb_color_dimmable_light_ep = esp_zb_color_dimmable_light_ep_create(HA_COLOR_DIMMABLE_LIGHT_ENDPOINT, &light_cfg);
and copy pasted your code. Unfortunately, now I have the exact same effect you describe in your original post. On/off and level works. Color temperature information crashes the ESP and leads to a reboot. Did you change anything else in the code? I am also working on a ESP32-H2 DevKit base. The esp-zigbee-sdk has version 1.1.2. Thanks for any advice!

ALexey32
Posts: 1
Joined: Wed Apr 10, 2024 12:58 pm

Re: Zigbee Color temperature light

Postby ALexey32 » Wed Apr 10, 2024 1:07 pm

Maybe this will be useful for you ;)
https://github.com/username-AL/ESP32H2-ZigbeeCCT

olli100
Posts: 2
Joined: Fri Mar 15, 2024 4:02 pm

Re: Zigbee Color temperature light

Postby olli100 » Fri Apr 12, 2024 1:41 pm

Hi ALexey32,

I read your reply but did not have time so far to try it out. Nevertheless, it looks very promising 8-) I'll write as soon as I tested.
Thanks for now.

Best wishes

Who is online

Users browsing this forum: MicroController and 207 guests