Skip to content

Zigbee Thermostat example | Unable to get mode , temperature state #12259

@sonirohit3

Description

@sonirohit3

Board

ESP32-C6

Device Description

Custom board

Hardware Configuration

No pins required

Version

Please select a version from the list below

Type

Task

IDE Name

Arduino IDE

Operating System

Macos

Flash frequency

160

PSRAM enabled

no

Upload speed

115200

Description

I am using thermostat example. The end goal is to utilize the thermostat example, have UI on HA and provide Temperature , Mode and FAN ( currently unavailable) to the esp32-C6. This module will then transmit IR codes and control the AC.

Issue: There are no callback registered to get the data from HA. I see those messages hitting the internal zb_attribute_set_handler function but no way to get data to sketch. Tried extern function extern "C" void zb_attribute_set_handler but won't hit since priority is set to internal function.

Sketch

#ifndef ZIGBEE_MODE_ZCZR
#error "Zigbee Router mode required"
#endif

#include "Zigbee.h"

#define ENDPOINT_ID 1

ZigbeeThermostat thermostat(ENDPOINT_ID);

/* ---------------- ZCL ATTRIBUTE WRITE HANDLER ---------------- */
extern "C" void zb_attribute_set_handler(
  esp_zb_zcl_addr_t src_addr,
  uint8_t endpoint,
  uint16_t cluster,
  uint16_t attribute,
  uint8_t *data,
  uint16_t length
) {
  (void)src_addr;

  if (endpoint != ENDPOINT_ID) return;

  if (cluster == 0x0201) {  // Thermostat cluster
    Serial.println(">>> HA → Thermostat Write <<<");

    // SystemMode
    if (attribute == 0x001C && length == 1) {
      Serial.printf("SystemMode: %u\n", data[0]);
      // 0=Off, 3=Cool, 4=Heat
    }

    // Occupied Heating Setpoint
    if (attribute == 0x0012 && length == 2) {
      int16_t raw = data[0] | (data[1] << 8);
      float temp = raw / 100.0f;
      Serial.printf("Set Temperature: %.2f °C\n", temp);
    }

    // Unoccupied Heating Setpoint (HA also sends this)
    if (attribute == 0x0011 && length == 2) {
      int16_t raw = data[0] | (data[1] << 8);
      float temp = raw / 100.0f;
      Serial.printf("Unoccupied Setpoint: %.2f °C\n", temp);
    }
  }
}
/* ------------------------------------------------------------- */

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println("Zigbee Thermostat (IR Controller)");

  thermostat.setManufacturerAndModel("Espressif", "ZB-IR-AC");

  // Add endpoint
  Zigbee.addEndpoint(&thermostat);

  // Join existing coordinator (Home Assistant)
  if (!Zigbee.begin(ZIGBEE_ROUTER)) {
    Serial.println("Zigbee start failed");
    ESP.restart();
  }

  Serial.print("Joining Zigbee network");
  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(500);
  }

  Serial.println("\nConnected to Home Assistant");
}

void loop() {
  // Nothing required here
  delay(1000);
}

Debug Message

Enable verbose to see internal function logs

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.

Metadata

Metadata

Assignees

Labels

Area: ZigbeeIssues and Feature Request about ZigbeeType: Feature requestFeature request for Arduino ESP32

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions