Skip to content

Commit 8cb2659

Browse files
feat(zigbee): Add humidity support for Thermostat + TempSensor fix (#11940)
* feat(zigbee): Add humidity support for Thermostat * docs(zigbee): Update Thermostat APIs * fix(zigbee): Update logs format * ci(pre-commit): Apply automatic fixes --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent a98dad7 commit 8cb2659

File tree

6 files changed

+692
-64
lines changed

6 files changed

+692
-64
lines changed

docs/en/zigbee/ep_thermostat.rst

Lines changed: 222 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ ZigbeeThermostat
55
About
66
-----
77

8-
The ``ZigbeeThermostat`` class provides a thermostat endpoint for Zigbee networks that receives temperature data from temperature sensors. This endpoint implements the Zigbee Home Automation (HA) standard for thermostats that can bind to temperature sensors and receive temperature readings.
8+
The ``ZigbeeThermostat`` class provides a thermostat endpoint for Zigbee networks.
9+
This endpoint implements the Zigbee Home Automation (HA) standard for thermostats that can bind to temperature and humidity sensors and receive temperature and humidity readings.
910

1011
**Features:**
1112
* Automatic discovery and binding to temperature sensors
12-
* Temperature data reception from bound sensors
13-
* Configurable temperature reporting intervals
14-
* Sensor settings retrieval (min/max temperature, tolerance)
13+
* Temperature and humidity data reception from bound sensors
14+
* Configurable temperature and humidity reporting intervals
15+
* Sensor settings retrieval (min/max/tolerance for temperature and humidity)
1516
* Multiple addressing modes (group, specific endpoint, IEEE address)
1617

1718
API Reference
@@ -60,20 +61,60 @@ Sets a callback function for receiving temperature data with source information.
6061
* ``src_endpoint`` - Source endpoint that sent the temperature data
6162
* ``src_address`` - Source address information
6263

63-
onConfigReceive
64-
^^^^^^^^^^^^^^^
64+
onTempConfigReceive
65+
^^^^^^^^^^^^^^^^^^^
6566

6667
Sets a callback function for receiving sensor configuration data.
6768

6869
.. code-block:: arduino
6970
70-
void onConfigReceive(void (*callback)(float min_temp, float max_temp, float tolerance));
71+
void onTempConfigReceive(void (*callback)(float min_temp, float max_temp, float tolerance));
7172
7273
* ``callback`` - Function to call when sensor configuration is received
7374
* ``min_temp`` - Minimum temperature supported by the sensor
7475
* ``max_temp`` - Maximum temperature supported by the sensor
7576
* ``tolerance`` - Temperature tolerance of the sensor
7677

78+
onHumidityReceive
79+
^^^^^^^^^^^^^^^^^
80+
81+
Sets a callback function for receiving humidity data.
82+
83+
.. code-block:: arduino
84+
85+
void onHumidityReceive(void (*callback)(float humidity));
86+
87+
* ``callback`` - Function to call when humidity data is received
88+
* ``humidity`` - Humidity value in percentage
89+
90+
onHumidityReceiveWithSource
91+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
92+
93+
Sets a callback function for receiving humidity data with source information.
94+
95+
.. code-block:: arduino
96+
97+
void onHumidityReceiveWithSource(void (*callback)(float humidity, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address));
98+
99+
* ``callback`` - Function to call when humidity data is received
100+
* ``humidity`` - Humidity value in percentage
101+
* ``src_endpoint`` - Source endpoint that sent the humidity data
102+
* ``src_address`` - Source address information
103+
104+
onHumidityConfigReceive
105+
^^^^^^^^^^^^^^^^^^^^^^^
106+
107+
Sets a callback function for receiving humidity sensor configuration data.
108+
109+
.. code-block:: arduino
110+
111+
void onHumidityConfigReceive(void (*callback)(float min_humidity, float max_humidity, float tolerance));
112+
113+
* ``callback`` - Function to call when humidity sensor configuration is received
114+
* ``min_humidity`` - Minimum humidity supported by the sensor
115+
* ``max_humidity`` - Maximum humidity supported by the sensor
116+
* ``tolerance`` - Humidity tolerance of the sensor
117+
77118
Temperature Data Retrieval
78119
**************************
79120

@@ -98,7 +139,7 @@ Requests temperature data from a specific group.
98139
* ``group_addr`` - Group address to send the request to
99140

100141
getTemperature (Endpoint + Short Address)
101-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
142+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102143

103144
Requests temperature data from a specific endpoint using short address.
104145

@@ -110,7 +151,7 @@ Requests temperature data from a specific endpoint using short address.
110151
* ``short_addr`` - Short address of the target device
111152

112153
getTemperature (Endpoint + IEEE Address)
113-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
154+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114155

115156
Requests temperature data from a specific endpoint using IEEE address.
116157

@@ -121,49 +162,143 @@ Requests temperature data from a specific endpoint using IEEE address.
121162
* ``endpoint`` - Target endpoint number
122163
* ``ieee_addr`` - IEEE address of the target device
123164

124-
Sensor Settings Retrieval
125-
*************************
165+
Humidity Data Retrieval
166+
***********************
126167

127-
getSensorSettings
128-
^^^^^^^^^^^^^^^^^
168+
getHumidity
169+
^^^^^^^^^^^
170+
171+
Requests humidity data from all bound sensors.
172+
173+
.. code-block:: arduino
174+
175+
void getHumidity();
176+
177+
getHumidity (Group)
178+
^^^^^^^^^^^^^^^^^^^
179+
180+
Requests humidity data from a specific group.
181+
182+
.. code-block:: arduino
183+
184+
void getHumidity(uint16_t group_addr);
185+
186+
* ``group_addr`` - Group address to send the request to
187+
188+
getHumidity (Endpoint + Short Address)
189+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
190+
191+
Requests humidity data from a specific endpoint using short address.
192+
193+
.. code-block:: arduino
194+
195+
void getHumidity(uint8_t endpoint, uint16_t short_addr);
196+
197+
* ``endpoint`` - Target endpoint number
198+
* ``short_addr`` - Short address of the target device
199+
200+
getHumidity (Endpoint + IEEE Address)
201+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
202+
203+
Requests humidity data from a specific endpoint using IEEE address.
204+
205+
.. code-block:: arduino
206+
207+
void getHumidity(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);
208+
209+
* ``endpoint`` - Target endpoint number
210+
* ``ieee_addr`` - IEEE address of the target device
211+
212+
Temperature Settings Retrieval
213+
******************************
214+
215+
getTemperatureSettings
216+
^^^^^^^^^^^^^^^^^^^^^^
217+
218+
Requests temperature sensor settings from all bound sensors.
219+
220+
.. code-block:: arduino
221+
222+
void getTemperatureSettings();
223+
224+
getTemperatureSettings (Group)
225+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
226+
227+
Requests temperature sensor settings from a specific group.
129228

130-
Requests sensor settings from all bound sensors.
229+
.. code-block:: arduino
230+
231+
void getTemperatureSettings(uint16_t group_addr);
232+
233+
* ``group_addr`` - Group address to send the request to
234+
235+
getTemperatureSettings (Endpoint + Short Address)
236+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
237+
238+
Requests temperature sensor settings from a specific endpoint using short address.
131239

132240
.. code-block:: arduino
133241
134-
void getSensorSettings();
242+
void getTemperatureSettings(uint8_t endpoint, uint16_t short_addr);
243+
244+
* ``endpoint`` - Target endpoint number
245+
* ``short_addr`` - Short address of the target device
135246

136-
getSensorSettings (Group)
137-
^^^^^^^^^^^^^^^^^^^^^^^^^
247+
getTemperatureSettings (Endpoint + IEEE Address)
248+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
138249

139-
Requests sensor settings from a specific group.
250+
Requests temperature sensor settings from a specific endpoint using IEEE address.
140251

141252
.. code-block:: arduino
142253
143-
void getSensorSettings(uint16_t group_addr);
254+
void getTemperatureSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);
255+
256+
* ``endpoint`` - Target endpoint number
257+
* ``ieee_addr`` - IEEE address of the target device
258+
259+
Humidity Settings Retrieval
260+
***************************
261+
262+
getHumiditySettings
263+
^^^^^^^^^^^^^^^^^^^
264+
265+
Requests humidity sensor settings from all bound sensors.
266+
267+
.. code-block:: arduino
268+
269+
void getHumiditySettings();
270+
271+
getHumiditySettings (Group)
272+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
273+
274+
Requests humidity sensor settings from a specific group.
275+
276+
.. code-block:: arduino
277+
278+
void getHumiditySettings(uint16_t group_addr);
144279
145280
* ``group_addr`` - Group address to send the request to
146281

