Skip to content

Commit 85601cb

Browse files
committed
feat(zigbee): Update examples with optional Time cluster
1 parent 580084c commit 85601cb

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
#define TEMP_SENSOR_ENDPOINT_NUMBER 10
3737
uint8_t button = BOOT_PIN;
3838

39+
// Optional Time cluster variables
40+
struct tm timeinfo;
41+
struct tm *localTime;
42+
int32_t timezone;
43+
3944
ZigbeeTempSensor zbTempSensor = ZigbeeTempSensor(TEMP_SENSOR_ENDPOINT_NUMBER);
4045

4146
/************************ Temp sensor *****************************/
@@ -66,6 +71,9 @@ void setup() {
6671
// Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
6772
zbTempSensor.setTolerance(1);
6873

74+
// Optional: Time cluster configuration (default params, as this device will revieve time from coordinator)
75+
zbTempSensor.addTimeCluster();
76+
6977
// Add endpoint to Zigbee Core
7078
Zigbee.addEndpoint(&zbTempSensor);
7179

@@ -85,6 +93,19 @@ void setup() {
8593
}
8694
Serial.println();
8795

96+
// Optional: If time cluster is added, time can be read from the coordinator
97+
timeinfo = zbTempSensor.getTime();
98+
timezone = zbTempSensor.getTimezone();
99+
100+
Serial.println("UTC time:");
101+
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
102+
103+
time_t local = mktime(&timeinfo) + timezone;
104+
localTime = localtime(&local);
105+
106+
Serial.println("Local time with timezone:");
107+
Serial.println(localTime, "%A, %B %d %Y %H:%M:%S");
108+
88109
// Start Temperature sensor reading task
89110
xTaskCreate(temp_sensor_value_update, "temp_sensor_update", 2048, NULL, 10, NULL);
90111

libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ float sensor_max_temp;
4545
float sensor_min_temp;
4646
float sensor_tolerance;
4747

48+
struct tm timeinfo = {}; // Time structure for Time cluster
49+
4850
/****************** Temperature sensor handling *******************/
4951
void recieveSensorTemp(float temperature) {
5052
Serial.printf("Temperature sensor value: %.2f°C\n", temperature);
@@ -71,6 +73,19 @@ void setup() {
7173
//Optional: set Zigbee device name and model
7274
zbThermostat.setManufacturerAndModel("Espressif", "ZigbeeThermostat");
7375

76+
//Optional Time cluster configuration
77+
//example time January 13, 2025 13:30:30 CET
78+
timeinfo.tm_year = 2025 - 1900; // = 2025
79+
timeinfo.tm_mon = 0; // January
80+
timeinfo.tm_mday = 13; // 13th
81+
timeinfo.tm_hour = 12; // 12 hours - 1 hour (CET)
82+
timeinfo.tm_min = 30; // 30 minutes
83+
timeinfo.tm_sec = 30; // 30 seconds
84+
timeinfo.tm_isdst = -1;
85+
86+
// Set time and gmt offset (timezone in seconds -> CET = +3600 seconds)
87+
zbThermostat.addTimeCluster(timeinfo, 3600);
88+
7489
//Add endpoint to Zigbee Core
7590
Zigbee.addEndpoint(&zbThermostat);
7691

0 commit comments

Comments
 (0)