From b34d601ffdcb38419c101266f6e3aa06046ced27 Mon Sep 17 00:00:00 2001 From: Artem Sheremet Date: Sat, 15 Mar 2025 20:50:05 +0000 Subject: [PATCH] Add MQTT connection uptime sensor To debug network connectivity issues. --- templates/mqtt.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/templates/mqtt.yaml b/templates/mqtt.yaml index abddde6..a63cc04 100644 --- a/templates/mqtt.yaml +++ b/templates/mqtt.yaml @@ -10,3 +10,15 @@ mqtt: # No point in publishing NaN as it will not be accepted by # HA and only generate error messages. publish_nan_as_none: true + on_connect: + - sensor.duty_time.start: mqtt_connection_uptime + on_disconnect: + - sensor.duty_time.stop: mqtt_connection_uptime + - sensor.duty_time.reset: mqtt_connection_uptime + +sensor: + - platform: duty_time + id: mqtt_connection_uptime + name: "ESP chip MQTT connection uptime" + entity_category: diagnostic + accuracy_decimals: 0