Zigbee supporting Esp32 module with Arduino

@ilkeraktuna: I was looking at the ESP32-C6 and hoping to check out the ZigBee portion... but that is still not available yet even on the dev version of the ESP32 boards for the Arduino IDE. Thankfully the rest of the C6 is finally supported (it seems). I have two of these boards just waiting for official support.

Otherwise, I have a number of ESP8266 that I have on WiFi and being controlled by a Hubitat.

@snell , what do you mean by "zigbee support not available" on esp32-c6 ?
According to here:

there is already zigbee support on the dev kit.
I have ordered one.

Zigbee examples are referred here :

  • Official example 1 path: Zigbee -> light_sample -> HA_on_off_switch.
  • Official example 2 path: Zigbee -> light_sample -> HA_on_off_light.

The dev kit definitely has ZigBee but that hardware needs to be able to be used by the code and it seems that portion is still in progress. I also thought you were looking for it with Arduino not Visual Studio.

The ticket for the ZigBee support is still in the open state:

The examples and documentation below, aren't they usable in Arduino ?
I did not check them as I still don't have a board to try.
Well, if they are only VS , then maybe we can try to build on VS.
Isn't that possible ?

https://docs.espressif.com/projects/esp-zigbee-sdk/en/latest/esp32/developing.html

@snell,
the ticket you mentioned is not open.
It was closed 3 weeks ago saying:

Update: Ported 2 simple Zigbee examples from ESP-Zigbee-SDK (esp-idf) #9024.
Creating a wrapper or a library is not planned for now, so after merging the examples we are closing this issue.

Also, there are ported examples, here:

for example:

I think , following these, we can create our own apps.

