diff --git a/esphome/energymonitor.yaml b/esphome/energymonitor.yaml index cab5100..32b9365 100644 --- a/esphome/energymonitor.yaml +++ b/esphome/energymonitor.yaml @@ -16,6 +16,9 @@ esphome: # ESPHome emits angle-bracket includes before globals; the local entry copies the header. - - energy_day_history.h + - + - + - on_boot: then: - light.turn_on: display_backlight @@ -155,6 +158,14 @@ light: restore_mode: ALWAYS_ON switch: + - platform: template + id: memory_debug_enabled + name: "Memory Pressure Debug Logging" + entity_category: config + optimistic: true + restore_mode: RESTORE_DEFAULT_OFF + on_turn_on: + - script.execute: log_memory_pressure - platform: template id: slideshow_enabled name: "Diashow" @@ -342,6 +353,10 @@ globals: initial_value: '0' sensor: + - platform: uptime + name: "Uptime" + entity_category: diagnostic + update_interval: 60s - platform: scd30 id: room_climate i2c_id: grove_i2c @@ -540,6 +555,13 @@ sensor: name: 'WireGuard Latest Handshake' interval: + - interval: 60s + then: + - if: + condition: + switch.is_on: memory_debug_enabled + then: + - script.execute: log_memory_pressure - interval: 1s then: - script.execute: refresh_display @@ -587,6 +609,28 @@ interval: } script: + - id: log_memory_pressure + then: + - lambda: |- + multi_heap_info_t heap{}; + heap_caps_get_info(&heap, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT); + const auto reason = esp_reset_reason(); + const char *label; + switch (reason) { + case ESP_RST_POWERON: label = "power-on"; break; + case ESP_RST_EXT: label = "external"; break; + case ESP_RST_SW: label = "software"; break; + case ESP_RST_PANIC: label = "panic"; break; + case ESP_RST_INT_WDT: label = "interrupt watchdog"; break; + case ESP_RST_TASK_WDT: label = "task watchdog"; break; + case ESP_RST_WDT: label = "watchdog"; break; + case ESP_RST_BROWNOUT: label = "brownout"; break; + default: label = "other"; break; + } + ESP_LOGD("memory_pressure", "uptime=%lld s reset=%s (%d) internal 8-bit heap [bytes]: free=%u min_free=%u largest_block=%u; free_blocks=%u", + static_cast(esp_timer_get_time() / 1000000), label, static_cast(reason), + static_cast(heap.total_free_bytes), static_cast(heap.minimum_free_bytes), + static_cast(heap.largest_free_block), static_cast(heap.free_blocks)); - id: slideshow_worker mode: restart then: