9static const char *
const TAG =
"automation";
10static const int MAX_TIMESTAMP_DRIFT = 900;
35 if (last_check > time && last_check.
timestamp - time.
timestamp > MAX_TIMESTAMP_DRIFT) {
37 ESP_LOGW(TAG,
"Time has jumped back!");
38 }
else if (last_check >= time) {
41 }
else if (time > last_check && time.
timestamp - last_check.timestamp > MAX_TIMESTAMP_DRIFT) {
43 ESP_LOGW(TAG,
"Time has jumped ahead!");
49 last_check.increment_second();
50 if (last_check >= time)
60 ESP_LOGW(TAG,
"Time is out of range!");
61 ESP_LOGD(TAG,
"Second=%02u Minute=%02u Hour=%02u DayOfWeek=%u DayOfMonth=%u DayOfYear=%u Month=%u time=%" PRId64,
71 for (uint8_t it : seconds)
75 for (uint8_t it : minutes)
79 for (uint8_t it : hours)
83 for (uint8_t it : days_of_month)
87 for (uint8_t it : months)
91 for (uint8_t it : days_of_week)
ESPDEPRECATED("Use const char* or uint32_t overload instead. Removed in 2026.7.0", "2026.1.0") void set_interval(const std voi set_interval)(const char *name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
void add_second(uint8_t second)
void add_minutes(const std::vector< uint8_t > &minutes)
void add_month(uint8_t month)
std::bitset< 8 > days_of_week_
void add_hour(uint8_t hour)
void add_day_of_month(uint8_t day_of_month)
void add_seconds(const std::vector< uint8_t > &seconds)
bool matches(const ESPTime &time)
void add_months(const std::vector< uint8_t > &months)
float get_setup_priority() const override
void add_days_of_month(const std::vector< uint8_t > &days_of_month)
std::bitset< 32 > days_of_month_
std::bitset< 61 > seconds_
CronTrigger(RealTimeClock *rtc)
void add_minute(uint8_t minute)
optional< ESPTime > last_check_
void add_days_of_week(const std::vector< uint8_t > &days_of_week)
void add_day_of_week(uint8_t day_of_week)
std::bitset< 60 > minutes_
std::bitset< 13 > months_
void add_hours(const std::vector< uint8_t > &hours)
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
ESPTime now()
Get the time in the currently defined timezone.
void add_on_time_sync_callback(F &&callback)
SyncTrigger(RealTimeClock *rtc)
constexpr float HARDWARE
For components that deal with hardware and are very important like GPIO switch.
A more user-friendly version of struct tm from time.h.
uint8_t minute
minutes after the hour [0-59]
uint8_t second
seconds after the minute [0-60]
bool fields_in_range(bool check_day_of_week=true, bool check_day_of_year=true) const
Check if time fields are in range.
uint8_t hour
hours since midnight [0-23]
time_t timestamp
unix epoch time (seconds since UTC Midnight January 1, 1970)
uint16_t day_of_year
day of the year [1-366]
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).
uint8_t day_of_month
day of the month [1-31]
uint8_t month
month; january=1 [1-12]
uint8_t day_of_week
day of the week; sunday=1 [1-7]