ESPHome 2026.1.4
Loading...
Searching...
No Matches
zigbee_sensor_zephyr.cpp
Go to the documentation of this file.
2#if defined(USE_ZIGBEE) && defined(USE_NRF52) && defined(USE_SENSOR)
3#include "esphome/core/log.h"
4extern "C" {
5#include <zboss_api.h>
6#include <zboss_api_addons.h>
7#include <zb_nrf_platform.h>
8#include <zigbee/zigbee_app_utils.h>
9#include <zb_error_to_string.h>
10}
11namespace esphome::zigbee {
12
13static const char *const TAG = "zigbee.sensor";
14
15ZigbeeSensor::ZigbeeSensor(sensor::Sensor *sensor) : sensor_(sensor) {}
16
18 this->sensor_->add_on_state_callback([this](float state) {
20 ESP_LOGD(TAG, "Set attribute endpoint: %d, present_value %f", this->endpoint_, state);
21 ZB_ZCL_SET_ATTRIBUTE(this->endpoint_, ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
23 (zb_uint8_t *) &this->cluster_attributes_->present_value, ZB_FALSE);
24 this->parent_->flush();
25 });
26}
27
29 ESP_LOGCONFIG(TAG,
30 "Zigbee Sensor\n"
31 " Endpoint: %d, present_value %f",
33}
34
36
37static zb_ret_t check_value_analog_server(zb_uint16_t attr_id, zb_uint8_t endpoint,
38 zb_uint8_t *value) { // NOLINT(readability-non-const-parameter)
39 zb_ret_t ret = RET_OK;
40 ZVUNUSED(endpoint);
41
42 switch (attr_id) {
44 ret = ZB_ZCL_CHECK_BOOL_VALUE(*value) ? RET_OK : RET_ERROR;
45 break;
47 break;
48
51 ret = RET_ERROR;
52 }
53 break;
54
55 default:
56 break;
57 }
58
59 return ret;
60}
61
62} // namespace esphome::zigbee
63
65 zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
66 esphome::zigbee::check_value_analog_server, (zb_zcl_cluster_write_attr_hook_t) NULL,
67 (zb_zcl_cluster_handler_t) NULL);
68}
69
71 zb_zcl_add_cluster_handlers(ZB_ZCL_CLUSTER_ID_ANALOG_INPUT, ZB_ZCL_CLUSTER_CLIENT_ROLE,
72 (zb_zcl_cluster_check_value_t) NULL, (zb_zcl_cluster_write_attr_hook_t) NULL,
73 (zb_zcl_cluster_handler_t) NULL);
74}
75
76#endif
Base-class for all sensors.
Definition sensor.h:42
void add_on_state_callback(std::function< void(float)> &&callback)
Add a callback that will be called every time a filtered value arrives.
Definition sensor.cpp:89
ZigbeeSensor(sensor::Sensor *sensor)
bool state
Definition fan.h:0
const char *const TAG
Definition spi.cpp:7
const zb_uint8_t ZB_ZCL_ANALOG_INPUT_STATUS_FLAG_MAX_VALUE
void zb_zcl_analog_input_init_client()
void zb_zcl_analog_input_init_server()
@ ZB_ZCL_ATTR_ANALOG_INPUT_PRESENT_VALUE_ID
@ ZB_ZCL_ATTR_ANALOG_INPUT_OUT_OF_SERVICE_ID
@ ZB_ZCL_ATTR_ANALOG_INPUT_STATUS_FLAG_ID