147-
getSensorSettings (Endpoint + Short Address)
148-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
282+
getHumiditySettings (Endpoint + Short Address)
283+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149284

150-
Requests sensor settings from a specific endpoint using short address.
285+
Requests humidity sensor settings from a specific endpoint using short address.
151286

152287
.. code-block:: arduino
153288
154-
void getSensorSettings(uint8_t endpoint, uint16_t short_addr);
289+
void getHumiditySettings(uint8_t endpoint, uint16_t short_addr);
155290
156291
* ``endpoint`` - Target endpoint number
157292
* ``short_addr`` - Short address of the target device
158293

159-
getSensorSettings (Endpoint + IEEE Address)
160-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
294+
getHumiditySettings (Endpoint + IEEE Address)
295+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161296

162-
Requests sensor settings from a specific endpoint using IEEE address.
297+
Requests humidity sensor settings from a specific endpoint using IEEE address.
163298

164299
.. code-block:: arduino
165300
166-
void getSensorSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);
301+
void getHumiditySettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);
167302
168303
* ``endpoint`` - Target endpoint number
169304
* ``ieee_addr`` - IEEE address of the target device
@@ -228,6 +363,66 @@ Configures temperature reporting for a specific endpoint using IEEE address.
228363
* ``max_interval`` - Maximum reporting interval in seconds
229364
* ``delta`` - Minimum change in temperature to trigger a report
230365

