New Debug Component - How to get Reset reason & information seperate?

I not found an answer so i did it:

esphome:
...
  on_boot:
    - priority: -100
      then:
          - lambda: |-
            id(reset_reason).update();

...

text_sensor:
  - platform: template
    id: reset_reason
    name: Reset Reason
    update_interval: 15min
    lambda: |-
      // Define the reset reasons array
      const char *const RESET_REASONS[] = {
          "unknown source",
          "power-on event",
          "external pin",
          "software via esp_restart",
          "exception/panic",
          "interrupt watchdog",
          "task watchdog",
          "other watchdogs",
          "exiting deep sleep mode",
          "brownout",
          "SDIO",
          "USB peripheral",
          "JTAG",
          "efuse error",
          "power glitch detected",
          "CPU lock up",
      };

      // Return the corresponding reset reason string directly
      return std::string(RESET_REASONS[esp_reset_reason()]);

Sorry for bumping such an old thread but i’ll leave this here, maybe someone in the future need it

for reference: ESPHome: esphome/components/debug/debug_esp32.cpp Source File

1 Like