Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32H2 + ZigBee Door Sensor ZG-102lL #11169

Closed
1 task done
Usama050 opened this issue Mar 24, 2025 · 19 comments
Closed
1 task done

ESP32H2 + ZigBee Door Sensor ZG-102lL #11169

Usama050 opened this issue Mar 24, 2025 · 19 comments
Assignees
Labels
Area: Zigbee Issues and Feature Request about Zigbee Type: Question Only question

Comments

@Usama050
Copy link

Board

ESP32H2

Device Description

I am using ESP32H2 microcontroller as a ZigBee coordinator and I successfully connected my door sensor with ZigBee coordinator using ZIgBee_On_Off_Switch_Example but I can not read my sensor data. Can anyone tell me how can I read my sensor data which are connected with ZigBee coordinator on serial monitor. Thank you!

Hardware Configuration

I am using ZigBee protocol not any pin

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Window 11

Flash frequency

64 MHz

PSRAM enabled

yes

Upload speed

921600

Description

I am using ESP32H2 microcontroller as a ZigBee coordinator and I successfully connected my door sensor with ZigBee coordinator using ZIgBee_On_Off_Switch_Example but I can not read my sensor data. Can anyone tell me how can I read my sensor data which are connected with ZigBee coordinator on serial monitor. Thank you!

Sketch

I am not sure about it

Debug Message

