Time

API Reference

namespace time
class CronTrigger : public Trigger<NoArg>, public Component

Public Functions

CronTrigger(RealTimeClockComponent *rtc)
void add_second(uint8_t second)
void add_seconds(const std::vector<uint8_t> &seconds)
void add_minute(uint8_t minute)
void add_minutes(const std::vector<uint8_t> &minutes)
void add_hour(uint8_t hour)
void add_hours(const std::vector<uint8_t> &hours)
void add_day_of_month(uint8_t day_of_month)
void add_days_of_month(const std::vector<uint8_t> &days_of_month)
void add_month(uint8_t month)
void add_months(const std::vector<uint8_t> &months)
void add_day_of_week(uint8_t day_of_week)
void add_days_of_week(const std::vector<uint8_t> &days_of_week)
bool matches(const EsphomelibTime &time)
void loop()
float get_setup_priority() const

Protected Attributes

std::bitset<61> seconds_
std::bitset<60> minutes_
std::bitset<24> hours_
std::bitset<32> days_of_month_
std::bitset<13> months_
std::bitset<8> days_of_week_
RealTimeClockComponent *rtc_
optional<EsphomelibTime> last_check_
struct EsphomelibTime
#include <rtc_component.h>

A more user-friendly version of struct tm from time.h.

Public Functions

size_t strftime(char *buffer, size_t buffer_len, const char *format)

Convert this EsphomelibTime struct to a null-terminated c string buffer as specified by the format argument.

Up to buffer_len bytes are written.

See
https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime

std::string strftime(const std::string &format)

Convert this EsphomelibTime struct to a string as specified by the format argument.

See
https://www.gnu.org/software/libc/manual/html_node/Formatting-Calendar-Time.html#index-strftime
Warning
This method uses dynamically allocated strings which can cause heap fragmentation with some microcontrollers.

bool is_valid() const
bool in_range() const
struct tm to_c_tm()
void increment_second()
bool operator<(EsphomelibTime other)
bool operator<=(EsphomelibTime other)
bool operator==(EsphomelibTime other)
bool operator>=(EsphomelibTime other)
bool operator>(EsphomelibTime other)

Public Members

uint8_t second

seconds after the minute [0-60]

Note
second is generally 0-59; the extra range is to accommodate leap seconds.

uint8_t minute

minutes after the hour [0-59]

uint8_t hour

hours since midnight [0-23]

uint8_t day_of_week

day of the week; sunday=1 [1-7]

uint8_t day_of_month

day of the month [1-31]

uint16_t day_of_year

day of the year [1-366]

uint8_t month

month; january=1 [1-12]

uint16_t year

year

bool is_dst

daylight savings time flag

time_t time

unix epoch time (seconds since UTC Midnight January 1, 1970)

Public Static Functions

EsphomelibTime from_tm(struct tm *c_tm, time_t c_time)
class RealTimeClockComponent : public Component
#include <rtc_component.h>

The RealTimeClock class exposes common timekeeping functions via the device’s local real-time clock.

Note
The C library (newlib) available on ESPs only supports TZ strings that specify an offset and DST info; you cannot specify zone names or paths to zoneinfo files.
See
https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

Subclassed by time::HomeAssistantTime, time::SNTPComponent

Public Functions

RealTimeClockComponent()
void set_timezone(const std::string &tz)

Set the time zone.

std::string get_timezone()

Get the time zone currently in use.

EsphomelibTime now()

Get the time in the currently defined timezone.

EsphomelibTime utcnow()

Get the time without any time zone or DST corrections.

CronTrigger *make_cron_trigger()
void setup_()

Protected Attributes

std::string timezone_ = {}
namespace time
class SNTPComponent : public time::RealTimeClockComponent
#include <sntp_component.h>

The SNTP component allows you to configure local timekeeping via Simple Network Time Protocol.

Note
The C library (newlib) available on ESPs only supports TZ strings that specify an offset and DST info; you cannot specify zone names or paths to zoneinfo files.
See
https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html

Public Functions

SNTPComponent()
void setup()
void dump_config()
void set_servers(const std::string &server_1, const std::string &server_2, const std::string &server_3)

Change the servers used by SNTP for timekeeping.

float get_setup_priority() const
void loop()

Protected Attributes

std::string server_1_
std::string server_2_
std::string server_3_
bool has_time_ = {false}
namespace time
class GetTimeResponse : public api::APIMessage

Public Functions

bool decode_32bit(uint32_t field_id, uint32_t value)
api::APIMessageType message_type() const
class HomeAssistantTime : public time::RealTimeClockComponent

Public Functions

void setup()
void dump_config()
void set_epoch_time(uint32_t epoch)
float get_setup_priority() const