Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
249 changes: 222 additions & 27 deletions docs/en/zigbee/ep_thermostat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ ZigbeeThermostat
About
-----

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.
The ``ZigbeeThermostat`` class provides a thermostat endpoint for Zigbee networks.
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.

**Features:**
* Automatic discovery and binding to temperature sensors
* Temperature data reception from bound sensors
* Configurable temperature reporting intervals
* Sensor settings retrieval (min/max temperature, tolerance)
* Temperature and humidity data reception from bound sensors
* Configurable temperature and humidity reporting intervals
* Sensor settings retrieval (min/max/tolerance for temperature and humidity)
* Multiple addressing modes (group, specific endpoint, IEEE address)

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

onConfigReceive
^^^^^^^^^^^^^^^
onTempConfigReceive
^^^^^^^^^^^^^^^^^^^

Sets a callback function for receiving sensor configuration data.

.. code-block:: arduino

void onConfigReceive(void (*callback)(float min_temp, float max_temp, float tolerance));
void onTempConfigReceive(void (*callback)(float min_temp, float max_temp, float tolerance));

* ``callback`` - Function to call when sensor configuration is received
* ``min_temp`` - Minimum temperature supported by the sensor
* ``max_temp`` - Maximum temperature supported by the sensor
* ``tolerance`` - Temperature tolerance of the sensor

onHumidityReceive
^^^^^^^^^^^^^^^^^

Sets a callback function for receiving humidity data.

.. code-block:: arduino

void onHumidityReceive(void (*callback)(float humidity));

* ``callback`` - Function to call when humidity data is received
* ``humidity`` - Humidity value in percentage

onHumidityReceiveWithSource
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Sets a callback function for receiving humidity data with source information.

.. code-block:: arduino

void onHumidityReceiveWithSource(void (*callback)(float humidity, uint8_t src_endpoint, esp_zb_zcl_addr_t src_address));

* ``callback`` - Function to call when humidity data is received
* ``humidity`` - Humidity value in percentage
* ``src_endpoint`` - Source endpoint that sent the humidity data
* ``src_address`` - Source address information

onHumidityConfigReceive
^^^^^^^^^^^^^^^^^^^^^^^

Sets a callback function for receiving humidity sensor configuration data.

.. code-block:: arduino

void onHumidityConfigReceive(void (*callback)(float min_humidity, float max_humidity, float tolerance));

* ``callback`` - Function to call when humidity sensor configuration is received
* ``min_humidity`` - Minimum humidity supported by the sensor
* ``max_humidity`` - Maximum humidity supported by the sensor
* ``tolerance`` - Humidity tolerance of the sensor

Temperature Data Retrieval
**************************

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

