diff --git a/docs/en/zigbee/ep_carbon_dioxide_sensor.rst b/docs/en/zigbee/ep_carbon_dioxide_sensor.rst index 6f219a16fd0..d595fda8e1f 100644 --- a/docs/en/zigbee/ep_carbon_dioxide_sensor.rst +++ b/docs/en/zigbee/ep_carbon_dioxide_sensor.rst @@ -54,6 +54,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the carbon dioxide sensor in ppm. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(float defaultValue); + +* ``defaultValue`` - Default CO2 concentration value in ppm + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_flow_sensor.rst b/docs/en/zigbee/ep_flow_sensor.rst index 9423f321a5d..95c3b5c72c4 100644 --- a/docs/en/zigbee/ep_flow_sensor.rst +++ b/docs/en/zigbee/ep_flow_sensor.rst @@ -70,6 +70,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the flow sensor in 0.1 m³/h. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(float defaultValue); + +* ``defaultValue`` - Default flow rate value in 0.1 m³/h + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_illuminance_sensor.rst b/docs/en/zigbee/ep_illuminance_sensor.rst index 1e627f7dfe9..73b676e3f52 100644 --- a/docs/en/zigbee/ep_illuminance_sensor.rst +++ b/docs/en/zigbee/ep_illuminance_sensor.rst @@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the illuminance sensor. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(uint16_t defaultValue); + +* ``defaultValue`` - Default illuminance value in lux + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_pm25_sensor.rst b/docs/en/zigbee/ep_pm25_sensor.rst index 2f1432f8224..feac3c54e66 100644 --- a/docs/en/zigbee/ep_pm25_sensor.rst +++ b/docs/en/zigbee/ep_pm25_sensor.rst @@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the PM2.5 sensor in 0.1 μg/m³. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(float defaultValue); + +* ``defaultValue`` - Default PM2.5 concentration value in 0.1 μg/m³ + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_pressure_sensor.rst b/docs/en/zigbee/ep_pressure_sensor.rst index 5d857bb163e..b8a5fbeb18d 100644 --- a/docs/en/zigbee/ep_pressure_sensor.rst +++ b/docs/en/zigbee/ep_pressure_sensor.rst @@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the pressure sensor in 1 hPa. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(int16_t defaultValue); + +* ``defaultValue`` - Default pressure value in hPa + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_temperature_sensor.rst b/docs/en/zigbee/ep_temperature_sensor.rst index 85c2147f1a1..f14082d59f0 100644 --- a/docs/en/zigbee/ep_temperature_sensor.rst +++ b/docs/en/zigbee/ep_temperature_sensor.rst @@ -60,6 +60,21 @@ Sets the minimum and maximum temperature values for the sensor. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the temperature sensor in 0.01°C resolution. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(float defaultValue); + +* ``defaultValue`` - Default temperature value in degrees Celsius + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/docs/en/zigbee/ep_wind_speed_sensor.rst b/docs/en/zigbee/ep_wind_speed_sensor.rst index 67c4958e37c..7b294674e89 100644 --- a/docs/en/zigbee/ep_wind_speed_sensor.rst +++ b/docs/en/zigbee/ep_wind_speed_sensor.rst @@ -70,6 +70,21 @@ Sets the minimum and maximum measurement values. This function will return ``true`` if successful, ``false`` otherwise. +setDefaultValue +^^^^^^^^^^^^^^^ + +Sets the default (initial) value for the wind speed sensor in 0.01 m/s. This value will be used as the initial measured value when the device is in factory reset mode and before the sensor provides actual readings. + +.. code-block:: arduino + + bool setDefaultValue(float defaultValue); + +* ``defaultValue`` - Default wind speed value in 0.01 m/s + +**Important:** Must be called before adding the EP to Zigbee class. Only effective when the device is in factory reset mode (before commissioning/joining a network). + +This function will return ``true`` if successful, ``false`` otherwise. + setTolerance ^^^^^^^^^^^^ diff --git a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino index 54c085fbfea..401c4ab4552 100644 --- a/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino +++ b/libraries/Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy/Zigbee_Temp_Hum_Sensor_Sleepy.ino @@ -135,6 +135,9 @@ void setup() { // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement) zbTempSensor.setMinMaxValue(10, 50); + // Set default (initial) value for the temperature sensor to 10.0°C to match the minimum temperature measurement value (default value is 0.0°C) + zbTempSensor.setDefaultValue(10.0); + // Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C) zbTempSensor.setTolerance(1); @@ -142,8 +145,8 @@ void setup() { // The value can be also updated by calling zbTempSensor.setBatteryPercentage(percentage) or zbTempSensor.setBatteryVoltage(voltage) anytime after Zigbee.begin() zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100, 35); - // Add humidity cluster to the temperature sensor device with min, max and tolerance values - zbTempSensor.addHumiditySensor(0, 100, 1); + // Add humidity cluster to the temperature sensor device with min, max, tolerance and default values + zbTempSensor.addHumiditySensor(0, 100, 1, 0.0); // Set callback for default response to handle status of reported data, there are 2 options. diff --git a/libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino b/libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino index ad007abbbaa..e7f4721b47d 100644 --- a/libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino +++ b/libraries/Zigbee/examples/Zigbee_Temperature_Sensor/Zigbee_Temperature_Sensor.ino @@ -68,6 +68,9 @@ void setup() { // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement) zbTempSensor.setMinMaxValue(10, 50); + // Optional: Set default (initial) value for the temperature sensor to 10.0°C to match the minimum temperature measurement value + zbTempSensor.setDefaultValue(10.0); + // Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C) zbTempSensor.setTolerance(1); diff --git a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp index 225bb620f0b..711dd1e6879 100644 --- a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp @@ -38,6 +38,19 @@ ZigbeeCarbonDioxideSensor::ZigbeeCarbonDioxideSensor(uint8_t endpoint) : ZigbeeE _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; } +bool ZigbeeCarbonDioxideSensor::setDefaultValue(float defaultValue) { + float zb_default_value = defaultValue / 1000000.0f; + esp_zb_attribute_list_t *carbon_dioxide_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = + esp_zb_cluster_update_attr(carbon_dioxide_measure_cluster, ESP_ZB_ZCL_ATTR_CARBON_DIOXIDE_MEASUREMENT_MEASURED_VALUE_ID, (void *)&zb_default_value); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeCarbonDioxideSensor::setMinMaxValue(float min, float max) { float zb_min = min / 1000000.0f; float zb_max = max / 1000000.0f; diff --git a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.h b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.h index bd64e50e51e..2d6a87d946b 100644 --- a/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.h @@ -58,6 +58,10 @@ class ZigbeeCarbonDioxideSensor : public ZigbeeEP { // Set the carbon dioxide value in ppm bool setCarbonDioxide(float carbon_dioxide); + // Set the default (initial) value for the carbon dioxide sensor in ppm + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(float defaultValue); + // Set the min and max value for the carbon dioxide sensor in ppm bool setMinMaxValue(float min, float max); diff --git a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp index ddaee3ea88f..a946f7ad720 100644 --- a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp @@ -36,6 +36,18 @@ ZigbeeFlowSensor::ZigbeeFlowSensor(uint8_t endpoint) : ZigbeeEP(endpoint) { _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; } +bool ZigbeeFlowSensor::setDefaultValue(float defaultValue) { + uint16_t zb_default_value = (uint16_t)(defaultValue * 10); + esp_zb_attribute_list_t *flow_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_FLOW_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_VALUE_ID, (void *)&zb_default_value); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeFlowSensor::setMinMaxValue(float min, float max) { uint16_t zb_min = (uint16_t)(min * 10); uint16_t zb_max = (uint16_t)(max * 10); diff --git a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.h b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.h index 0402dd15377..0bc7b767bfe 100644 --- a/libraries/Zigbee/src/ep/ZigbeeFlowSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeeFlowSensor.h @@ -58,6 +58,10 @@ class ZigbeeFlowSensor : public ZigbeeEP { // Set the flow value in 0,1 m3/h bool setFlow(float value); + // Set the default (initial) value for the flow sensor in 0,1 m3/h + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(float defaultValue); + // Set the min and max value for the flow sensor in 0,1 m3/h bool setMinMaxValue(float min, float max); diff --git a/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp index a2a6d364f9d..351dbbac182 100644 --- a/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.cpp @@ -24,6 +24,17 @@ ZigbeeIlluminanceSensor::ZigbeeIlluminanceSensor(uint8_t endpoint) : ZigbeeEP(en _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_LIGHT_SENSOR_DEVICE_ID, .app_device_version = 0}; } +bool ZigbeeIlluminanceSensor::setDefaultValue(uint16_t defaultValue) { + esp_zb_attribute_list_t *light_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(light_measure_cluster, ESP_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID, (void *)&defaultValue); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeIlluminanceSensor::setMinMaxValue(uint16_t min, uint16_t max) { esp_zb_attribute_list_t *light_measure_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); diff --git a/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h b/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h index fdc369b4a55..5ae36b0c890 100644 --- a/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeeIlluminanceSensor.h @@ -49,6 +49,10 @@ class ZigbeeIlluminanceSensor : public ZigbeeEP { // Set the illuminance value bool setIlluminance(uint16_t value); + // Set the default (initial) value for the illuminance sensor + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(uint16_t defaultValue); + // Set the min and max value for the illuminance sensor bool setMinMaxValue(uint16_t min, uint16_t max); diff --git a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp index fc2ca820c9a..ab3f47d81bf 100644 --- a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.cpp @@ -36,6 +36,17 @@ ZigbeePM25Sensor::ZigbeePM25Sensor(uint8_t endpoint) : ZigbeeEP(endpoint) { _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; } +bool ZigbeePM25Sensor::setDefaultValue(float defaultValue) { + esp_zb_attribute_list_t *pm2_5_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(pm2_5_measure_cluster, ESP_ZB_ZCL_ATTR_PM2_5_MEASUREMENT_MEASURED_VALUE_ID, (void *)&defaultValue); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeePM25Sensor::setMinMaxValue(float min, float max) { esp_zb_attribute_list_t *pm2_5_measure_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PM2_5_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); diff --git a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h index e4b47574704..967ccdca167 100644 --- a/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h +++ b/libraries/Zigbee/src/ep/ZigbeePM25Sensor.h @@ -58,6 +58,10 @@ class ZigbeePM25Sensor : public ZigbeeEP { // Set the PM2.5 value in 0.1 µg/m³ bool setPM25(float pm25); + // Set the default (initial) value for the PM2.5 sensor in 0.1 µg/m³ + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(float defaultValue); + // Set the min and max value for the PM2.5 sensor in 0.1 µg/m³ bool setMinMaxValue(float min, float max); diff --git a/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp b/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp index 4fdf8600fbe..da356334965 100644 --- a/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeePressureSensor.cpp @@ -36,6 +36,17 @@ ZigbeePressureSensor::ZigbeePressureSensor(uint8_t endpoint) : ZigbeeEP(endpoint _ep_config = {.endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_SIMPLE_SENSOR_DEVICE_ID, .app_device_version = 0}; } +bool ZigbeePressureSensor::setDefaultValue(int16_t defaultValue) { + esp_zb_attribute_list_t *pressure_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(pressure_measure_cluster, ESP_ZB_ZCL_ATTR_PRESSURE_MEASUREMENT_VALUE_ID, (void *)&defaultValue); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeePressureSensor::setMinMaxValue(int16_t min, int16_t max) { esp_zb_attribute_list_t *pressure_measure_cluster = esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); diff --git a/libraries/Zigbee/src/ep/ZigbeePressureSensor.h b/libraries/Zigbee/src/ep/ZigbeePressureSensor.h index cd38a24d4a0..930846c8721 100644 --- a/libraries/Zigbee/src/ep/ZigbeePressureSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeePressureSensor.h @@ -58,6 +58,10 @@ class ZigbeePressureSensor : public ZigbeeEP { // Set the pressure value in 1 hPa bool setPressure(int16_t value); + // Set the default (initial) value for the pressure sensor in 1 hPa + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(int16_t defaultValue); + // Set the min and max value for the pressure sensor in 1 hPa bool setMinMaxValue(int16_t min, int16_t max); diff --git a/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp index 484506e139d..79b39b14c56 100644 --- a/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeTempSensor.cpp @@ -22,6 +22,9 @@ ZigbeeTempSensor::ZigbeeTempSensor(uint8_t endpoint) : ZigbeeEP(endpoint) { esp_zb_temperature_sensor_cfg_t temp_sensor_cfg = ESP_ZB_DEFAULT_TEMPERATURE_SENSOR_CONFIG(); _cluster_list = esp_zb_temperature_sensor_clusters_create(&temp_sensor_cfg); + // Set default (initial) value for the temperature sensor to 0.0°C + setDefaultValue(0.0); + _ep_config = { .endpoint = _endpoint, .app_profile_id = ESP_ZB_AF_HA_PROFILE_ID, .app_device_id = ESP_ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID, .app_device_version = 0 }; @@ -49,6 +52,18 @@ bool ZigbeeTempSensor::setMinMaxValue(float min, float max) { return true; } +bool ZigbeeTempSensor::setDefaultValue(float defaultValue) { + int16_t zb_default_value = zb_float_to_s16(defaultValue); + esp_zb_attribute_list_t *temp_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(temp_measure_cluster, ESP_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, (void *)&zb_default_value); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeTempSensor::setTolerance(float tolerance) { // Convert tolerance to ZCL uint16_t uint16_t zb_tolerance = (uint16_t)(tolerance * 100); @@ -126,11 +141,11 @@ bool ZigbeeTempSensor::reportTemperature() { return true; } -void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance) { +void ZigbeeTempSensor::addHumiditySensor(float min, float max, float tolerance, float defaultValue) { uint16_t zb_min = (uint16_t)(min * 100); uint16_t zb_max = (uint16_t)(max * 100); uint16_t zb_tolerance = (uint16_t)(tolerance * 100); - uint16_t default_hum = ESP_ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MEASURED_VALUE_DEFAULT; + uint16_t default_hum = (uint16_t)(defaultValue * 100); 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); diff --git a/libraries/Zigbee/src/ep/ZigbeeTempSensor.h b/libraries/Zigbee/src/ep/ZigbeeTempSensor.h index e7219c17335..edc8812d5ae 100644 --- a/libraries/Zigbee/src/ep/ZigbeeTempSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeeTempSensor.h @@ -31,6 +31,10 @@ class ZigbeeTempSensor : public ZigbeeEP { // Set the temperature value in 0,01°C bool setTemperature(float value); + // Set the default (initial) value for the temperature sensor in 0,01°C + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(float defaultValue); + // Set the min and max value for the temperature sensor in 0,01°C bool setMinMaxValue(float min, float max); @@ -44,7 +48,7 @@ class ZigbeeTempSensor : public ZigbeeEP { bool reportTemperature(); // Add humidity cluster to the temperature sensor device - void addHumiditySensor(float min, float max, float tolerance); + void addHumiditySensor(float min = 0.0, float max = 100.0, float tolerance = 0.1, float defaultValue = 0.0); // Set the humidity value in 0,01% bool setHumidity(float value); diff --git a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp index 672b6254017..85e7efa655d 100644 --- a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp +++ b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.cpp @@ -42,6 +42,18 @@ static uint16_t zb_windspeed_to_u16(float windspeed) { return (uint16_t)(windspeed * 100); } +bool ZigbeeWindSpeedSensor::setDefaultValue(float defaultValue) { + uint16_t zb_default_value = zb_windspeed_to_u16(defaultValue); + esp_zb_attribute_list_t *windspeed_measure_cluster = + esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_WIND_SPEED_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE); + esp_err_t ret = esp_zb_cluster_update_attr(windspeed_measure_cluster, ESP_ZB_ZCL_ATTR_WIND_SPEED_MEASUREMENT_MEASURED_VALUE_ID, (void *)&zb_default_value); + if (ret != ESP_OK) { + log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret)); + return false; + } + return true; +} + bool ZigbeeWindSpeedSensor::setMinMaxValue(float min, float max) { uint16_t zb_min = zb_windspeed_to_u16(min); uint16_t zb_max = zb_windspeed_to_u16(max); diff --git a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h index b5371f8fdef..011cb5e663c 100644 --- a/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h +++ b/libraries/Zigbee/src/ep/ZigbeeWindSpeedSensor.h @@ -56,6 +56,10 @@ class ZigbeeWindSpeedSensor : public ZigbeeEP { // Set the WindSpeed value in 0,01 m/s bool setWindSpeed(float value); + // Set the default (initial) value for the wind speed sensor in 0,01 m/s + // Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning) + bool setDefaultValue(float defaultValue); + // Set the min and max value for the WindSpeed sensor bool setMinMaxValue(float min, float max);