ESPHome 2026.11.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
6extern "C" {
7#include <user_interface.h>
8}
9
10namespace esphome::deep_sleep {
11
12ESPHOME_LOG_TAG(TAG, "deep_sleep");
13
15 // The ESP8266 can only wake from deep sleep through the RTC timer (via GPIO16 -> RST).
16 // NOLINTNEXTLINE(readability-static-accessed-through-instance)
17 if (ESP.getResetInfoPtr()->reason == REASON_DEEP_SLEEP_AWAKE) {
18 return WAKEUP_CAUSE_TIMER;
19 }
20 return WAKEUP_CAUSE_NONE;
21}
22
23optional<uint32_t> DeepSleepComponent::get_run_duration_() const { return this->run_duration_; }
24
26
27bool DeepSleepComponent::prepare_to_sleep_() { return true; }
28
30 ESP.deepSleep(this->sleep_duration_.value_or(0)); // NOLINT(readability-static-accessed-through-instance)
31}
32
33bool DeepSleepComponent::should_teardown_() { return true; }
34
35} // namespace esphome::deep_sleep
36#endif
optional< uint32_t > get_run_duration_() const
ESPHOME_LOG_TAG(TAG, "deep_sleep")
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).