ESPHome 2026.1.4
Loading...
Searching...
No Matches
zigbee_binary_sensor_zephyr.cpp
Go to the documentation of this file.
2#if defined(USE_ZIGBEE) && defined(USE_NRF52) && defined(USE_BINARY_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.binary_sensor";
14
15ZigbeeBinarySensor::ZigbeeBinarySensor(binary_sensor::BinarySensor *binary_sensor) : binary_sensor_(binary_sensor) {}
16
18 this->binary_sensor_->add_on_state_callback([this](bool state) {
19 this->cluster_attributes_->present_value = state ? ZB_TRUE : ZB_FALSE;
20 ESP_LOGD(TAG, "Set attribute endpoint: %d, present_value %d", this->endpoint_,
22 ZB_ZCL_SET_ATTRIBUTE(this->endpoint_, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, ZB_ZCL_CLUSTER_SERVER_ROLE,
23 ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, &this->cluster_attributes_->present_value,
24 ZB_FALSE);
25 this->parent_->flush();
26 });
27}
28
30 ESP_LOGCONFIG(TAG,
31 "Zigbee Binary Sensor\n"
32 " Endpoint: %d, present_value %u",
34}
35
36} // namespace esphome::zigbee
37#endif
void add_on_state_callback(std::function< void(T)> &&callback)
Base class for all binary_sensor-type classes.
ZigbeeBinarySensor(binary_sensor::BinarySensor *binary_sensor)
bool state
Definition fan.h:0
const char *const TAG
Definition spi.cpp:7