ESPHome 2026.8.0-dev
Loading...
Searching...
No Matches
deep_sleep_esp8266.cpp
Go to the documentation of this file.
1#ifdef USE_ESP8266
3
4#include <Esp.h>
5
6#ifdef USE_DEEP_SLEEP_ON_WAKE
7extern "C" {
8#include <user_interface.h>
9}
10#endif
11
12namespace esphome::deep_sleep {
13
14static const char *const TAG = "deep_sleep";
15
16#ifdef USE_DEEP_SLEEP_ON_WAKE
18 // The ESP8266 can only wake from deep sleep through the RTC timer (via GPIO16 -> RST).
19 // NOLINTNEXTLINE(readability-static-accessed-through-instance)
20 if (ESP.getResetInfoPtr()->reason == REASON_DEEP_SLEEP_AWAKE) {
21 return WAKEUP_CAUSE_TIMER;
22 }
23 return WAKEUP_CAUSE_NONE;
24}
25#endif // USE_DEEP_SLEEP_ON_WAKE
26
27optional<uint32_t> DeepSleepComponent::get_run_duration_() const { return this->run_duration_; }
28
30
31bool DeepSleepComponent::prepare_to_sleep_() { return true; }
32
34 ESP.deepSleep(this->sleep_duration_.value_or(0)); // NOLINT(readability-static-accessed-through-instance)
35}
36
37bool DeepSleepComponent::should_teardown_() { return true; }
38
39} // namespace esphome::deep_sleep
40#endif
optional< uint32_t > get_run_duration_() const
WakeupCause get_wakeup_cause()
Return why the device woke from deep sleep. Implemented per platform.
WakeupCause
Why the device woke from deep sleep. Passed to on_wake automations.
@ WAKEUP_CAUSE_TIMER
The device was woken by the sleep timer.
@ WAKEUP_CAUSE_NONE
The device did not wake from deep sleep (for example a cold boot, reset or OTA restart).