I saw the examples but the base one I linked (#8807) still has Open and a status of "In Progress". It was just updated to mention the examples they will be including in the examples section.

I will try to see if I can run one of those examples with one of my boards tonight though, to see if it will actually work.

UPDATE:
I just loaded the light bulb on one of my two boards. It loaded without errors... but nothing is happening at all. I have it just a couple feet away from a hub and it is not being detected when I hit Start Zigbee pairing on the hub. I plan on trying more to see if I can get it functional... but right now I have family things to go deal with.

1 Like

@snell that would be wonderful. Please let me know if it works.
Actually I am not sure if we have to install any libraries to make these zigbee examples work.
Any idea ?

the readme here doesn't say anything about installing a library:

but the example code for light bulb has these includes:
#include "esp_zigbee_core.h"
#include "ha/esp_zigbee_ha_standard.h"

Do you know where they are available ?

the examples are not meant to work with Hubitat hub.
actually they are designed to connect to each other. Light switch is the coordinator, Light bulb is the end device.
So if you have 2 boards you can try connecting them together.
Or you can modify the code and add a network join routine...

You do not need to do anything special for the libraries, at least not on mine and I do not have much of any libraries installed.

I was HOPING as an end-device it had been set up as a "normal" ZigBee device that would be recognized... not just using it as a communication protocol between them. I have made drivers for ZigBee devices but I have never done anything involving this side of stuff with Arduino, most of my Arduino code is pretty basic.

So this means I have to get the rest of the ZigBee join done because there is zero value to me to have to set them up any other way... since I know the WiFi side and already have working code to integrate that with my Hubitats.

UPDATE:
Tried a bunch of things to no success. I will see if I come up with any better ideas tomorrow or stumble across any examples I can actually understand better. Not giving up overall though.

Those β€œZigbee” are examples are NOT using the Zigbee Home Automation (ZHA) standard (neither 1.2 nor 3.0). They are just a tech demo. Been there, tried that….

Yup, I figured that out. Just a "using ZigBee as a communication method" not what most people REALLY would want. So my plan is to look for different ones or maybe someone that has a project I can ask for some pointers from. Certainly a nights sleep did not give me any new insight. Oh well... off to work.

1 Like

@ogiewon , @snell
that's too bad. I was hoping to just modify some examples to make my own zigbee device and join the Hubitat hub.
So if this is the case, we must find either other examples or maybe another development environment.

Btw, there is a sdk documentatiom. Maybe we can find methods there for joining a hub.

@ogiewon , @snell : any news ?

this page says :

Zigbee

  • Zigbee 3.0 Home Automation - Supported
  • Zigbee RCP - Supported
  • Zigbee Gateway - Supported
2 Likes

and here are some HA examples:

1 Like

Nice! Looks like Zigbee Home Automation (ZHA) support is finally coming along for the ESP32-C6. I typically wait for support to be added to the Arduino IDE, as that is where I am most comfortable. But, if I have some time, I may try to build one of the ZHA examples using the Espressif IDF.

Thank you for sharing what you've found!

To be honest I got side tracked with other stuff and was not thinking about it much after the previous roadblocks. I will take a look at the new stuff you posted tonight.

UPDATE:
Unfortunately the HA samples are the same ones that have been around for a bit and that I have tried, where one is the end device and the other is the coordinator. They are not using the methods needed to work with Hubitat as they still do not rely on the ZigBee network/mesh. So they definitely have the capability for it... but no examples of how to do it yet. I replied to igrr about it... need to see what they respond with.

UPDATE 2:
Ok, so the examples they gave do supposedly allow connecting to a hub. They just did not say they could in the initial readme. Unfortunately these are not Arduino ones like you are looking for and are meant for the Espressif IDF. I have ZERO familiarity with it... but am trying to build it to at least see for myself. Hello World... Ugh... can't somebody come up with something new by now...

UPDATE 3 (Last for tonight):
I got the On/Off light to work with Hubitat. The example (as is) cannot pair with it at all... It will sit there forever and it will always be showing about Network steering not successful in the IDF's monitor. However, after updating the dependencies listed (all 3 dependencies in the idf_component file are outdated) and completely changing the esp_zb_task per people's work in this issue... it now pairs as a "Generic ZigBee Outlet" and the LED responds to On/Off commands. Tomorrow night I will try the Color Dimmable one...

So long story short, these CAN work with Hubitat (finally). The IDF examples do not appear to work as is (but CAN be made to work). After playing with these a bit over the next couple days I may see what is missing from the Arduino example and see if I can start making changes there. Fingers crossed.

Actually Espressif IDE codes can be easily ported to Arduino as far as I understand.

Check these 2 codes:

One is the pure Espressif IDE version, the other is the Arduino.

@snell
good news :slight_smile:
Can you share what you changed to make the example (espressif IDE one) work on a hub ?

btw, the esp32-c6 has an inner RGB led which we can try to control as a color lamp to test.
it is defined as:
#define LED_PIN RGB_BUILTIN

and then controlled as:
neopixelWrite(LED_PIN,255light_state,255light_state,255*light_state);

in this example:

Sure. The idf_component.yml is small enough, that changed to (you can see the old versions it listed commented out):

## IDF Component Manager Manifest File
dependencies:
  espressif/led_strip: "^2.5.2"
  espressif/esp-zboss-lib: "~1.0.9"
  espressif/esp-zigbee-lib: "~1.0.9"
  #espressif/esp-zboss-lib: "~1.0.0"
  #espressif/esp-zigbee-lib: "~1.0.0"
  #espressif/led_strip: "~2.0.0"
  ## Required IDF version
  idf:
    version: ">=5.0.0"

The esp_zb_light.c file, I replaced the esp_zb_task portion with what was posted in issue 10662 I linked before. Here is what I used:

char modelid[] = {13, 'E', 'S', 'P', '3', '2', 'C', '6', '.', 'L', 'i', 'g', 'h', 't'};
char manufname[] = {9, 'E', 's', 'p', 'r', 'e', 's', 's', 'i', 'f'};

static void esp_zb_task(void *pvParameters)
{
    // initialize Zigbee stack with Zigbee end-device config 
    esp_zb_cfg_t zb_nwk_cfg = ESP_ZB_ZED_CONFIG();
    esp_zb_init(&zb_nwk_cfg);
    esp_zb_set_primary_network_channel_set(ESP_ZB_PRIMARY_CHANNEL_MASK);

    // set the on-off light device config
    uint8_t test_attr, test_attr2;
 
    test_attr = 0;
    test_attr2 = 4;
    // 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_attr2);
    esp_zb_cluster_update_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, &test_attr2);
    esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, &modelid[0]);
    esp_zb_basic_cluster_add_attr(esp_zb_basic_cluster, ESP_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, &manufname[0]);
    // 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);
    // 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);
    // update basic cluster in the existed cluster list
    //esp_zb_cluster_list_update_basic_cluster(esp_zb_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
    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_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_LIGHT_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();
}

The color_dimmable light controls the LED if I remember correctly. That is why tonight's project will be to work on that a bit. I also had to bring over some of their "common" code and such also from github and things like that (plus getting the idf working properly) are probably what took up more time (and problem solving).

@snell

thanks for sharing that.
Unfortunately I don't have the Espressif IDE environment set up on my PC.
Is it easy to start with ?
Do you use VS or Eclipse ?

Btw, have you read my previous post about porting the code to Arduino ?
Is it possible or not ?