various tidyups
This commit is contained in:
@@ -54,4 +54,76 @@ text_sensor:
|
||||
# }
|
||||
# icon: mdi:clock-start
|
||||
|
||||
###############################################################################
|
||||
# WIFI & MQTT CONNECT COUNTERS
|
||||
# Replicates Tasmota-style "WiFi Connect Count" and "MQTT Connect Count"
|
||||
# - Increments each time the connection succeeds.
|
||||
# - Skips counting reconnects during the first 60s after boot (uptime filter).
|
||||
# - Persists across reboots (restore_value: yes).
|
||||
###############################################################################
|
||||
|
||||
globals:
|
||||
- id: wifi_connect_count
|
||||
type: int
|
||||
restore_value: yes
|
||||
initial_value: '0'
|
||||
|
||||
- id: mqtt_connect_count
|
||||
type: int
|
||||
restore_value: yes
|
||||
initial_value: '0'
|
||||
|
||||
# Uptime sensor to use for filtering
|
||||
sensor:
|
||||
- platform: uptime
|
||||
id: uptime_seconds
|
||||
update_interval: 10s
|
||||
internal: true
|
||||
|
||||
- platform: template
|
||||
name: "WiFi Connect Count"
|
||||
id: wifi_connect_sensor
|
||||
icon: mdi:wifi
|
||||
state_class: total_increasing
|
||||
entity_category: diagnostic
|
||||
#unit_of_measurement: "connections"
|
||||
accuracy_decimals: 0
|
||||
lambda: |-
|
||||
return id(wifi_connect_count);
|
||||
|
||||
- platform: template
|
||||
name: "MQTT Connect Count"
|
||||
id: mqtt_connect_sensor
|
||||
icon: mdi:cloud-outline
|
||||
state_class: total_increasing
|
||||
entity_category: diagnostic
|
||||
#unit_of_measurement: "connections"
|
||||
accuracy_decimals: 0
|
||||
lambda: |-
|
||||
return id(mqtt_connect_count);
|
||||
|
||||
wifi:
|
||||
on_connect:
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return (id(uptime_seconds).state > 60);' # Only count if uptime > 60s
|
||||
then:
|
||||
- lambda: |-
|
||||
id(wifi_connect_count)++;
|
||||
ESP_LOGI("wifi", "WiFi reconnected, count=%d", id(wifi_connect_count));
|
||||
- component.update: wifi_connect_sensor
|
||||
|
||||
mqtt:
|
||||
on_connect:
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return (id(uptime_seconds).state > 60);' # Only count if uptime > 60s
|
||||
then:
|
||||
- lambda: |-
|
||||
id(mqtt_connect_count)++;
|
||||
ESP_LOGI("mqtt", "MQTT reconnected, count=%d", id(mqtt_connect_count));
|
||||
- component.update: mqtt_connect_sensor
|
||||
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ wifi:
|
||||
fast_connect: ${wifi_fast_connect}
|
||||
# Define dns domain / suffix to add to hostname
|
||||
domain: "${dns_domain}"
|
||||
#min_auth_mode: WPA2
|
||||
|
||||
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
|
||||
|
||||
|
||||
Reference in New Issue
Block a user