Skip to content

Commit 4049f57

Browse files
committed
feat(zigbee): Add hue and sat attributes and update color capabilities
1 parent 74c1854 commit 4049f57

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
lines changed

Diff for: libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.cpp

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44
ZigbeeColorDimmableLight::ZigbeeColorDimmableLight(uint8_t endpoint) : ZigbeeEP(endpoint) {
55
_device_id = ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID;
66

7-
esp_zb_color_dimmable_light_cfg_t light_cfg = ESP_ZB_DEFAULT_COLOR_DIMMABLE_LIGHT_CONFIG();
7+
esp_zb_color_dimmable_light_cfg_t light_cfg = ZIGBEE_DEFAULT_COLOR_DIMMABLE_LIGHT_CONFIG();
88
_cluster_list = esp_zb_color_dimmable_light_clusters_create(&light_cfg);
9+
10+
//Add support for hue and saturation
11+
uint8_t hue = 0;
12+
uint8_t saturation = 0;
13+
14+
esp_zb_attribute_list_t *color_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
15+
esp_zb_color_control_cluster_add_attr(color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, &hue);
16+
esp_zb_color_control_cluster_add_attr(color_cluster, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, &saturation);
17+
918
_ep_config = {
1019
.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID, .app_device_version = 0
1120
};
@@ -30,8 +39,8 @@ uint16_t ZigbeeColorDimmableLight::getCurrentColorY() {
3039
->data_p);
3140
}
3241

33-
uint16_t ZigbeeColorDimmableLight::getCurrentColorHue() {
34-
return (*(uint16_t *)esp_zb_zcl_get_attribute(
42+
uint8_t ZigbeeColorDimmableLight::getCurrentColorHue() {
43+
return (*(uint8_t *)esp_zb_zcl_get_attribute(
3544
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID
3645
)
3746
->data_p);
@@ -84,8 +93,8 @@ void ZigbeeColorDimmableLight::zbAttributeSet(const esp_zb_zcl_set_attr_value_me
8493
_current_color = espXYToRgbColor(255, light_color_x, light_color_y); //TODO: Check if level is correct
8594
lightChanged();
8695
return;
87-
} else if (message->attribute.id == ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U16) {
88-
uint16_t light_color_hue = (*(uint16_t *)message->attribute.data.value);
96+
} else if (message->attribute.id == ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_U8) {
97+
uint8_t light_color_hue = (*(uint8_t *)message->attribute.data.value);
8998
_current_color = espHsvToRgbColor(light_color_hue, getCurrentColorSaturation(), 255);
9099
lightChanged();
91100
return;
@@ -137,8 +146,9 @@ void ZigbeeColorDimmableLight::setLight(bool state, uint8_t level, uint8_t red,
137146
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID, &xy_color.y, false
138147
);
139148
//set hsv color
149+
uint8_t hue = (uint8_t)hsv_color.h;
140150
esp_zb_zcl_set_attribute_val(
141-
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, &hsv_color.h, false
151+
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, &hue, false
142152
);
143153
esp_zb_zcl_set_attribute_val(
144154
_endpoint, ESP_ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, &hsv_color.s, false

Diff for: libraries/Zigbee/src/ep/ZigbeeColorDimmableLight.h

+43-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,48 @@
99
#include "ZigbeeEP.h"
1010
#include "ha/esp_zigbee_ha_standard.h"
1111

12+
#define ZIGBEE_DEFAULT_COLOR_DIMMABLE_LIGHT_CONFIG() \
13+
{ \
14+
.basic_cfg = \
15+
{ \
16+
.zcl_version = ESP_ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE, \
17+
.power_source = ESP_ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE, \
18+
}, \
19+
.identify_cfg = \
20+
{ \
21+
.identify_time = ESP_ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE, \
22+
}, \
23+
.groups_cfg = \
24+
{ \
25+
.groups_name_support_id = ESP_ZB_ZCL_GROUPS_NAME_SUPPORT_DEFAULT_VALUE, \
26+
}, \
27+
.scenes_cfg = \
28+
{ \
29+
.scenes_count = ESP_ZB_ZCL_SCENES_SCENE_COUNT_DEFAULT_VALUE, \
30+
.current_scene = ESP_ZB_ZCL_SCENES_CURRENT_SCENE_DEFAULT_VALUE, \
31+
.current_group = ESP_ZB_ZCL_SCENES_CURRENT_GROUP_DEFAULT_VALUE, \
32+
.scene_valid = ESP_ZB_ZCL_SCENES_SCENE_VALID_DEFAULT_VALUE, \
33+
.name_support = ESP_ZB_ZCL_SCENES_NAME_SUPPORT_DEFAULT_VALUE, \
34+
}, \
35+
.on_off_cfg = \
36+
{ \
37+
.on_off = ESP_ZB_ZCL_ON_OFF_ON_OFF_DEFAULT_VALUE, \
38+
}, \
39+
.level_cfg = \
40+
{ \
41+
.current_level = ESP_ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_DEFAULT_VALUE, \
42+
}, \
43+
.color_cfg = \
44+
{ \
45+
.current_x = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_X_DEF_VALUE, \
46+
.current_y = ESP_ZB_ZCL_COLOR_CONTROL_CURRENT_Y_DEF_VALUE, \
47+
.color_mode = ESP_ZB_ZCL_COLOR_CONTROL_COLOR_MODE_DEFAULT_VALUE, \
48+
.options = ESP_ZB_ZCL_COLOR_CONTROL_OPTIONS_DEFAULT_VALUE, \
49+
.enhanced_color_mode = ESP_ZB_ZCL_COLOR_CONTROL_ENHANCED_COLOR_MODE_DEFAULT_VALUE, \
50+
.color_capabilities = 0x0009, \
51+
}, \
52+
}
53+
1254
class ZigbeeColorDimmableLight : public ZigbeeEP {
1355
public:
1456
ZigbeeColorDimmableLight(uint8_t endpoint);
@@ -52,7 +94,7 @@ class ZigbeeColorDimmableLight : public ZigbeeEP {
5294

5395
uint16_t getCurrentColorX();
5496
uint16_t getCurrentColorY();
55-
uint16_t getCurrentColorHue();
97+
uint8_t getCurrentColorHue();
5698
uint8_t getCurrentColorSaturation();
5799

58100
void lightChanged();

0 commit comments

Comments
 (0)