17 namespace deep_sleep {
63 void set_sleep_duration(uint32_t time_ms);
64 #if defined(USE_ESP32) 73 #if defined(USE_ESP32) 74 #if !defined(USE_ESP32_VARIANT_ESP32C3) 78 void set_touch_wakeup(
bool touch_wakeup);
87 void set_run_duration(uint32_t time_ms);
89 void setup()
override;
90 void dump_config()
override;
92 float get_loop_priority()
const override;
93 float get_setup_priority()
const override;
96 void begin_sleep(
bool manual =
false);
98 void prevent_deep_sleep();
99 void allow_deep_sleep();
115 bool next_enter_deep_sleep_{
false};
116 bool prevent_{
false};
124 TEMPLATABLE_VALUE(uint32_t, sleep_duration);
127 void set_until(uint8_t hour, uint8_t minute, uint8_t second) {
129 this->minute_ = minute;
130 this->second_ = second;
137 if (this->sleep_duration_.has_value()) {
138 this->deep_sleep_->set_sleep_duration(this->sleep_duration_.value(x...));
142 if (this->hour_.has_value()) {
143 auto time = this->time_->now();
144 const uint32_t timestamp_now = time.timestamp;
146 bool after_time =
false;
147 if (time.hour > this->hour_) {
150 if (time.hour == this->hour_) {
151 if (time.minute > this->minute_) {
154 if (time.minute == this->minute_) {
155 if (time.second > this->second_) {
163 time.hour = *this->hour_;
164 time.minute = *this->minute_;
165 time.second = *this->second_;
166 time.recalc_timestamp_utc();
168 time_t timestamp = time.timestamp;
171 timestamp += 60 * 60 * 24;
175 const uint32_t ms_left = (timestamp - timestamp_now) * 1000;
176 this->deep_sleep_->set_sleep_duration(ms_left);
179 this->deep_sleep_->begin_sleep(
true);
195 void play(Ts... x)
override { this->parent_->prevent_deep_sleep(); }
200 void play(Ts... x)
override { this->parent_->allow_deep_sleep(); }
void play(Ts... x) override
void set_until(uint8_t hour, uint8_t minute, uint8_t second)
void play(Ts... x) override
optional< bool > touch_wakeup_
optional< WakeupCauseToRunDuration > wakeup_cause_to_run_duration_
bool global_has_deep_sleep
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock...
WakeupPinMode
The values of this enum define what should be done if deep sleep is set up with a wakeup pin on the E...
optional< uint64_t > sleep_duration_
This component allows setting up the node to go into deep sleep mode to conserve battery.
time::RealTimeClock * time_
DeepSleepComponent * deep_sleep_
optional< uint32_t > run_duration_
optional< Ext1Wakeup > ext1_wakeup_
optional< uint8_t > minute_
Ignore the fact that we will wake up when going into deep sleep.
void play(Ts... x) override
InternalGPIOPin * wakeup_pin_
optional< uint8_t > second_
optional< uint8_t > hour_
void set_time(time::RealTimeClock *time)
EnterDeepSleepAction(DeepSleepComponent *deep_sleep)
As long as the wakeup pin is still in the wakeup state, keep awake.
Automatically invert the wakeup level.
esp_sleep_ext1_wakeup_mode_t wakeup_mode
static int32_t timezone_offset()
Helper class to easily give an object a parent of type T.
void set_wakeup_pin(InternalGPIOPin *pin)
Set the pin to wake up to on the ESP32 once it's in deep sleep mode.