ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
shutdown.cpp
Go to the documentation of this file.
1#include "shutdown.h"
2#include "esphome/core/log.h"
4#include "esphome/core/hal.h"
5
6#ifdef USE_ESP32
7#include <esp_sleep.h>
8#endif
9#ifdef USE_ESP8266
10#include <Esp.h>
11#endif
12#ifdef USE_ZEPHYR
13#include <zephyr/sys/poweroff.h>
14#endif
15#ifdef USE_HOST
16#include <cstdlib>
17#endif
18
20
21ESPHOME_LOG_TAG(TAG, "shutdown");
22
24 ESP_LOGI(TAG, "Shutting down");
25 App.safe_shutdown(TEARDOWN_TIMEOUT_REBOOT_MS);
26#if defined(USE_ESP8266)
27 ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
28#elif defined(USE_ESP32)
29 esp_deep_sleep_start();
30#elif defined(USE_BK72XX)
31 // No wake source is set, so only a reset wakes it
32 lt_deep_sleep_enter();
33#elif defined(USE_ZEPHYR) && defined(CONFIG_POWEROFF)
34 sys_poweroff();
35#elif defined(USE_HOST)
36 exit(0); // NOLINT(concurrency-mt-unsafe)
37#else
38 // No power off on this chip: the main loop stops here until a reset
39 while (true) {
41 delay(100); // NOLINT
42 }
43#endif
44}
45
46} // namespace esphome::shutdown
void safe_shutdown(uint32_t timeout_ms)
Run the safe shutdown hooks, give components up to timeout_ms to tear down, then run the powerdown ho...
void shutdown_device()
Run by the shutdown button and switch.
Definition shutdown.cpp:23
ESPHOME_LOG_TAG(TAG, "shutdown")
void arch_feed_wdt()
Definition hal.cpp:133
void HOT delay(uint32_t ms)
Definition hal.cpp:78
Application App
Global storage of Application pointer - only one Application can exist.