366+
Humidity Reporting Configuration
367+
********************************
368+
369+
setHumidityReporting
370+
^^^^^^^^^^^^^^^^^^^^
371+
372+
Configures humidity reporting for all bound sensors.
373+
374+
.. code-block:: arduino
375+
376+
void setHumidityReporting(uint16_t min_interval, uint16_t max_interval, float delta);
377+
378+
* ``min_interval`` - Minimum reporting interval in seconds
379+
* ``max_interval`` - Maximum reporting interval in seconds
380+
* ``delta`` - Minimum change in humidity to trigger a report
381+
382+
setHumidityReporting (Group)
383+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
384+
385+
Configures humidity reporting for a specific group.
386+
387+
.. code-block:: arduino
388+
389+
void setHumidityReporting(uint16_t group_addr, uint16_t min_interval, uint16_t max_interval, float delta);
390+
391+
* ``group_addr`` - Group address to configure
392+
* ``min_interval`` - Minimum reporting interval in seconds
393+
* ``max_interval`` - Maximum reporting interval in seconds
394+
* ``delta`` - Minimum change in humidity to trigger a report
395+
396+
setHumidityReporting (Endpoint + Short Address)
397+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
398+
399+
Configures humidity reporting for a specific endpoint using short address.
400+
401+
.. code-block:: arduino
402+
403+
void setHumidityReporting(uint8_t endpoint, uint16_t short_addr, uint16_t min_interval, uint16_t max_interval, float delta);
404+
405+
* ``endpoint`` - Target endpoint number
406+
* ``short_addr`` - Short address of the target device
407+
* ``min_interval`` - Minimum reporting interval in seconds
408+
* ``max_interval`` - Maximum reporting interval in seconds
409+
* ``delta`` - Minimum change in humidity to trigger a report
410+
411+
setHumidityReporting (Endpoint + IEEE Address)
412+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
413+
414+
Configures humidity reporting for a specific endpoint using IEEE address.
415+
416+
.. code-block:: arduino
417+
418+
void setHumidityReporting(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr, uint16_t min_interval, uint16_t max_interval, float delta);
419+
420+
* ``endpoint`` - Target endpoint number
421+
* ``ieee_addr`` - IEEE address of the target device
422+
* ``min_interval`` - Minimum reporting interval in seconds
423+
* ``max_interval`` - Maximum reporting interval in seconds
424+
* ``delta`` - Minimum change in humidity to trigger a report
425+
231426
Example
232427
-------
233428

