I have an ESP32-C6 that successfully connects to my zigbee coordinator, including a custom set manufacturer name, model number and related config file so that it shows up properly as a supported device in Z2M:
Curently the state only reports linkquality:
What I'd like to do is report other parameters to state.json (ie sensor readings from something connected to the ESP32), so that they can be used in HomeAssistant.
Here's my zb_task code:
- static void esp_zb_task(void *pvParameters)
- {
- // Custom mfg/model
- char manufname[] = {9, 'E', 's', 'p', 'r', 'e', 's', 's', 'i', 'f'};
- char modelid[] = {14, 'E', 'S', 'P', '3', '2', 'C', '6', '.', 'S', 'e', 'n', 's', 'o', 'r'};
- /* Initialize Zigbee stack */
- esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG();
- esp_zb_init(&zb_nwk_cfg);
- /* Create basic cluster */
- 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_MANUFACTURER_NAME_ID, &manufname[0]);
- esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, &modelid[0]);
- /* Create cluster lists for this endpoint */
- esp_zb_cluster_list_t *esp_zb_cluster_list = esp_zb_zcl_cluster_list_create();
- esp_zb_cluster_list_add_basic_cluster(esp_zb_cluster_list, esp_zb_basic_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_ESP_SENSOR_ENDPOINT, ESP_ZB_AF_HA_PROFILE_ID, ESP_ZB_HA_ON_OFF_OUTPUT_DEVICE_ID);
- esp_zb_device_register(esp_zb_ep_list);
- esp_zb_core_action_handler_register(zb_action_handler);
- ESP_ERROR_CHECK(esp_zb_start(false));
- esp_zb_main_loop_iteration();
- }