2#if defined(USE_ZIGBEE) && defined(USE_ESP32) && defined(USE_TIME)
9static constexpr uint32_t REGISTER_RETRY_TIMEOUT_ID = 0;
10static constexpr uint32_t SYNC_RETRY_TIMEOUT_ID = 1;
28 ezb_zcl_time_interface_t time_interface = {
33 if (!esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
37 ret = ezb_zcl_time_server_interface_register(this->
endpoint_, time_interface);
38 esp_zigbee_lock_release();
39 if (
ret != EZB_ERR_NONE) {
40 ESP_LOGW(TAG,
"Setup failed: %d",
ret);
52 if (
status == EZB_ERR_NONE) {
53 ESP_LOGV(TAG,
"Time synchronization successful");
54 }
else if (
status == EZB_ERR_TIMEOUT) {
55 ESP_LOGW(TAG,
"Time synchronization timed out");
57 ESP_LOGW(TAG,
"Time synchronization failed with error: %d",
status);
63 if (esp_zigbee_lock_acquire(10 / portTICK_PERIOD_MS)) {
64 ESP_LOGV(TAG,
"Updating time sync from Zigbee network...");
66 EZB_ZCL_TIME_SERVER_RANK_MASTER);
67 esp_zigbee_lock_release();
71 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time, will retry maximum 3 times");
77 ESP_LOGW(TAG,
"Could not acquire Zigbee lock to synchronize time");
82 ESP_LOGD(TAG,
"Not connected to Zigbee network, cannot synchronize time");
96 if (utc <= (std::numeric_limits<uint32_t>::max() -
EPOCH_2000)) {
103 this->
defer([
this, utc]() {
104 ESP_LOGV(TAG,
"Setting device time to UTC: %u",
static_cast<unsigned>(utc));
114 RealTimeClock::dump_config();
void mark_failed()
Mark this component as failed.
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void defer(const char *name, std::function< void()> &&f)
Defer a callback to the next loop() call with a const char* name.
ESPTime now()
Get the time in the currently defined timezone.
virtual time_t timestamp_now()
Get the current time as the UTC epoch since January 1st 1970.
void synchronize_epoch_(uint32_t epoch)
Report a unix epoch as current time.
void add_on_start_callback(F &&cb)
void add_on_join_callback(F &&cb)
void set_epoch_time(uint32_t utc)
static void status_cb(ezb_err_t status)
ZigbeeComponent * parent_
static void set_utc_time(uint32_t utc)
static uint32_t get_utc_time()
void dump_config() override
constexpr time_t EPOCH_2000
ESPHOME_LOG_TAG(TAG, "zigbee.time")