From 46e9353186e4282551d601ab14af7c67340a948f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 7 Jul 2025 10:26:22 +0200 Subject: [PATCH 1/3] feat(zigbee): Add Fan Control endpoint support --- CMakeLists.txt | 1 + .../examples/Zigbee_Fan_Control/README.md | 83 +++++++++++ .../Zigbee_Fan_Control/Zigbee_Fan_Control.ino | 131 ++++++++++++++++++ .../examples/Zigbee_Fan_Control/ci.json | 6 + libraries/Zigbee/keywords.txt | 60 ++++++-- libraries/Zigbee/src/Zigbee.h | 1 + libraries/Zigbee/src/ep/ZigbeeFanControl.cpp | 58 ++++++++ libraries/Zigbee/src/ep/ZigbeeFanControl.h | 65 +++++++++ 8 files changed, 393 insertions(+), 12 deletions(-) create mode 100644 libraries/Zigbee/examples/Zigbee_Fan_Control/README.md create mode 100644 libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino create mode 100644 libraries/Zigbee/examples/Zigbee_Fan_Control/ci.json create mode 100644 libraries/Zigbee/src/ep/ZigbeeFanControl.cpp create mode 100644 libraries/Zigbee/src/ep/ZigbeeFanControl.h diff --git a/CMakeLists.txt b/CMakeLists.txt index e8f44ac5ee0..f21183ee11e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -305,6 +305,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp libraries/Zigbee/src/ep/ZigbeeBinary.cpp libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp + libraries/Zigbee/src/ep/ZigbeeFanControl.cpp ) set(ARDUINO_LIBRARY_BLE_SRCS diff --git a/libraries/Zigbee/examples/Zigbee_Fan_Control/README.md b/libraries/Zigbee/examples/Zigbee_Fan_Control/README.md new file mode 100644 index 00000000000..91700b669a0 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Fan_Control/README.md @@ -0,0 +1,83 @@ +# Arduino-ESP32 Zigbee Fan Control Example + +This example demonstrates how to use the Zigbee library to create a router device fan control and use it as a Home Automation (HA) fan control device. + +# Supported Targets + +Currently, this example supports the following targets. + +| Supported Targets | ESP32-C6 | ESP32-H2 | +| ----------------- | -------- | -------- | + +## Fan Control Functions + +1. Initialize a Zigbee fan control device. +2. Control fan modes (OFF, LOW, MEDIUM, HIGH, ON). +3. Respond to fan control commands from the Zigbee network. + +## Hardware Required + +* ESP32-H2 or ESP32-C6 development board +* A USB cable for power supply and programming +* RGB LED for visual feedback (built-in on most development boards) + +### Configure the Project + +In this example the RGB LED is used to indicate the current fan control mode. +The LED colors represent different fan modes: +- OFF: No light +- LOW: Blue +- MEDIUM: Yellow +- HIGH: Red +- ON: White + +Set the button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (BOOT button on ESP32-C6 and ESP32-H2). + +#### Using Arduino IDE + +To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits). + +* Before Compile/Verify, select the correct board: `Tools -> Board`. +* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)` +* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee ZCZR 4MB with spiffs` +* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port. +* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`. + +## Troubleshooting + +If the End device flashed with this example is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator. +You can do the following: + +* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`. +* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack. + +By default, the coordinator network is closed after rebooting or flashing new firmware. +To open the network you have 2 options: + +* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`. +* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join. + + +***Important: Make sure you are using a good quality USB cable and that you have a reliable power source*** + +* **LED not blinking:** Check the wiring connection and the IO selection. +* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed. +* **COM port not detected:** Check the USB cable and the USB to Serial driver installation. + +If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute). + +## Contribute + +To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst) + +If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome! + +Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else. + +## Resources + +* Official ESP32 Forum: [Link](https://esp32.com) +* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) +* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) +* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) +* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com) diff --git a/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino b/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino new file mode 100644 index 00000000000..868aa1f74f9 --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino @@ -0,0 +1,131 @@ +// Copyright 2025 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @brief This example demonstrates simple Zigbee fan control. + * + * The example demonstrates how to use Zigbee library to create a router device fan control. + * The fan control is a Zigbee router device, which is controlled by a Zigbee coordinator. + * + * Proper Zigbee mode must be selected in Tools->Zigbee mode + * and also the correct partition scheme must be selected in Tools->Partition Scheme. + * + * Please check the README.md for instructions and more detailed description. + * + * Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/) + */ + +#ifndef ZIGBEE_MODE_ZCZR +#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode" +#endif + +#include "Zigbee.h" + +/* Zigbee light bulb configuration */ +#define ZIGBEE_FAN_CONTROL_ENDPOINT 1 + +#ifdef RGB_BUILTIN +uint8_t led = RGB_BUILTIN; // To demonstrate the current fan control mode +#else +uint8_t led = 2; +#endif + +uint8_t button = BOOT_PIN; + +ZigbeeFanControl zbFanControl = ZigbeeFanControl(ZIGBEE_FAN_CONTROL_ENDPOINT); + +/********************* fan control callback function **************************/ +void setFan(ZigbeeFanMode mode) { + switch (mode) { + case FAN_MODE_OFF: + rgbLedWrite(led, 0, 0, 0); // Off + Serial.println("Fan mode: OFF"); + break; + case FAN_MODE_LOW: + rgbLedWrite(led, 0, 0, 255); // Blue + Serial.println("Fan mode: LOW"); + break; + case FAN_MODE_MEDIUM: + rgbLedWrite(led, 255, 255, 0); // Yellow + Serial.println("Fan mode: MEDIUM"); + break; + case FAN_MODE_HIGH: + rgbLedWrite(led, 255, 0, 0); // Red + Serial.println("Fan mode: HIGH"); + break; + case FAN_MODE_ON: + rgbLedWrite(led, 255, 255, 255); // White + Serial.println("Fan mode: ON"); + break; + default: + log_e("Unhandled fan mode: %d", mode); + break; + } +} + +/********************* Arduino functions **************************/ +void setup() { + Serial.begin(115200); + + // Init LED that will be used to indicate the current fan control mode + rgbLedWrite(led, 0, 0, 0); + + // Init button for factory reset + pinMode(button, INPUT_PULLUP); + + //Optional: set Zigbee device name and model + zbFanControl.setManufacturerAndModel("Espressif", "ZBFanControl"); + + // Set the fan mode sequence to LOW_MED_HIGH + zbFanControl.setFanModeSequence(FAN_MODE_SEQUENCE_LOW_MED_HIGH); + + // Set callback function for fan mode change + zbFanControl.onFanModeChange(setFan); + + //Add endpoint to Zigbee Core + Serial.println("Adding ZigbeeFanControl endpoint to Zigbee Core"); + Zigbee.addEndpoint(&zbFanControl); + + // When all EPs are registered, start Zigbee in ROUTER mode + if (!Zigbee.begin(ZIGBEE_ROUTER)) { + Serial.println("Zigbee failed to start!"); + Serial.println("Rebooting..."); + ESP.restart(); + } + Serial.println("Connecting to network"); + while (!Zigbee.connected()) { + Serial.print("."); + delay(100); + } + Serial.println(); +} + +void loop() { + // Checking button for factory reset + if (digitalRead(button) == LOW) { // Push button pressed + // Key debounce handling + delay(100); + int startTime = millis(); + while (digitalRead(button) == LOW) { + delay(50); + if ((millis() - startTime) > 3000) { + // If key pressed for more than 3secs, factory reset Zigbee and reboot + Serial.println("Resetting Zigbee to factory and rebooting in 1s."); + delay(1000); + Zigbee.factoryReset(); + } + } + } + delay(100); +} diff --git a/libraries/Zigbee/examples/Zigbee_Fan_Control/ci.json b/libraries/Zigbee/examples/Zigbee_Fan_Control/ci.json new file mode 100644 index 00000000000..15d6190e4ae --- /dev/null +++ b/libraries/Zigbee/examples/Zigbee_Fan_Control/ci.json @@ -0,0 +1,6 @@ +{ + "fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr", + "requires": [ + "CONFIG_ZB_ENABLED=y" + ] +} diff --git a/libraries/Zigbee/keywords.txt b/libraries/Zigbee/keywords.txt index 556b6408ea2..23f3af3bf02 100644 --- a/libraries/Zigbee/keywords.txt +++ b/libraries/Zigbee/keywords.txt @@ -12,25 +12,31 @@ Zigbee KEYWORD1 ZigbeeEP KEYWORD1 # Endpoint Classes -ZigbeeLight KEYWORD1 -ZigbeeSwitch KEYWORD1 -ZigbeeColorDimmableLight KEYWORD1 -ZigbeeColorDimmerSwitch KEYWORD1 -ZigbeeTempSensor KEYWORD1 -ZigbeeThermostat KEYWORD1 -ZigbeeFlowSensor KEYWORD1 -ZigbeePressureSensor KEYWORD1 -ZigbeeOccupancySensor KEYWORD1 ZigbeeAnalog KEYWORD1 +ZigbeeBinary KEYWORD1 ZigbeeCarbonDioxideSensor KEYWORD1 +ZigbeeColorDimmableLight KEYWORD1 +ZigbeeColorDimmerSwitch KEYWORD1 ZigbeeContactSwitch KEYWORD1 +ZigbeeDimableLight KEYWORD1 ZigbeeDoorWindowHandle KEYWORD1 +ZigbeeElectricalMeasurement KEYWORD1 +ZigbeeFanControl KEYWORD1 +ZigbeeFlowSensor KEYWORD1 ZigbeeGateway KEYWORD1 +ZigbeeIlluminanceSensor KEYWORD1 +ZigbeeLight KEYWORD1 +ZigbeeOccupancySensor KEYWORD1 +ZigbeePM25Sensor KEYWORD1 +ZigbeePowerOutlet KEYWORD1 +ZigbeePressureSensor KEYWORD1 ZigbeeRangeExtender KEYWORD1 +ZigbeeSwitch KEYWORD1 +ZigbeeTempSensor KEYWORD1 +ZigbeeThermostat KEYWORD1 ZigbeeVibrationSensor KEYWORD1 ZigbeeWindowCovering KEYWORD1 -ZigbeeIlluminanceSensor KEYWORD1 -ZigbeePowerOutlet KEYWORD1 +ZigbeeWindSpeedSensor KEYWORD1 # Other zigbee_role_t KEYWORD1 @@ -39,6 +45,8 @@ zb_device_params_t KEYWORD1 zigbee_scan_result_t KEYWORD1 zb_power_source_t KEYWORD1 ZigbeeWindowCoveringType KEYWORD1 +ZigbeeFanMode KEYWORD1 +ZigbeeFanModeSequence KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) @@ -73,6 +81,7 @@ printBoundDevices KEYWORD2 getBoundDevices KEYWORD2 bound KEYWORD2 allowMultipleBinding KEYWORD2 +setManualBinding KEYWORD2 setManufacturerAndModel KEYWORD2 setPowerSource KEYWORD2 setBatteryPercentage KEYWORD2 @@ -80,6 +89,13 @@ reportBatteryPercentage KEYWORD2 readManufacturer KEYWORD2 readModel KEYWORD2 onIdentify KEYWORD2 +addTimeCluster KEYWORD2 +setTime KEYWORD2 +setTimezone KEYWORD2 +getTime KEYWORD2 +getTimezone KEYWORD2 +addOTAClient KEYWORD2 +clearBoundDevices KEYWORD2 # ZigbeeLight + ZigbeeColorDimmableLight onLightChange KEYWORD2 @@ -171,7 +187,7 @@ setTilted KEYWORD2 # ZigbeeVibrationSensor setVibration KEYWORD2 -ZigbeeWindowCovering +# ZigbeeWindowCovering onOpen KEYWORD2 onClose KEYWORD2 onGoToLiftPercentage KEYWORD2 @@ -186,6 +202,26 @@ setConfigStatus KEYWORD2 setMode KEYWORD2 setLimits KEYWORD2 +# ZigbeeBinary +addBinaryInput KEYWORD2 +addBinaryOutput KEYWORD2 +onBinaryOutputChange KEYWORD2 +setBinaryInput KEYWORD2 +setBinaryOutput KEYWORD2 +getBinaryOutput KEYWORD2 +reportBinaryInput KEYWORD2 +reportBinaryOutput KEYWORD2 +setBinaryInputApplication KEYWORD2 +setBinaryInputDescription KEYWORD2 +setBinaryOutputApplication KEYWORD2 +setBinaryOutputDescription KEYWORD2 + +# ZigbeeFanControl +setFanModeSequence KEYWORD2 +getFanMode KEYWORD2 +getFanModeSequence KEYWORD2 +onFanModeChange KEYWORD2 + ####################################### # Constants (LITERAL1) ####################################### diff --git a/libraries/Zigbee/src/Zigbee.h b/libraries/Zigbee/src/Zigbee.h index b2e2e5dd027..65c9e7f0daa 100644 --- a/libraries/Zigbee/src/Zigbee.h +++ b/libraries/Zigbee/src/Zigbee.h @@ -16,6 +16,7 @@ #include "ep/ZigbeeLight.h" //// Controllers #include "ep/ZigbeeThermostat.h" +#include "ep/ZigbeeFanControl.h" ////Outlets #include "ep/ZigbeePowerOutlet.h" //// Sensors diff --git a/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp new file mode 100644 index 00000000000..600df1f63a8 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp @@ -0,0 +1,58 @@ +#include "ZigbeeFanControl.h" +#if CONFIG_ZB_ENABLED + +ZigbeeFanControl::ZigbeeFanControl(uint8_t endpoint) : ZigbeeEP(endpoint) { + _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + + //Create basic analog sensor clusters without configuration + _cluster_list = esp_zb_zcl_cluster_list_create(); + esp_zb_cluster_list_add_basic_cluster(_cluster_list, esp_zb_basic_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_zb_cluster_list_add_fan_control_cluster(_cluster_list, esp_zb_fan_control_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + + _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID, .app_device_version = 0}; +} + +bool ZigbeeFanControl::setFanModeSequence(ZigbeeFanModeSequence sequence) { + esp_zb_attribute_list_t *fan_control_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_FAN_CONTROL, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(fan_control_cluster, ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID, (void *)&sequence); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + _current_fan_mode_sequence = sequence; + _current_fan_mode = FAN_MODE_OFF; + // Set initial fan mode to OFF + ret = esp_zb_cluster_update_attr(fan_control_cluster, ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID, (void *)&_current_fan_mode); + if (ret != ESP_OK) { + log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + +//set attribute method -> method overridden in child class +void ZigbeeFanControl::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) { + //check the data and call right method + if (message->info.cluster == ESP_ZB_ZCL_CLUSTER_ID_FAN_CONTROL) { + if (message->attribute.id == ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID && message->attribute.data.type == ESP_ZB_ZCL_ATTR_TYPE_8BIT_ENUM) { + _current_fan_mode = *(ZigbeeFanMode *)message->attribute.data.value; + fanModeChanged(); + } else { + log_w("Received message ignored. Attribute ID: %d not supported for On/Off Light", message->attribute.id); + } + } else { + log_w("Received message ignored. Cluster ID: %d not supported for On/Off Light", message->info.cluster); + } +} + +void ZigbeeFanControl::fanModeChanged() { + if (_on_fan_mode_change) { + _on_fan_mode_change(_current_fan_mode); + } else { + log_w("No callback function set for light change"); + } +} + +#endif // CONFIG_ZB_ENABLED diff --git a/libraries/Zigbee/src/ep/ZigbeeFanControl.h b/libraries/Zigbee/src/ep/ZigbeeFanControl.h new file mode 100644 index 00000000000..25b5862c5c4 --- /dev/null +++ b/libraries/Zigbee/src/ep/ZigbeeFanControl.h @@ -0,0 +1,65 @@ +/* Class of Zigbee Pressure sensor endpoint inherited from common EP class */ + +#pragma once + +#include "soc/soc_caps.h" +#include "sdkconfig.h" +#if CONFIG_ZB_ENABLED + +#include "ZigbeeEP.h" +#include "ha/esp_zigbee_ha_standard.h" + +// Custom Arduino-friendly enums for fan mode values +enum ZigbeeFanMode { + FAN_MODE_OFF = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_OFF, + FAN_MODE_LOW = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_LOW, + FAN_MODE_MEDIUM = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_MEDIUM, + FAN_MODE_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_HIGH, + FAN_MODE_ON = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_ON, + FAN_MODE_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_AUTO, + FAN_MODE_SMART = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SMART, +}; + +// Custom Arduino-friendly enums for fan mode sequence +enum ZigbeeFanModeSequence { + FAN_MODE_SEQUENCE_LOW_MED_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH, + FAN_MODE_SEQUENCE_LOW_HIGH = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH, + FAN_MODE_SEQUENCE_LOW_MED_HIGH_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH_AUTO, + FAN_MODE_SEQUENCE_LOW_HIGH_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH_AUTO, + FAN_MODE_SEQUENCE_ON_AUTO = ESP_ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_ON_AUTO, +}; + +class ZigbeeFanControl : public ZigbeeEP { +public: + ZigbeeFanControl(uint8_t endpoint); + ~ZigbeeFanControl() {} + + // Set the fan mode sequence value + bool setFanModeSequence(ZigbeeFanModeSequence sequence); + + // Use to get fan mode + ZigbeeFanMode getFanMode() { + return _current_fan_mode; + } + + // Use to get fan mode sequence + ZigbeeFanModeSequence getFanModeSequence() { + return _current_fan_mode_sequence; + } + + // On fan mode change callback + void onFanModeChange(void (*callback)(ZigbeeFanMode mode)) { + _on_fan_mode_change = callback; + } + +private: + void zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *message) override; + //callback function to be called on fan mode change + void (*_on_fan_mode_change)(ZigbeeFanMode mode); + void fanModeChanged(); + + ZigbeeFanMode _current_fan_mode; + ZigbeeFanModeSequence _current_fan_mode_sequence; +}; + +#endif // CONFIG_ZB_ENABLED From 305299da284c3ff3f71b5482767821443c98bace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 7 Jul 2025 13:33:03 +0200 Subject: [PATCH 2/3] fix(zigbee): Update logs and change device_id --- libraries/Zigbee/src/ep/ZigbeeFanControl.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp index 600df1f63a8..c8a6e2df2d4 100644 --- a/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp @@ -2,7 +2,7 @@ #if CONFIG_ZB_ENABLED ZigbeeFanControl::ZigbeeFanControl(uint8_t endpoint) : ZigbeeEP(endpoint) { - _device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID; + _device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID; //There is no FAN_CONTROL_DEVICE_ID in the Zigbee spec //Create basic analog sensor clusters without configuration _cluster_list = esp_zb_zcl_cluster_list_create(); @@ -26,7 +26,7 @@ bool ZigbeeFanControl::setFanModeSequence(ZigbeeFanModeSequence sequence) { // Set initial fan mode to OFF ret = esp_zb_cluster_update_attr(fan_control_cluster, ESP_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID, (void *)&_current_fan_mode); if (ret != ESP_OK) { - log_e("Failed to set min value: 0x%x: %s", ret, esp_err_to_name(ret)); + log_e("Failed to set fan mode: 0x%x: %s", ret, esp_err_to_name(ret)); return false; } return true; @@ -40,10 +40,10 @@ void ZigbeeFanControl::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t _current_fan_mode = *(ZigbeeFanMode *)message->attribute.data.value; fanModeChanged(); } else { - log_w("Received message ignored. Attribute ID: %d not supported for On/Off Light", message->attribute.id); + log_w("Received message ignored. Attribute ID: %d not supported for Fan Control", message->attribute.id); } } else { - log_w("Received message ignored. Cluster ID: %d not supported for On/Off Light", message->info.cluster); + log_w("Received message ignored. Cluster ID: %d not supported for Fan Control", message->info.cluster); } } @@ -51,7 +51,7 @@ void ZigbeeFanControl::fanModeChanged() { if (_on_fan_mode_change) { _on_fan_mode_change(_current_fan_mode); } else { - log_w("No callback function set for light change"); + log_w("No callback function set for fan mode change"); } } From f76554ffb5ae4789a5c21ac11d3731743fae3ace Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 7 Jul 2025 16:53:58 +0000 Subject: [PATCH 3/3] ci(pre-commit): Apply automatic fixes --- .../Zigbee_Fan_Control/Zigbee_Fan_Control.ino | 16 +++++++--------- libraries/Zigbee/src/ep/ZigbeeFanControl.cpp | 6 ++++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino b/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino index 868aa1f74f9..4c0d15aa563 100644 --- a/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino +++ b/libraries/Zigbee/examples/Zigbee_Fan_Control/Zigbee_Fan_Control.ino @@ -36,7 +36,7 @@ #define ZIGBEE_FAN_CONTROL_ENDPOINT 1 #ifdef RGB_BUILTIN -uint8_t led = RGB_BUILTIN; // To demonstrate the current fan control mode +uint8_t led = RGB_BUILTIN; // To demonstrate the current fan control mode #else uint8_t led = 2; #endif @@ -49,28 +49,26 @@ ZigbeeFanControl zbFanControl = ZigbeeFanControl(ZIGBEE_FAN_CONTROL_ENDPOINT); void setFan(ZigbeeFanMode mode) { switch (mode) { case FAN_MODE_OFF: - rgbLedWrite(led, 0, 0, 0); // Off + rgbLedWrite(led, 0, 0, 0); // Off Serial.println("Fan mode: OFF"); break; case FAN_MODE_LOW: - rgbLedWrite(led, 0, 0, 255); // Blue + rgbLedWrite(led, 0, 0, 255); // Blue Serial.println("Fan mode: LOW"); break; case FAN_MODE_MEDIUM: - rgbLedWrite(led, 255, 255, 0); // Yellow + rgbLedWrite(led, 255, 255, 0); // Yellow Serial.println("Fan mode: MEDIUM"); break; case FAN_MODE_HIGH: - rgbLedWrite(led, 255, 0, 0); // Red + rgbLedWrite(led, 255, 0, 0); // Red Serial.println("Fan mode: HIGH"); break; case FAN_MODE_ON: - rgbLedWrite(led, 255, 255, 255); // White + rgbLedWrite(led, 255, 255, 255); // White Serial.println("Fan mode: ON"); break; - default: - log_e("Unhandled fan mode: %d", mode); - break; + default: log_e("Unhandled fan mode: %d", mode); break; } } diff --git a/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp index c8a6e2df2d4..f4b32ce1200 100644 --- a/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeFanControl.cpp @@ -2,7 +2,7 @@ #if CONFIG_ZB_ENABLED ZigbeeFanControl::ZigbeeFanControl(uint8_t endpoint) : ZigbeeEP(endpoint) { - _device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID; //There is no FAN_CONTROL_DEVICE_ID in the Zigbee spec + _device_id = ESP_ZB_HA_THERMOSTAT_DEVICE_ID; //There is no FAN_CONTROL_DEVICE_ID in the Zigbee spec //Create basic analog sensor clusters without configuration _cluster_list = esp_zb_zcl_cluster_list_create(); @@ -10,7 +10,9 @@ ZigbeeFanControl::ZigbeeFanControl(uint8_t endpoint) : ZigbeeEP(endpoint) { esp_zb_cluster_list_add_identify_cluster(_cluster_list, esp_zb_identify_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); esp_zb_cluster_list_add_fan_control_cluster(_cluster_list, esp_zb_fan_control_cluster_create(NULL), ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); - _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID, .app_device_version = 0}; + _ep_config = { + .endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID, .app_device_version = 0 + }; } bool ZigbeeFanControl::setFanModeSequence(ZigbeeFanModeSequence sequence) {