esphome device updates

This commit is contained in:
root
2025-09-20 15:18:46 +12:00
parent a27b79fbd9
commit 1e1d0571d9
32 changed files with 3756 additions and 1188 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
#############################################
##########################################################################################
# Enable the Home Assistant API
# https://esphome.io/components/api.html
#############################################
##########################################################################################
api:
encryption:
key: ${local_api_key}
@@ -0,0 +1,64 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
# LITE (1MB-friendly)
##########################################################################################
sensor:
- platform: uptime
name: "Uptime (s):"
update_interval: ${local_update_interval}
id: uptime_sensor
entity_category: diagnostic
- platform: wifi_signal
name: "Wifi (dB):"
id: wifi_signal_db
update_interval: ${local_update_interval}
entity_category: diagnostic
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi (%):"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "% Max"
entity_category: "diagnostic"
device_class: ""
binary_sensor:
- platform: status
name: "Network Status"
icon: mdi:check-network-outline
entity_category: diagnostic
##########################################################################################
# Text Sensors
# https://esphome.io/components/text_sensor/index.html
##########################################################################################
text_sensor:
- platform: uptime # Uptime for this device human readable
name: "Uptime:"
icon: mdi:clock-start
update_interval: ${local_update_interval}
entity_category: "diagnostic"
##########################################################################################
# BUTTONS
# Diagnostic buttons, activated if needed in HA
##########################################################################################
button:
- platform: safe_mode
name: "Safe Mode Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: restart
name: "Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: factory_reset
name: "FACTORY RESET:"
entity_category: "diagnostic"
disabled_by_default: true
@@ -0,0 +1,64 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
# LITE (1MB-friendly)
##########################################################################################
sensor:
- platform: uptime
name: "Uptime (s):"
update_interval: ${local_update_interval}
id: uptime_sensor
entity_category: diagnostic
- platform: wifi_signal
name: "Wifi (dB):"
id: wifi_signal_db
update_interval: ${local_update_interval}
entity_category: diagnostic
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi (%):"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "% Max"
entity_category: "diagnostic"
device_class: ""
binary_sensor:
- platform: status
name: "Network Status"
icon: mdi:check-network-outline
entity_category: diagnostic
##########################################################################################
# Text Sensors
# https://esphome.io/components/text_sensor/index.html
##########################################################################################
text_sensor:
- platform: uptime # Uptime for this device human readable
name: "Uptime:"
icon: mdi:clock-start
update_interval: ${local_update_interval}
entity_category: "diagnostic"
##########################################################################################
# BUTTONS
# Diagnostic buttons, activated if needed in HA
##########################################################################################
button:
- platform: safe_mode
name: "Safe Mode Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: restart
name: "Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: factory_reset
name: "FACTORY RESET:"
entity_category: "diagnostic"
disabled_by_default: true
@@ -0,0 +1,42 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
##########################################################################################
# Debug helpers (loop time / heap / reset info)
debug:
update_interval: ${local_update_interval}
sensor:
# Free heap via debug (replaces template-based ESP.getFreeHeap if you prefer)
- platform: debug
free:
name: "Free Heap"
entity_category: "diagnostic"
# Loop time via debug (replaces broken template loop time)
- platform: debug
loop_time:
name: "Loop Time"
entity_category: "diagnostic"
## If youd rather keep the legacy heap sensor, uncomment below and
## delete the debug "free" block above to avoid duplicates:
# - platform: template
# name: "${friendly_name} Free Heap"
# unit_of_measurement: "B"
# update_interval: 30s
# entity_category: "diagnostic"
# lambda: |-
# return (float) ESP.getFreeHeap();
## # Only works with esp8266
#- platform: adc
# pin: VCC
# name: "VCC Voltage"
# id: vcc_voltage_sensor
# entity_category: diagnostic
@@ -0,0 +1,54 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# Text Sensors
# https://esphome.io/components/text_sensor/index.html
##########################################################################################
text_sensor:
- platform: version
name: "Version:"
entity_category: "diagnostic"
- platform: wifi_info
ip_address:
icon: mdi:ip-network
entity_category: diagnostic
name: "IP Address:"
ssid:
name: "Connected SSID"
icon: mdi:wifi-strength-2
entity_category: diagnostic
mac_address:
name: "MAC Address:"
icon: mdi:network-pos
entity_category: diagnostic
#####################################################################################################
# Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds
###################################################################################################
# - platform: template
# name: "Uptime (Days)"
# entity_category: diagnostic
# lambda: |-
# int seconds = (id(uptime_sensor).state);
# int days = seconds / (24 * 3600);
# seconds = seconds % (24 * 3600);
# int hours = seconds / 3600;
# seconds = seconds % 3600;
# int minutes = seconds / 60;
# seconds = seconds % 60;
# if ( days > 3650 ) {
# return "Starting up" ;
# } else if ( days ) {
# return (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() ;
# } else if ( hours ) {
# return (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() ;
# } else if ( minutes ) {
# return (String(minutes) +"m "+ String(seconds) +"s").c_str() ;
# } else {
# return (String(seconds) +"s").c_str() ;
# }
# icon: mdi:clock-start
@@ -0,0 +1,183 @@
##########################################################################################
##########################################################################################
# Title: Reset Classification & Counters (Interval-based, no on_boot work)
# Target: ESP8266/ESP32 (optimized for ESP8266 heap stability)
#
# Exposes four entities:
# - <friendly> Restarts: Power (sensor)
# - <friendly> Restarts: Software (sensor)
# - <friendly> Restarts: Crashes (sensor)
# - <friendly> Restarts: Last Reason (text_sensor)
#
# Also exposes a button:
# - <friendly> Restarts: Clear Counters
#
# Behavior:
# - Does NOT run on_boot. Instead, an interval waits a short time after power-up, then:
# * Reads ESP.getResetReason()
# * Categorizes into one of: power, software, crash (exactly one bucket)
# * Increments that counter and publishes all three sensors + the last reason.
# - A 'run-once per boot' guard prevents re-incrementing on subsequent intervals.
#
# Notes:
# - Uses Arduino String (not std::string) in lambdas to reduce heap churn.
# - Sensors use update_interval: never; theyre pushed when we publish.
# - If you prefer a different delay, change the interval: value below.
##########################################################################################
##########################################################################################
##########################################################################################
# GLOBALS
##########################################################################################
globals:
# Cumulative counters (persist across reboots)
- id: power_reset_count
type: int
restore_value: true
initial_value: '0'
- id: software_reset_count
type: int
restore_value: true
initial_value: '0'
- id: crash_reset_count
type: int
restore_value: true
initial_value: '0'
# Per-boot guard so the interval only classifies once each boot
- id: reset_classified_this_boot
type: bool
restore_value: false # always false at cold boot
initial_value: 'false'
##########################################################################################
# SENSORS (push-only; never self-update)
##########################################################################################
sensor:
- platform: template
id: power_reset_count_sensor
name: "${friendly_name} Restarts: Power"
icon: mdi:power-plug
unit_of_measurement: "restarts"
accuracy_decimals: 0
entity_category: diagnostic
update_interval: never
- platform: template
id: software_reset_count_sensor
name: "${friendly_name} Restarts: Software"
icon: mdi:restart
unit_of_measurement: "restarts"
accuracy_decimals: 0
entity_category: diagnostic
update_interval: never
- platform: template
id: crash_reset_count_sensor
name: "${friendly_name} Restarts: Crashes"
icon: mdi:alert-decagram
unit_of_measurement: "restarts"
accuracy_decimals: 0
entity_category: diagnostic
update_interval: never
##########################################################################################
# TEXT SENSORS (push-only; never self-update)
##########################################################################################
text_sensor:
- platform: template
id: last_reset_reason_txt
name: "${friendly_name} Restarts: Last Reason"
icon: mdi:restart-alert
entity_category: diagnostic
update_interval: never
##########################################################################################
# BUTTONS
##########################################################################################
button:
- platform: template
id: clear_reset_counters_btn
name: "${friendly_name} Restarts: Clear Counters"
icon: mdi:backup-restore
entity_category: diagnostic
on_press:
- lambda: |-
id(power_reset_count) = 0;
id(software_reset_count) = 0;
id(crash_reset_count) = 0;
id(power_reset_count_sensor).publish_state(0);
id(software_reset_count_sensor).publish_state(0);
id(crash_reset_count_sensor).publish_state(0);
// Keep the last reason as-is; it describes the most recent boot.
##########################################################################################
# SCRIPTS
##########################################################################################
script:
# Classify last reset exactly once per boot
- id: classify_reset_once
mode: restart
then:
- lambda: |-
// 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();
// Category: 1=power, 2=software, 3=crash
int cat = 0;
// 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 {
cat = 3;
}
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
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)
- id: publish_reset_status
mode: restart
then:
- lambda: |-
id(power_reset_count_sensor).publish_state(id(power_reset_count));
id(software_reset_count_sensor).publish_state(id(software_reset_count));
id(crash_reset_count_sensor).publish_state(id(crash_reset_count));
##########################################################################################
# INTERVAL: run once shortly after boot, then no-op
##########################################################################################
interval:
- interval: 10s
then:
- if:
condition:
lambda: 'return !id(reset_classified_this_boot);'
then:
- 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
@@ -22,3 +22,4 @@ mqtt:
id: mqtt_client
reboot_timeout: 0s # same for MQTT
log_topic: null # <— stops MQTT log streaming (big JSON payloads)
keepalive: 60s
+39 -39
View File
@@ -1,8 +1,8 @@
substitutions:
##############################################
############################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
###########################################################################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
@@ -30,7 +30,7 @@ substitutions:
base_interval_hours: "23" # Base interval in hours
random_offset_max_minutes: "59" # Max random offset in minutes
#############################################
###########################################################################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
@@ -38,13 +38,13 @@ substitutions:
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
###########################################################################################
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
power_save_mode: none # https://esphome.io/components/wifi.html#wifi-power-save-mode
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
@@ -63,60 +63,60 @@ wifi:
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
###########################################################################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
###########################################################################################
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
#- platform: web_server # Uncomment if you want to be able to do OTA with the web interface
#############################################
###########################################################################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
###########################################################################################
safe_mode:
#############################################
###########################################################################################
# Network
# global configuration for all types of networks
# https://esphome.io/components/network.html
#############################################
###########################################################################################
network:
enable_ipv6: ${ipv6_enable}
#############################################
##########################################################################################
# Interval
# Restart Networking every x hours + rand mins
# This ensure that the device is connected to the best AP
#############################################
script:
- id: random_reconnect
mode: restart
then:
- lambda: |-
// Compute total delay: base hours + random offset minutes
uint32_t extra;
#if defined(ESP32)
// ESP32 (both Arduino & IDF builds) uses esp_random()
extra = esp_random() % (${random_offset_max_minutes} + 1);
#elif defined(ESP8266)
// ESP8266 Arduino core
extra = os_random() % (${random_offset_max_minutes} + 1);
#else
// Fallback to esp_random() on other platforms
extra = esp_random() % (${random_offset_max_minutes} + 1);
#endif
uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
// Delay inside lambda (blocks script execution but OK for reconnect timing)
delay(total_s * 1000);
- logger.log: "network_check: performing reconnect"
- wifi.disable: {}
- delay: 1s
- wifi.enable: {}
- script.execute: random_reconnect
##########################################################################################
#script:
# - id: random_reconnect
# mode: restart
# then:
# - lambda: |-
# // Compute total delay: base hours + random offset minutes
# uint32_t extra;
# #if defined(ESP32)
# // ESP32 (both Arduino & IDF builds) uses esp_random()
# extra = esp_random() % (${random_offset_max_minutes} + 1);
# #elif defined(ESP8266)
# // ESP8266 Arduino core
# extra = os_random() % (${random_offset_max_minutes} + 1);
# #else
# // Fallback to esp_random() on other platforms
# extra = esp_random() % (${random_offset_max_minutes} + 1);
# #endif
# uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
# ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
# // Delay inside lambda (blocks script execution but OK for reconnect timing)
# delay(total_s * 1000);
# - logger.log: "network_check: performing reconnect"
# - wifi.disable: {}
# - delay: 1s
# - wifi.enable: {}
# - script.execute: random_reconnect
-126
View File
@@ -1,126 +0,0 @@
substitutions:
##############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ".local"
# Automatically add the mac address to the name
# eg so you can use a single firmware for all devices
add_mac_suffix: "false"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_dns1
static_ip_dns2: !secret ha_wifi_dns2
# Network reconnect every x hours to ensure best access point
base_interval_hours: "6" # Base interval in hours
random_offset_max_minutes: "59" # Max random offset in minutes
#############################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
networks:
- ssid: "vega_control_1"
password: "3Kd#vQBP8RDc"
priority: 1.0
- ssid: ${wifi_ssid}
password: ${wifi_password}
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
priority: 0.5
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
dns2: ${static_ip_dns2}
use_address: ${local_static_ip_address} # required when any network uses manual_ip
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${device_name} AP
password: ${fallback_ap_password}
ap_timeout: 10min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:
#############################################
# Network
# global configuration for all types of networks
# https://esphome.io/components/network.html
#############################################
network:
enable_ipv6: ${ipv6_enable}
#############################################
# Interval
# Restart Networking every x hours + rand mins
#############################################
script:
- id: random_reconnect
mode: restart
then:
- lambda: |-
// Compute total delay: base hours + random offset minutes
uint32_t extra;
#if defined(ESP32)
// ESP32 (both Arduino & IDF builds) uses esp_random()
extra = esp_random() % (${random_offset_max_minutes} + 1);
#elif defined(ESP8266)
// ESP8266 Arduino core
extra = os_random() % (${random_offset_max_minutes} + 1);
#else
// Fallback to esp_random() on other platforms
extra = esp_random() % (${random_offset_max_minutes} + 1);
#endif
uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
// Delay inside lambda (blocks script execution but OK for reconnect timing)
delay(total_s * 1000);
- logger.log: "network_check: performing reconnect"
- wifi.disable: {}
- delay: 1s
- wifi.enable: {}
- script.execute: random_reconnect
@@ -1,81 +0,0 @@
substitutions:
##############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ".local"
# Automatically add the mac address to the name
# eg so you can use a single firmware for all devices
add_mac_suffix: "false"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_gateway
#############################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${device_name} AP
password: ${fallback_ap_password}
ap_timeout: 10min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:
#############################################
# Network
# global configuration for all types of networks
# https://esphome.io/components/network.html
#############################################
network:
enable_ipv6: ${ipv6_enable}
-1
View File
@@ -1 +0,0 @@
<<: !include ../secrets.yaml
+73 -86
View File
@@ -1,26 +1,58 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
##########################################################################################
# Debug helpers (loop time / heap / reset info)
debug:
update_interval: ${local_update_interval}
sensor:
- platform: uptime # Uptime for this device in seconds
name: "Uptime (s):"
update_interval: ${local_update_interval}
id: uptime_sensor
entity_category: "diagnostic"
- platform: wifi_signal # Wifi Strength
name: "Wifi (dB):"
id: wifi_signal_db
update_interval: ${local_update_interval}
entity_category: "diagnostic"
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi (%):"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "% Max"
entity_category: "diagnostic"
device_class: ""
# - platform: uptime # Uptime for this device in seconds
# name: "Uptime (s):"
# update_interval: ${local_update_interval}
# id: uptime_sensor
# entity_category: "diagnostic"
# - platform: wifi_signal # Wifi Strength
# name: "Wifi (dB):"
# id: wifi_signal_db
# update_interval: ${local_update_interval}
# entity_category: "diagnostic"
# - platform: copy # Reports the WiFi signal strength in %
# source_id: wifi_signal_db
# name: "WiFi (%):"
# filters:
# - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
# unit_of_measurement: "% Max"
# entity_category: "diagnostic"
# device_class: ""
# Free heap via debug (replaces template-based ESP.getFreeHeap if you prefer)
- platform: debug
free:
name: "Free Heap"
entity_category: "diagnostic"
# Loop time via debug (replaces broken template loop time)
- platform: debug
loop_time:
name: "Loop Time"
entity_category: "diagnostic"
# If youd rather keep the legacy heap sensor, uncomment below and
# delete the debug "free" block above to avoid duplicates:
# - platform: template
# name: "${friendly_name} Free Heap"
# unit_of_measurement: "B"
# update_interval: 30s
# entity_category: "diagnostic"
# lambda: |-
# return (float) ESP.getFreeHeap();
# Only works with esp8266
#- platform: adc
@@ -29,11 +61,11 @@ sensor:
# id: vcc_voltage_sensor
# entity_category: diagnostic
binary_sensor:
- platform: status
name: "Network Status"
icon: mdi:check-network-outline
entity_category: diagnostic
#binary_sensor:
# - platform: status
# name: "Network Status"
# icon: mdi:check-network-outline
# entity_category: diagnostic
##########################################################################################
# Text Sensors
@@ -46,6 +78,7 @@ text_sensor:
- platform: version
name: "Version:"
entity_category: "diagnostic"
- platform: wifi_info
ip_address:
icon: mdi:ip-network
@@ -59,37 +92,12 @@ text_sensor:
name: "MAC Address:"
icon: mdi:network-pos
entity_category: diagnostic
- platform: uptime # Uptime for this device human readable
name: "Uptime:"
icon: mdi:clock-start
update_interval: ${local_update_interval}
entity_category: "diagnostic"
- platform: template
name: "Last Reset Reason"
update_interval: 30s
entity_category: diagnostic
lambda: |-
#if defined(USE_ESP8266)
return { ESP.getResetReason().c_str() };
#elif defined(USE_ESP32)
auto r = esp_reset_reason();
switch (r) {
case ESP_RST_POWERON: return { "Power-on" };
case ESP_RST_EXT: return { "External pin" };
case ESP_RST_SW: return { "Software reset" };
case ESP_RST_PANIC: return { "Exception/Panic" };
case ESP_RST_INT_WDT: return { "Interrupt WDT" };
case ESP_RST_TASK_WDT: return { "Task WDT" };
case ESP_RST_WDT: return { "Other WDT" };
case ESP_RST_DEEPSLEEP: return { "Deep sleep wake" };
case ESP_RST_BROWNOUT: return { "Brownout" };
case ESP_RST_SDIO: return { "SDIO" };
default: return { "Unknown" };
}
#else
return { "Unknown" };
#endif
###################################################################################################
# Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds
@@ -118,44 +126,23 @@ text_sensor:
# }
# icon: mdi:clock-start
# - platform: template
# name: "Uptime (Days)"
# entity_category: diagnostic
# lambda: |-
# int seconds = (id(uptime_sensor).state);
# int days = seconds / (24 * 3600);
# seconds = seconds % (24 * 3600);
# int hours = seconds / 3600;
# seconds = seconds % 3600;
# int minutes = seconds / 60;
# seconds = seconds % 60;
# if ( days > 3650 ) {
# return { "Starting up" };
# } else if ( days ) {
# return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else if ( hours ) {
# return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else if ( minutes ) {
# return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
# } else {
# return { (String(seconds) +"s").c_str() };
# }
# icon: mdi:clock-start
##########################################################################################
# BUTTONS
# Diagnostic buttons, activated if needed in HA
##########################################################################################
button:
- platform: safe_mode
name: "Safe Mode Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: restart
name: "Restart:"
entity_category: "diagnostic"
disabled_by_default: true
- platform: factory_reset
name: "FACTORY RESET:"
entity_category: "diagnostic"
disabled_by_default: true
#button:
# - platform: safe_mode
# name: "Safe Mode Restart:"
# entity_category: "diagnostic"
# disabled_by_default: true
#
# - platform: restart
# name: "Restart:"
# entity_category: "diagnostic"
# disabled_by_default: true
#
# - platform: factory_reset
# name: "FACTORY RESET:"
# entity_category: "diagnostic"
# disabled_by_default: true
+12
View File
@@ -1,3 +1,6 @@
substitutions:
local_update_interval: 30s
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
@@ -16,6 +19,15 @@ sensor:
update_interval: ${local_update_interval}
entity_category: diagnostic
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "WiFi (%):"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "% Max"
entity_category: "diagnostic"
device_class: ""
binary_sensor:
- platform: status
name: "Network Status"
+7 -7
View File
@@ -1,8 +1,8 @@
##############################################
############################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace
# these with the values (in quotes)
#############################################
###########################################################################################
substitutions:
timezone: "Pacific/Auckland"
sntp_update_interval: 6h # Set the duration between the sntp service polling
@@ -11,12 +11,12 @@ substitutions:
sntp_server_2: !secret ntp_server_2
sntp_server_3: !secret ntp_server_3
#############################################
###########################################################################################
# Real time clock time source for ESPHome
# If it's invalid, we fall back to an internal clock
# https://esphome.io/components/time/index.html
# https://esphome.io/components/time/sntp
#############################################
###########################################################################################
time:
- platform: sntp
id: sntp_time
@@ -53,14 +53,14 @@ time:
text_sensor:
# Creates a sensor showing when the device was last restarted
- platform: template
name: "Last Restart"
name: "Time: Last Restart"
id: device_last_restart
icon: mdi:clock
entity_category: diagnostic
#device_class: timestamp
- platform: template
name: "Internal Time"
name: "Time: Internal Time"
id: time_text
update_interval: "1min"
entity_category: diagnostic
@@ -69,7 +69,7 @@ text_sensor:
return { time_text };
- platform: template
name: "Time Sync Status"
name: "Time: Sync Status"
id: time_sync
update_interval: "1min"
entity_category: diagnostic