esphome lounge switches and scene control

This commit is contained in:
root
2025-10-08 19:21:28 +13:00
parent 1e1d0571d9
commit e96344e3ad
62 changed files with 4189 additions and 925 deletions
@@ -0,0 +1,8 @@
substitutions:
mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic
# MQTT REMOTE Controls
mqtt_remote1_device_name: "3dprinter-power"
mqtt_remote1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote1_device_name}" # Topic we will use to command this locally without HA
mqtt_remote1_status_topic: "${mqtt_status_main_topic}/${mqtt_remote1_device_name}" # Topic we will use to view status locally without HA
@@ -115,7 +115,6 @@ button:
# SCRIPTS
##########################################################################################
script:
# Classify last reset exactly once per boot
- id: classify_reset_once
mode: restart
then:
@@ -123,40 +122,60 @@ script:
// Guard: only run once per boot
if (id(reset_classified_this_boot)) return;
// Read raw reason string (examples: "Power on", "External System",
// "Software/System restart", "Fatal exception:29", "WDT reset")
String reason = ESP.getResetReason();
// Build a human-readable reason string that's valid on both ESP8266 and ESP32
std::string reason;
int cat = 0; // 1=power, 2=software, 3=crash
// Category: 1=power, 2=software, 3=crash
int cat = 0;
#if defined(ARDUINO_ARCH_ESP8266)
// ESP8266: use Arduino core helper, returns Arduino String
reason = std::string(ESP.getResetReason().c_str());
// Crash has priority if phrases appear (rare but be explicit)
if (reason.indexOf("Watchdog") >= 0 || reason.indexOf("WDT") >= 0 ||
reason.indexOf("Exception") >= 0 || reason.indexOf("exception") >= 0) {
cat = 3; // crash
}
// Software/System restart (HA/API/OTA initiated)
else if (reason.indexOf("Software") >= 0 || reason.indexOf("System") >= 0) {
cat = 2; // software
}
// Power-like causes (power-on, external reset pin/button, deep sleep wake)
else if (reason.indexOf("Power") >= 0 || reason.indexOf("External") >= 0 ||
reason.indexOf("Deep") >= 0) {
cat = 1; // power
}
// Anything else -> crash bucket
else {
// Classify (string match like your original)
if (reason.find("Watchdog") != std::string::npos ||
reason.find("WDT") != std::string::npos ||
reason.find("Exception")!= std::string::npos ||
reason.find("exception")!= std::string::npos) {
cat = 3;
} else if (reason.find("Software") != std::string::npos ||
reason.find("System") != std::string::npos) {
cat = 2;
} else if (reason.find("Power") != std::string::npos ||
reason.find("External") != std::string::npos ||
reason.find("Deep") != std::string::npos) {
cat = 1;
} else {
cat = 3;
}
#elif defined(ARDUINO_ARCH_ESP32)
// ESP32: use IDF enum and map to text + categories directly
esp_reset_reason_t r = esp_reset_reason();
switch (r) {
case ESP_RST_POWERON: reason = "Power on"; cat = 1; break;
case ESP_RST_EXT: reason = "External reset"; cat = 1; break; // reset pin/button
case ESP_RST_SW: reason = "Software reset"; cat = 2; break; // OTA/API/HA/etc.
case ESP_RST_PANIC: reason = "Panic/exception"; cat = 3; break;
case ESP_RST_INT_WDT: reason = "Interrupt WDT"; cat = 3; break;
case ESP_RST_TASK_WDT: reason = "Task WDT"; cat = 3; break;
case ESP_RST_WDT: reason = "Other WDT"; cat = 3; break;
case ESP_RST_DEEPSLEEP: reason = "Deep sleep wake"; cat = 1; break;
case ESP_RST_BROWNOUT: reason = "Brownout"; cat = 1; break; // power-ish
case ESP_RST_SDIO: reason = "SDIO reset"; cat = 3; break;
default: reason = "Unknown reset reason"; cat = 3; break;
}
#else
// Fallback for any other arch (very unlikely in your setup)
reason = "Unknown platform reset";
cat = 3;
}
#endif
// Increment counters
if (cat == 1) id(power_reset_count) += 1;
if (cat == 2) id(software_reset_count) += 1;
if (cat == 3) id(crash_reset_count) += 1;
// Publish reason text now
// Publish reason and mark done
id(last_reset_reason_txt).publish_state(reason.c_str());
// Mark done for this boot
id(reset_classified_this_boot) = true;
# Publish the three counters (kept separate so we can reuse)
@@ -181,3 +200,4 @@ interval:
- script.execute: classify_reset_once
- script.execute: publish_reset_status
# On later passes, the guard prevents re-counting and this block does nothing.
-1
View File
@@ -10,7 +10,6 @@ substitutions:
#############################################
# MQTT Monitoring
# https://esphome.io/components/mqtt.html?highlight=mqtt
# MUST also have api enabled if you enable MQTT
#############################################
mqtt:
broker: ${mqtt_server}