19:55:32.168 -> [ 17966][I][ZigbeeCore.cpp:338] esp_zb_app_signal_handler(): Network(0x24a7) is open for 180 seconds
19:57:01.923 -> Toggling light
19:57:01.923 -> [107716][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
19:57:01.923 -> Bound devices:
19:57:01.923 -> [107725][V][ZigbeeCore.cpp:351] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
19:57:01.962 -> Device on endpoint 255, short address: 0xffff, ieee address: 00:00:00:00:00:00:00:00
19:57:05.381 -> Toggling light
19:57:05.381 -> [111181][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
19:57:05.423 -> [111190][V][ZigbeeCore.cpp:351] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
19:57:09.011 -> Toggling light
19:57:09.011 -> [114796][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
19:57:09.011 -> [114805][V][ZigbeeCore.cpp:351] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
19:57:11.178 -> Toggling light
19:57:11.178 -> [116977][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
19:57:11.224 -> [116986][V][ZigbeeCore.cpp:351] esp_zb_app_signal_handler(): ZDO signal: ZDO Device Unavailable (0x3c), status: ESP_OK
19:57:12.915 -> Toggling light
19:57:12.916 -> [118668][V][ZigbeeSwitch.cpp:72] lightToggle(): Sending 'light toggle' command
19:57:12.916 -> Bound devices:

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@Usama050 Usama050 added the Status: Awaiting triage Issue is waiting for triage label Mar 24, 2025
@Parsaabasi Parsaabasi assigned Parsaabasi and unassigned Parsaabasi Mar 25, 2025
@P-R-O-C-H-Y P-R-O-C-H-Y marked this as a duplicate of #11175 Mar 25, 2025
@P-R-O-C-H-Y P-R-O-C-H-Y self-assigned this Mar 25, 2025
@P-R-O-C-H-Y P-R-O-C-H-Y added the Area: Zigbee Issues and Feature Request about Zigbee label Mar 25, 2025
@P-R-O-C-H-Y
Copy link
Member

@Usama050 Hi, Can you provide the sketch you are using? Thanks

@P-R-O-C-H-Y P-R-O-C-H-Y removed the Status: Awaiting triage Issue is waiting for triage label Mar 25, 2025
@Usama050
Copy link
Author

Usama050 commented Mar 25, 2025

@P-R-O-C-H-Y Hi, I am using the same code as in example
libraries/Zigbee/examples/Zigbee_On_Off_Switch/Zigbee_On_Off_Switch.ino example

@Usama050
Copy link
Author

Usama050 commented Mar 25, 2025

@P-R-O-C-H-Y Hi!
Then I change some code but still did not read the value I am using ZG-102ZL/ ZG-102Z Door sensor

#ifndef ZIGBEE_MODE_ZCZR
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
#endif

#include "Zigbee.h"

/* Zigbee switch configuration */
#define SWITCH_ENDPOINT_NUMBER 5
#define DOOR_ENDPOINT_NUMBER 4 

#define GPIO_INPUT_IO_TOGGLE_SWITCH BOOT_PIN
#define PAIR_SIZE(TYPE_STR_PAIR)    (sizeof(TYPE_STR_PAIR) / sizeof(TYPE_STR_PAIR[0]))

typedef enum {
  SWITCH_ON_CONTROL,
  SWITCH_OFF_CONTROL,
  SWITCH_ONOFF_TOGGLE_CONTROL,
  SWITCH_LEVEL_UP_CONTROL,
  SWITCH_LEVEL_DOWN_CONTROL,
  SWITCH_LEVEL_CYCLE_CONTROL,
  SWITCH_COLOR_CONTROL,
} SwitchFunction;

typedef struct {
  uint8_t pin;
  SwitchFunction func;
} SwitchData;

typedef enum {
  SWITCH_IDLE,
  SWITCH_PRESS_ARMED,
  SWITCH_PRESS_DETECTED,
  SWITCH_PRESSED,
  SWITCH_RELEASE_DETECTED,
} SwitchState;

static SwitchData buttonFunctionPair[] = {{GPIO_INPUT_IO_TOGGLE_SWITCH, SWITCH_ONOFF_TOGGLE_CONTROL}};

ZigbeeSwitch zbSwitch = ZigbeeSwitch(SWITCH_ENDPOINT_NUMBER);
ZigbeeDoorWindowHandle zbDoor = ZigbeeDoorWindowHandle(DOOR_ENDPOINT_NUMBER);


void setup() {
  Serial.begin(115200);

  //Optional: set Zigbee device name and model
  zbDoor.setManufacturerAndModel("Espressif", "ZigbeeDoor");

  //Optional to allow multiple light to bind to the switch
  zbDoor.allowMultipleBinding(true);

  //Add endpoint to Zigbee Core
  Serial.println("Adding ZigbeeSwitch endpoint to Zigbee Core");
  Zigbee.addEndpoint(&zbDoor);

  //Open network for 180 seconds after boot
  Zigbee.setRebootOpenNetwork(180);
if (!Zigbee.begin(ZIGBEE_COORDINATOR)) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }

  Serial.println("Waiting for Door Sensor to bound to the switch");
  //Wait for switch to bound to a light:
  while (!zbDoor.bound()) {
    Serial.printf(".");
    delay(500);
  }

  // Optional: List all bound devices and read manufacturer and model name
  std::list<zb_device_params_t *> boundLights = zbDoor.getBoundDevices();
  for (const auto &device : boundLights) {
    Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr);
    Serial.printf(
      "IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", device->ieee_addr[7], device->ieee_addr[6], device->ieee_addr[5], device->ieee_addr[4],
      device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]
    );
    char *manufacturer = zbDoor.readManufacturer(device->endpoint, device->short_addr, device->ieee_addr);
    char *model = zbDoor.readModel(device->endpoint, device->short_addr, device->ieee_addr);
    if (manufacturer != nullptr) {
      Serial.printf("Light manufacturer: %s\r\n", manufacturer);
    }
    if (model != nullptr) {
      Serial.printf("Light model: %s\r\n", model);
    }
  }

  Serial.println();
}

void loop() {
  // Handle button switch in loop()
  uint8_t pin = 0;
  SwitchData buttonSwitch;
  static SwitchState buttonState = SWITCH_IDLE;
  bool eventFlag = false;
 static uint32_t lastPrint = 0;
    if (millis() - lastPrint > 10000) {
      lastPrint = millis();
       zbDoor.printBoundDevices(Serial);
    }
}

@P-R-O-C-H-Y
Copy link
Member

Hello, this is not the way the Zigbee library works.
In order to be able to receive the DoorSensor data, the coordinator needs to have the same cluster implemented but in client role (the door sensor have it in server role). I can add kind of device to have all sensors clusters in client role, but tbh this Zigbee library is mostly made to create the End Devices that connects to Coordinator running for example under HomeAssistants ZHA or Zigbee2MQTT.

@Usama050
Copy link
Author

Usama050 commented Mar 26, 2025

@P-R-O-C-H-Y Hello! I just want to make my esp32h2 a zigbee coordinator and then connect some sensor with this coordinator and then want to read the data of these sensor.

@Usama050
Copy link
Author

@P-R-O-C-H-Y As far as I understand it means I can not create zigbee coordinator ?

@Usama050
Copy link
Author

@P-R-O-C-H-Y and I think it is possible to make esp32h2 a ZigBee coordinator and then connect ZigBee sensor with this coordinator and read their values.

@P-R-O-C-H-Y
Copy link
Member

@Usama050 You can create a coordinator, but there are examples and classes only for Thermostat and Switches.
There is no class for Door Sensor Reader that have the correct clusters implemented.
If you want you can create your own class based on thermostat (just the base, most function will be useless), but changing the temperature measurement (client role) cluster to the one that fits your case.

@P-R-O-C-H-Y
Copy link
Member

Do you know what clusters does your Door Sensor use?

@P-R-O-C-H-Y P-R-O-C-H-Y added the Type: Question Only question label Mar 26, 2025
@Usama050
Copy link
Author

Usama050 commented Mar 26, 2025

@P-R-O-C-H-Y I am not sure I guess IAS cluster or HA cluster

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Mar 28, 2025

In that case how I said, you will need to develop an endpoint, which have an IAS client cluster, so its able to receive the data from the door sensor.

@Usama050
Copy link
Author

@P-R-O-C-H-Y Hello! Do we have binary Input cluster in ZigBee lib in Arduino?

@P-R-O-C-H-Y
Copy link
Member

@P-R-O-C-H-Y Hello! Do we have binary Input cluster in ZigBee lib in Arduino?

@Usama050 Hi! Not yet. I am planning to add Binary Input/output and Multistate Input/output once its fully supported in HomeAssistant ZHA integration. It may be done in few weeks.

@Usama050
Copy link
Author

Usama050 commented Apr 1, 2025

@P-R-O-C-H-Y Hello! so it means I can not read the data from my door sensor because my door sensor only has on and off state.

@mmackh
Copy link

mmackh commented Apr 1, 2025

+1, aim is to setup the ESP32 as a coordinator and read the state of a contact switch/sensor and toggling a light on or off. I haven't managed to get it working - if anyone has, please share some code. Either for the esp-idf zigbee sdk directly or through the Arduino abstraction

@Usama050
Copy link
Author

Usama050 commented Apr 1, 2025

I am working on it, you can check this example in this example the made esp32h2 as coordinator and receive the temperature data you can change the cluster according to your requirement

@P-R-O-C-H-Y
Copy link
Member

P-R-O-C-H-Y commented Apr 3, 2025

@Usama050 too make it clear, you are posting to the esp-zigbee-sdk example, not Arduino Zigbee Library.
I am closing this issue (as duplicate) as you also have one in esp-zigbee-sdk repo regarding same topic and it waiting on your reply. And it seems that you are using that also.
espressif/esp-zigbee-sdk#604

@mmackh
Copy link

mmackh commented Apr 3, 2025

@P-R-O-C-H-Y is it possible that there will be an Arduino abstraction in the future? It seems valuable.

@P-R-O-C-H-Y
Copy link
Member

@mmackh It is possible and also a doable thing by the community :) I have that in my list of possible features to add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Zigbee Issues and Feature Request about Zigbee Type: Question Only question
Projects
None yet
Development

No branches or pull requests

4 participants