ESPHome 2026.5.1
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::shutdown {
14
15static const char *const TAG = "shutdown.switch";
16
17void ShutdownSwitch::dump_config() { LOG_SWITCH("", "Shutdown Switch", this); }
19 // Acknowledge
20 this->publish_state(false);
21
22 if (state) {
23 ESP_LOGI(TAG, "Shutting down");
24 delay(100); // NOLINT
25
27#ifdef USE_ESP8266
28 ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance)
29#endif
30#ifdef USE_ESP32
31 esp_deep_sleep_start();
32#endif
33 }
34}
35
36} // namespace esphome::shutdown
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:56
bool state
Definition fan.h:2
void HOT delay(uint32_t ms)
Definition hal.cpp:85
Application App
Global storage of Application pointer - only one Application can exist.