@@ -129,8 +129,8 @@ bool ZigbeeAnalog::setAnalogOutputApplication(uint32_t application_type) {
129
129
void ZigbeeAnalog::zbAttributeSet (const esp_zb_zcl_set_attr_value_message_t *message) {
130
130
if (message->info .cluster == ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT) {
131
131
if (message->attribute .id == ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID && message->attribute .data .type == ESP_ZB_ZCL_ATTR_TYPE_SINGLE) {
132
- float analog_output = *(float *)message->attribute .data .value ;
133
- analogOutputChanged (analog_output );
132
+ _output_state = *(float *)message->attribute .data .value ;
133
+ analogOutputChanged ();
134
134
} else {
135
135
log_w (" Received message ignored. Attribute ID: %d not supported for Analog Output" , message->attribute .id );
136
136
}
@@ -139,9 +139,9 @@ void ZigbeeAnalog::zbAttributeSet(const esp_zb_zcl_set_attr_value_message_t *mes
139
139
}
140
140
}
141
141
142
- void ZigbeeAnalog::analogOutputChanged (float analog_output ) {
142
+ void ZigbeeAnalog::analogOutputChanged () {
143
143
if (_on_analog_output_change) {
144
- _on_analog_output_change (analog_output );
144
+ _on_analog_output_change (_output_state );
145
145
} else {
146
146
log_w (" No callback function set for analog output change" );
147
147
}
@@ -166,6 +166,26 @@ bool ZigbeeAnalog::setAnalogInput(float analog) {
166
166
return true ;
167
167
}
168
168
169
+ bool ZigbeeAnalog::setAnalogOutput (float analog) {
170
+ esp_zb_zcl_status_t ret = ESP_ZB_ZCL_STATUS_SUCCESS;
171
+ _output_state = analog;
172
+ analogOutputChanged ();
173
+
174
+ log_v (" Updating analog output to %.2f" , analog);
175
+ /* Update analog output */
176
+ esp_zb_lock_acquire (portMAX_DELAY);
177
+ ret = esp_zb_zcl_set_attribute_val (
178
+ _endpoint, ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT, ESP_ZB_ZCL_CLUSTER_SERVER_ROLE, ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID, &_output_state, false
179
+ );
180
+ esp_zb_lock_release ();
181
+
182
+ if (ret != ESP_ZB_ZCL_STATUS_SUCCESS) {
183
+ log_e (" Failed to set analog output: 0x%x: %s" , ret, esp_zb_zcl_status_to_name (ret));
184
+ return false ;
185
+ }
186
+ return true ;
187
+ }
188
+
169
189
bool ZigbeeAnalog::reportAnalogInput () {
170
190
/* Send report attributes command */
171
191
esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
@@ -187,6 +207,27 @@ bool ZigbeeAnalog::reportAnalogInput() {
187
207
return true ;
188
208
}
189
209
210
+ bool ZigbeeAnalog::reportAnalogOutput () {
211
+ /* Send report attributes command */
212
+ esp_zb_zcl_report_attr_cmd_t report_attr_cmd;
213
+ report_attr_cmd.address_mode = ESP_ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT;
214
+ report_attr_cmd.attributeID = ESP_ZB_ZCL_ATTR_ANALOG_OUTPUT_PRESENT_VALUE_ID;
215
+ report_attr_cmd.direction = ESP_ZB_ZCL_CMD_DIRECTION_TO_CLI;
216
+ report_attr_cmd.clusterID = ESP_ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT;
217
+ report_attr_cmd.zcl_basic_cmd .src_endpoint = _endpoint;
218
+ report_attr_cmd.manuf_code = ESP_ZB_ZCL_ATTR_NON_MANUFACTURER_SPECIFIC;
219
+
220
+ esp_zb_lock_acquire (portMAX_DELAY);
221
+ esp_err_t ret = esp_zb_zcl_report_attr_cmd_req (&report_attr_cmd);
222
+ esp_zb_lock_release ();
223
+ if (ret != ESP_OK) {
224
+ log_e (" Failed to send Analog Output report: 0x%x: %s" , ret, esp_err_to_name (ret));
225
+ return false ;
226
+ }
227
+ log_v (" Analog Output report sent" );
228
+ return true ;
229
+ }
230
+
190
231
bool ZigbeeAnalog::setAnalogInputReporting (uint16_t min_interval, uint16_t max_interval, float delta) {
191
232
esp_zb_zcl_reporting_info_t reporting_info;
192
233
memset (&reporting_info, 0 , sizeof (esp_zb_zcl_reporting_info_t ));
0 commit comments