getTemperature (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests temperature data from a specific endpoint using short address.

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

getTemperature (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests temperature data from a specific endpoint using IEEE address.

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

Sensor Settings Retrieval
*************************
Humidity Data Retrieval
***********************

getSensorSettings
^^^^^^^^^^^^^^^^^
getHumidity
^^^^^^^^^^^

Requests humidity data from all bound sensors.

.. code-block:: arduino

void getHumidity();

getHumidity (Group)
^^^^^^^^^^^^^^^^^^^

Requests humidity data from a specific group.

.. code-block:: arduino

void getHumidity(uint16_t group_addr);

* ``group_addr`` - Group address to send the request to

getHumidity (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests humidity data from a specific endpoint using short address.

.. code-block:: arduino

void getHumidity(uint8_t endpoint, uint16_t short_addr);

* ``endpoint`` - Target endpoint number
* ``short_addr`` - Short address of the target device

getHumidity (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests humidity data from a specific endpoint using IEEE address.

.. code-block:: arduino

void getHumidity(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);

* ``endpoint`` - Target endpoint number
* ``ieee_addr`` - IEEE address of the target device

Temperature Settings Retrieval
******************************

getTemperatureSettings
^^^^^^^^^^^^^^^^^^^^^^

Requests temperature sensor settings from all bound sensors.

.. code-block:: arduino

void getTemperatureSettings();

getTemperatureSettings (Group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests temperature sensor settings from a specific group.

Requests sensor settings from all bound sensors.
.. code-block:: arduino

void getTemperatureSettings(uint16_t group_addr);

* ``group_addr`` - Group address to send the request to

getTemperatureSettings (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests temperature sensor settings from a specific endpoint using short address.

.. code-block:: arduino

void getSensorSettings();
void getTemperatureSettings(uint8_t endpoint, uint16_t short_addr);

* ``endpoint`` - Target endpoint number
* ``short_addr`` - Short address of the target device

getTemperatureSettings (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests temperature sensor settings from a specific endpoint using IEEE address.

.. code-block:: arduino

void getTemperatureSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);

* ``endpoint`` - Target endpoint number
* ``ieee_addr`` - IEEE address of the target device

Humidity Settings Retrieval
***************************

getHumiditySettings
^^^^^^^^^^^^^^^^^^^

getSensorSettings (Group)
^^^^^^^^^^^^^^^^^^^^^^^^^
Requests humidity sensor settings from all bound sensors.

Requests sensor settings from a specific group.
.. code-block:: arduino

void getHumiditySettings();

getHumiditySettings (Group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests humidity sensor settings from a specific group.

.. code-block:: arduino

void getSensorSettings(uint16_t group_addr);
void getHumiditySettings(uint16_t group_addr);

* ``group_addr`` - Group address to send the request to

getSensorSettings (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
getHumiditySettings (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests sensor settings from a specific endpoint using short address.
Requests humidity sensor settings from a specific endpoint using short address.

.. code-block:: arduino

void getSensorSettings(uint8_t endpoint, uint16_t short_addr);
void getHumiditySettings(uint8_t endpoint, uint16_t short_addr);

* ``endpoint`` - Target endpoint number
* ``short_addr`` - Short address of the target device

getSensorSettings (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
getHumiditySettings (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Requests sensor settings from a specific endpoint using IEEE address.
Requests humidity sensor settings from a specific endpoint using IEEE address.

.. code-block:: arduino

void getSensorSettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);
void getHumiditySettings(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr);

* ``endpoint`` - Target endpoint number
* ``ieee_addr`` - IEEE address of the target device
Expand Down Expand Up @@ -228,6 +363,66 @@ Configures temperature reporting for a specific endpoint using IEEE address.
* ``max_interval`` - Maximum reporting interval in seconds
* ``delta`` - Minimum change in temperature to trigger a report

Humidity Reporting Configuration
********************************

setHumidityReporting
^^^^^^^^^^^^^^^^^^^^

Configures humidity reporting for all bound sensors.

.. code-block:: arduino

void setHumidityReporting(uint16_t min_interval, uint16_t max_interval, float delta);

* ``min_interval`` - Minimum reporting interval in seconds
* ``max_interval`` - Maximum reporting interval in seconds
* ``delta`` - Minimum change in humidity to trigger a report

setHumidityReporting (Group)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Configures humidity reporting for a specific group.

.. code-block:: arduino

void setHumidityReporting(uint16_t group_addr, uint16_t min_interval, uint16_t max_interval, float delta);

* ``group_addr`` - Group address to configure
* ``min_interval`` - Minimum reporting interval in seconds
* ``max_interval`` - Maximum reporting interval in seconds
* ``delta`` - Minimum change in humidity to trigger a report

setHumidityReporting (Endpoint + Short Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Configures humidity reporting for a specific endpoint using short address.

.. code-block:: arduino

void setHumidityReporting(uint8_t endpoint, uint16_t short_addr, uint16_t min_interval, uint16_t max_interval, float delta);

* ``endpoint`` - Target endpoint number
* ``short_addr`` - Short address of the target device
* ``min_interval`` - Minimum reporting interval in seconds
* ``max_interval`` - Maximum reporting interval in seconds
* ``delta`` - Minimum change in humidity to trigger a report

setHumidityReporting (Endpoint + IEEE Address)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Configures humidity reporting for a specific endpoint using IEEE address.

.. code-block:: arduino

void setHumidityReporting(uint8_t endpoint, esp_zb_ieee_addr_t ieee_addr, uint16_t min_interval, uint16_t max_interval, float delta);

* ``endpoint`` - Target endpoint number
* ``ieee_addr`` - IEEE address of the target device
* ``min_interval`` - Minimum reporting interval in seconds
* ``max_interval`` - Maximum reporting interval in seconds
* ``delta`` - Minimum change in humidity to trigger a report

Example
-------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void setup() {
#endif

// Set callback function for receiving sensor configuration
zbThermostat.onConfigReceive(receiveSensorConfig);
zbThermostat.onTempConfigReceive(receiveSensorConfig);

//Optional: set Zigbee device name and model
zbThermostat.setManufacturerAndModel("Espressif", "ZigbeeThermostat");
Expand Down Expand Up @@ -138,10 +138,10 @@ void setup() {
"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],
device->ieee_addr[5], device->ieee_addr[4], device->ieee_addr[3], device->ieee_addr[2], device->ieee_addr[1], device->ieee_addr[0]
);
zbThermostat.getSensorSettings(device->endpoint, device->ieee_addr);
zbThermostat.getTemperatureSettings(device->endpoint, device->ieee_addr);
} else {
Serial.printf("Device on endpoint %d, short address: 0x%x\r\n", device->endpoint, device->short_addr);
zbThermostat.getSensorSettings(device->endpoint, device->short_addr);
zbThermostat.getTemperatureSettings(device->endpoint, device->short_addr);
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions libraries/Zigbee/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,17 @@ onLightColorChangeWithSource KEYWORD2

# ZigbeeThermostat
onTempRecieve KEYWORD2
onConfigRecieve KEYWORD2
onTempReceiveWithSource KEYWORD2
onTempConfigReceive KEYWORD2
getTemperature KEYWORD2
getSensorSettings KEYWORD2
getTemperatureSettings KEYWORD2
setTemperatureReporting KEYWORD2
onHumidityReceive KEYWORD2
onHumidityReceiveWithSource KEYWORD2
onHumidityConfigReceive KEYWORD2
getHumidity KEYWORD2
getHumiditySettings KEYWORD2
setHumidityReporting KEYWORD2

# Common Zigbee Sensor
setMinMaxValue KEYWORD2
Expand Down
8 changes: 4 additions & 4 deletions libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ bool ZigbeeTempSensor::reportTemperature() {
}

void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance) {
int16_t zb_min = zb_float_to_s16(min);
int16_t zb_max = zb_float_to_s16(max);
uint16_t zb_min = (uint16_t)(min * 100);
uint16_t zb_max = (uint16_t)(max * 100);
uint16_t zb_tolerance = (uint16_t)(tolerance * 100);
int16_t default_hum = ESP_ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_DEFAULT;
uint16_t default_hum = ESP_ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_DEFAULT;
esp_zb_attribute_list_t *humidity_cluster = esp_zb_zcl_attr_list_create(ESP_ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT);
esp_zb_humidity_meas_cluster_add_attr(humidity_cluster, ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID, &default_hum);
esp_zb_humidity_meas_cluster_add_attr(humidity_cluster, ESP_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID, &zb_min);
Expand All @@ -142,7 +142,7 @@ void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance)

bool ZigbeeTempSensor::setHumidity(float humidity) {
esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
int16_t zb_humidity = zb_float_to_s16(humidity);
uint16_t zb_humidity = (uint16_t)(humidity * 100);
log_v("Updating humidity sensor value...");
/* Update humidity sensor measured value */
log_d("Setting humidity to %d", zb_humidity);
Expand Down
Loading
Loading