libraries/Zigbee/examples/Zigbee_Thermostat/Zigbee_Thermostat.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void setup() {
9090
#endif
9191

9292
// Set callback function for receiving sensor configuration
93-
zbThermostat.onConfigReceive(receiveSensorConfig);
93+
zbThermostat.onTempConfigReceive(receiveSensorConfig);
9494

9595
//Optional: set Zigbee device name and model
9696
zbThermostat.setManufacturerAndModel("Espressif", "ZigbeeThermostat");
@@ -138,10 +138,10 @@ void setup() {
138138
"Device on endpoint %d, IEEE Address: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\r\n", device->endpoint, device->ieee_addr[7], device->ieee_addr[6],
139139
device->ieee_addr[5], device->ieee_addr[4], device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]
140140
);
141-
zbThermostat.getSensorSettings(device->endpoint, device->ieee_addr);
141+
zbThermostat.getTemperatureSettings(device->endpoint, device->ieee_addr);
142142
} else {
143143
Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr);
144-
zbThermostat.getSensorSettings(device->endpoint, device->short_addr);
144+
zbThermostat.getTemperatureSettings(device->endpoint, device->short_addr);
145145
}
146146
}
147147
}

libraries/Zigbee/keywords.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,17 @@ onLightColorChangeWithSource KEYWORD2
142142

143143
# ZigbeeThermostat
144144
onTempRecieve KEYWORD2
145-
onConfigRecieve KEYWORD2
146145
onTempReceiveWithSource KEYWORD2
146+
onTempConfigReceive KEYWORD2
147147
getTemperature KEYWORD2
148-
getSensorSettings KEYWORD2
148+
getTemperatureSettings KEYWORD2
149149
setTemperatureReporting KEYWORD2
150+
onHumidityReceive KEYWORD2
151+
onHumidityReceiveWithSource KEYWORD2
152+
onHumidityConfigReceive KEYWORD2
153+
getHumidity KEYWORD2
154+
getHumiditySettings KEYWORD2
155+
setHumidityReporting KEYWORD2
150156

151157
# Common Zigbee Sensor
152158
setMinMaxValue KEYWORD2

libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ bool ZigbeeTempSensor::reportTemperature() {
127127
}
128128

129129
void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance) {
130-
int16_t zb_min = zb_float_to_s16(min);
131-
int16_t zb_max = zb_float_to_s16(max);
130+
uint16_t zb_min = (uint16_t)(min * 100);
131+
uint16_t zb_max = (uint16_t)(max * 100);
132132
uint16_t zb_tolerance = (uint16_t)(tolerance * 100);
133-
int16_t default_hum = ESP_ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_DEFAULT;
133+
uint16_t default_hum = ESP_ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_DEFAULT;
134134
esp_zb_attribute_list_t *humidity_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT);
135135
esp_zb_humidity_meas_cluster_add_attr(humidity_cluster, ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID, &default_hum);
136136
esp_zb_humidity_meas_cluster_add_attr(humidity_cluster, ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID, &zb_min);
@@ -142,7 +142,7 @@ void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance)
142142

143143
bool ZigbeeTempSensor::setHumidity(float humidity) {
144144
esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
145-
int16_t zb_humidity = zb_float_to_s16(humidity);
145+
uint16_t zb_humidity = (uint16_t)(humidity * 100);
146146
log_v("Updating humidity sensor value...");
147147
/* Update humidity sensor measured value */
148148
log_d("Setting humidity to %d", zb_humidity);

0 commit comments

Comments
 (0)