Skip to content

Commit e41c6a9

Browse files
committed
feat(zigbee): Add option to set initial (default) value
1 parent a048db0 commit e41c6a9

21 files changed

+220
-3
lines changed

docs/en/zigbee/ep_carbon_dioxide_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ Sets the minimum and maximum measurement values.
5454

5555
This function will return ``true`` if successful, ``false`` otherwise.
5656

57+
setDefaultValue
58+
^^^^^^^^^^^^^^^
59+
60+
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.
61+
62+
.. code-block:: arduino
63+
64+
bool setDefaultValue(float defaultValue);
65+
66+
* ``defaultValue`` - Default CO2 concentration value in ppm
67+
68+
**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).
69+
70+
This function will return ``true`` if successful, ``false`` otherwise.
71+
5772
setTolerance
5873
^^^^^^^^^^^^
5974

docs/en/zigbee/ep_flow_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ Sets the minimum and maximum measurement values.
7070

7171
This function will return ``true`` if successful, ``false`` otherwise.
7272

73+
setDefaultValue
74+
^^^^^^^^^^^^^^^
75+
76+
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.
77+
78+
.. code-block:: arduino
79+
80+
bool setDefaultValue(float defaultValue);
81+
82+
* ``defaultValue`` - Default flow rate value in 0.1 m³/h
83+
84+
**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).
85+
86+
This function will return ``true`` if successful, ``false`` otherwise.
87+
7388
setTolerance
7489
^^^^^^^^^^^^
7590

docs/en/zigbee/ep_illuminance_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values.
6060

6161
This function will return ``true`` if successful, ``false`` otherwise.
6262

63+
setDefaultValue
64+
^^^^^^^^^^^^^^^
65+
66+
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.
67+
68+
.. code-block:: arduino
69+
70+
bool setDefaultValue(uint16_t defaultValue);
71+
72+
* ``defaultValue`` - Default illuminance value in lux
73+
74+
**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).
75+
76+
This function will return ``true`` if successful, ``false`` otherwise.
77+
6378
setTolerance
6479
^^^^^^^^^^^^
6580

docs/en/zigbee/ep_pm25_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values.
6060

6161
This function will return ``true`` if successful, ``false`` otherwise.
6262

63+
setDefaultValue
64+
^^^^^^^^^^^^^^^
65+
66+
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.
67+
68+
.. code-block:: arduino
69+
70+
bool setDefaultValue(float defaultValue);
71+
72+
* ``defaultValue`` - Default PM2.5 concentration value in 0.1 μg/m³
73+
74+
**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).
75+
76+
This function will return ``true`` if successful, ``false`` otherwise.
77+
6378
setTolerance
6479
^^^^^^^^^^^^
6580

docs/en/zigbee/ep_pressure_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ Sets the minimum and maximum measurement values.
6060

6161
This function will return ``true`` if successful, ``false`` otherwise.
6262

63+
setDefaultValue
64+
^^^^^^^^^^^^^^^
65+
66+
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.
67+
68+
.. code-block:: arduino
69+
70+
bool setDefaultValue(int16_t defaultValue);
71+
72+
* ``defaultValue`` - Default pressure value in hPa
73+
74+
**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).
75+
76+
This function will return ``true`` if successful, ``false`` otherwise.
77+
6378
setTolerance
6479
^^^^^^^^^^^^
6580

docs/en/zigbee/ep_temperature_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ Sets the minimum and maximum temperature values for the sensor.
6060

6161
This function will return ``true`` if successful, ``false`` otherwise.
6262

63+
setDefaultValue
64+
^^^^^^^^^^^^^^^
65+
66+
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.
67+
68+
.. code-block:: arduino
69+
70+
bool setDefaultValue(float defaultValue);
71+
72+
* ``defaultValue`` - Default temperature value in degrees Celsius
73+
74+
**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).
75+
76+
This function will return ``true`` if successful, ``false`` otherwise.
77+
6378
setTolerance
6479
^^^^^^^^^^^^
6580

docs/en/zigbee/ep_wind_speed_sensor.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ Sets the minimum and maximum measurement values.
7070

7171
This function will return ``true`` if successful, ``false`` otherwise.
7272

73+
setDefaultValue
74+
^^^^^^^^^^^^^^^
75+
76+
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.
77+
78+
.. code-block:: arduino
79+
80+
bool setDefaultValue(float defaultValue);
81+
82+
* ``defaultValue`` - Default wind speed value in 0.01 m/s
83+
84+
**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).
85+
86+
This function will return ``true`` if successful, ``false`` otherwise.
87+
7388
setTolerance
7489
^^^^^^^^^^^^
7590

libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ ZigbeeCarbonDioxideSensor::ZigbeeCarbonDioxideSensor(uint8_t endpoint) : ZigbeeE
3838
_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};
3939
}
4040

41+
bool ZigbeeCarbonDioxideSensor::setDefaultValue(float defaultValue) {
42+
float zb_default_value = defaultValue / 1000000.0f;
43+
esp_zb_attribute_list_t *carbon_dioxide_measure_cluster =
44+
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_CARBON_DIOXIDE_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
45+
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);
46+
if (ret != ESP_OK) {
47+
log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret));
48+
return false;
49+
}
50+
return true;
51+
}
52+
4153
bool ZigbeeCarbonDioxideSensor::setMinMaxValue(float min, float max) {
4254
float zb_min = min / 1000000.0f;
4355
float zb_max = max / 1000000.0f;

libraries/Zigbee/src/ep/ZigbeeCarbonDioxideSensor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class ZigbeeCarbonDioxideSensor : public ZigbeeEP {
5858
// Set the carbon dioxide value in ppm
5959
bool setCarbonDioxide(float carbon_dioxide);
6060

61+
// Set the default (initial) value for the carbon dioxide sensor in ppm
62+
// Must be called before adding the EP to Zigbee class. Only effective in factory reset mode (before commissioning)
63+
bool setDefaultValue(float defaultValue);
64+
6165
// Set the min and max value for the carbon dioxide sensor in ppm
6266
bool setMinMaxValue(float min, float max);
6367

libraries/Zigbee/src/ep/ZigbeeFlowSensor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ ZigbeeFlowSensor::ZigbeeFlowSensor(uint8_t endpoint) : ZigbeeEP(endpoint) {
3636
_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};
3737
}
3838

39+
bool ZigbeeFlowSensor::setDefaultValue(float defaultValue) {
40+
uint16_t zb_default_value = (uint16_t)(defaultValue * 10);
41+
esp_zb_attribute_list_t *flow_measure_cluster =
42+
esp_zb_cluster_list_get_cluster(_cluster_list, ESP_ZB_ZCL_CLUSTER_ID_FLOW_MEASUREMENT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE);
43+
esp_err_t ret = esp_zb_cluster_update_attr(flow_measure_cluster, ESP_ZB_ZCL_ATTR_FLOW_MEASUREMENT_VALUE_ID, (void *)&zb_default_value);
44+
if (ret != ESP_OK) {
45+
log_e("Failed to set default value: 0x%x: %s", ret, esp_err_to_name(ret));
46+
return false;
47+
}
48+
return true;
49+
}
50+
3951
bool ZigbeeFlowSensor::setMinMaxValue(float min, float max) {
4052
uint16_t zb_min = (uint16_t)(min * 10);
4153
uint16_t zb_max = (uint16_t)(max * 10);

0 commit comments

Comments
 (0)