ESPHome 2025.5.0
Loading...
Searching...
No Matches
shutdown_switch.cpp
Go to the documentation of this file.
1#include "shutdown_switch.h"
2#include "esphome/core/hal.h"
3#include "esphome/core/log.h"
5
6#ifdef USE_ESP32
7#include <esp_sleep.h>
8#endif
9#ifdef USE_ESP8266
10#include <Esp.h>
11#endif
12
13namespace esphome {
14namespace shutdown {
15
16static const char *const TAG = "shutdown.switch";
17
18void ShutdownSwitch::dump_config() { LOG_SWITCH("", "Shutdown Switch", this); }
20 // Acknowledge
21 this->publish_state(false);
22
23 if (state) {
24 ESP_LOGI(TAG, "Shutting down...");
25 delay(100); // NOLINT
26
28#ifdef USE_ESP8266
29 ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
30#endif
31#ifdef USE_ESP32
32 esp_deep_sleep_start();
33#endif
34 }
35}
36
37} // namespace shutdown
38} // namespace esphome
void write_state(bool state) override
void publish_state(bool state)
Publish a state to the front-end from the back-end.
Definition switch.cpp:47
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:28
Application App
Global storage of Application pointer - only one Application can exist.