ESPHome 2026.10.0-dev
Loading...
Searching...
No Matches
real_time_clock.h
Go to the documentation of this file.
1#pragma once
2
3#include <bitset>
4#include <cstdlib>
8#include "esphome/core/time.h"
9#ifdef USE_TIME_TIMEZONE
10#include "posix_tz.h"
11#endif
12
13namespace esphome::time {
14
22 public:
23 explicit RealTimeClock();
24
27
30
32 time_t timestamp_now() { return ::time(nullptr); }
33
34 template<typename F> void add_on_time_sync_callback(F &&callback) {
35 this->time_sync_callback_.add(std::forward<F>(callback));
36 }
37
38 void dump_config() override;
39
40 protected:
42 void synchronize_epoch_(uint32_t epoch);
43
45};
46
47template<typename... Ts> class TimeHasTimeCondition final : public Condition<Ts...> {
48 public:
50 bool check(const Ts &...x) override { return this->parent_->now().is_valid(); }
51
52 protected:
54};
55
56} // namespace esphome::time
Base class for all automation conditions.
Definition automation.h:438
This class simplifies creating components that periodically check a state.
Definition component.h:510
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
time_t timestamp_now()
Get the current time as the UTC epoch since January 1st 1970.
ESPTime now()
Get the time in the currently defined timezone.
ESPTime utcnow()
Get the time without any time zone or DST corrections.
LazyCallbackManager< void()> time_sync_callback_
void add_on_time_sync_callback(F &&callback)
void synchronize_epoch_(uint32_t epoch)
Report a unix epoch as current time.
bool check(const Ts &...x) override
TimeHasTimeCondition(RealTimeClock *parent)
static void uint32_t
A more user-friendly version of struct tm from time.h.
Definition time.h:23
bool is_valid(bool check_day_of_week=true, bool check_day_of_year=true) const
Check if this ESPTime is valid (year >= 2019 and the requested fields are in range).
Definition time.h:82
static ESPTime from_epoch_utc(time_t epoch)
Convert an UTC epoch timestamp to a UTC time ESPTime instance.
Definition time.h:143
uint16_t x
Definition tt21100.cpp:5