Skip to content

ZigbeeDimmableLight doesn't handle On/Off cluster commands leading to incompatibility with Philip Hue Lights #12026

@IAPark

Description

@IAPark

Board

Seeed Studio XIAO ESP32-C6

Device Description

It's dead simple and I'm pretty sure this is unrelated to hardware, but I'm using a Seeed Studio XIAO ESP32-C6 module attached to a small custom pcb with a single transister and resister controlling the output of a usb socket. I'm using it to control a string of fair lights with PWM.

Image

Hardware Configuration

Rough schematic
Image

Version

v3.3.4

Type

Bug

IDE Name

Arduino IDE

Operating System

MacOS 15.6.1

Flash frequency

80MHz

PSRAM enabled

no

Upload speed

921600

Description

onLightChange isn't being called when the board receives a command like endpoint: 10, cluster id: 0x6, command id: 0x40 buff: 0x00 0x00

Or when it receives a command like endpoint: 10, cluster id: 0x6, command id: 0x1 buff: See #12025 for a proposed fix/way to make this easier to solve on my end

Sketch

This code is very messy and adapted from the zigbee dimmable light example  

++

#include "Zigbee.h"

extern "C" {
  #include "zboss_api.h"
}

#ifndef ZIGBEE_MODE_ED
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
#endif

int led_pin = D6;
uint8_t led_resultion = 12;
uint32_t duty_cycle_range = 4096;
uint32_t min_duty_cyle = 55;
uint32_t available_range = duty_cycle_range - min_duty_cyle;

// this is well know but technically private
uint8_t light_link_key[] = {/* I'm not sure if I can legally share this, it is easy to find online*/};

class HueCompatibleDimmerLight : public ZigbeeDimmableLight {
    public:
  HueCompatibleDimmerLight(uint8_t endpoint): ZigbeeDimmableLight(endpoint) {
    _ep_config.app_device_version = 1;
  }
};

HueCompatibleDimmerLight zigbeeLight = HueCompatibleDimmerLight(10);

void write_brightness(uint8_t brightness) {
  uint32_t scaled = brightness * (available_range - 1);
  scaled = scaled / 254;
  scaled += min_duty_cyle;

  Serial.print("write_brightness ");
  Serial.println(scaled);

  analogWrite(led_pin, scaled);
}

void onLightChange(bool on, uint8_t brightness) {
  if (on && brightness > 0) {
    Serial.print("on ");
    Serial.println(brightness);
    write_brightness(brightness);
  } else {
    Serial.println("off");

    analogWrite(led_pin, 0);
  }
}

bool esp_zb_raw_command_handler(uint8_t bufid) {
  zb_zcl_parsed_hdr_t *cmd_info = ZB_BUF_GET_PARAM(bufid, zb_zcl_parsed_hdr_t);

  printf("endpoint: %d, cluster id: 0x%x, command id: 0x%x", cmd_info->addr_data.common_data.dst_endpoint, cmd_info->cluster_id, cmd_info->cmd_id);
  uint8_t *buf = (uint8_t*) zb_buf_begin(bufid);
  printf(" buff: ");
  for (int i = 0; i < zb_buf_len(bufid); ++i) {
      printf("0x%02X ", buf[i]);
  }
  printf("\n");
  return false;
}


void setup() {
  pinMode(led_pin, OUTPUT);    
  ledcOutputInvert(led_pin, true);
  Serial.begin(9600);
  analogWriteFrequency(led_pin, 5000);
  analogWriteResolution(led_pin, led_resultion);

  write_brightness(0);

  zigbeeLight.onLightChange(onLightChange);

  zigbeeLight.setManufacturerAndModel("Espressif", "USBFairyController");
  Zigbee.addEndpoint(&zigbeeLight);

  if (!Zigbee.begin()) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }

  esp_zb_raw_command_handler_register(&esp_zb_raw_command_handler);

  esp_zb_enable_joining_to_distributed(true);
  esp_zb_secur_TC_standard_distributed_key_set(light_link_key);

  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(100);
  }

  zigbeeLight.restoreLight();

  Serial.println("Initialized");
}

void loop() {
  delay(1000);
}

Debug Message

endpoint: 10, cluster id: 0x6, command id: 0x40 buff: 0x00 0x00 
endpoint: 10, cluster id: 0x6, command id: 0x1 buff: 
endpoint: 10, cluster id: 0x4, command id: 0x2 buff: 0x00 
endpoint: 10, cluster id: 0x5, command id: 0x6 buff: 0x08 0x23

Other Steps to Reproduce

It's likely that other zigbee light link adjacent setups will have this same issue. I only have the hue bridge

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

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions