-
-
Notifications
You must be signed in to change notification settings - Fork 500
Expand file tree
/
Copy pathmqtt_status.yaml
More file actions
95 lines (90 loc) · 3.72 KB
/
Copy pathmqtt_status.yaml
File metadata and controls
95 lines (90 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
######################################################################
# @CCOSTAN - Follow Me on X
# For more info visit https://www.vcloudinfo.com/click-here
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
# -------------------------------------------------------------------
# MQTT Broker Monitoring - Broker reachability + remediation handoff
# Probes local MQTT broker TCP health and escalates failures to Spook + Joanna.
# -------------------------------------------------------------------
# Notes: Probe target is pinned to docker_10 host broker endpoint 192.168.10.10:1883.
# Notes: `binary_sensor.mqtt_status_raw` is `on` when probe returns `open`.
# Notes: Creates/clears Spook repair issue `mqtt_broker_unreachable`.
######################################################################
command_line:
- binary_sensor:
name: MQTT Status Raw
unique_id: mqtt_status_raw
command: >-
/bin/bash -c "(echo > /dev/tcp/192.168.10.10/1883) > /dev/null 2>&1 && echo open || echo closed"
payload_on: "open"
payload_off: "closed"
scan_interval: 60
template:
- binary_sensor:
- name: MQTT Broker Problem
unique_id: mqtt_broker_problem
device_class: problem
state: >-
{{ states('binary_sensor.mqtt_status_raw') | lower in ['off', 'unknown', 'unavailable'] }}
automation:
- id: mqtt_open_repair_on_failure
alias: MQTT - Open Repair On Failure
description: Open a Spook Repair issue and dispatch Joanna when broker health is down.
mode: single
trigger:
- platform: state
entity_id: binary_sensor.mqtt_broker_problem
to: "on"
for: "00:03:00"
action:
- variables:
broker_endpoint: "192.168.10.10:1883"
mqtt_raw_state: "{{ states('binary_sensor.mqtt_status_raw') }}"
issue_id: "mqtt_broker_unreachable"
trigger_context: "HA automation mqtt_open_repair_on_failure (MQTT - Open Repair On Failure)"
- service: repairs.create
data:
issue_id: "{{ issue_id }}"
title: "MQTT broker unreachable"
severity: "warning"
persistent: true
description: >-
Home Assistant detected MQTT broker connectivity failure.
broker_endpoint: {{ broker_endpoint }}
mqtt_status_raw: {{ mqtt_raw_state }}
- service: script.send_to_logbook
data:
topic: "MQTT"
message: >-
MQTT broker appears down at {{ broker_endpoint }}. Spook repair opened and Joanna remediation requested.
- service: script.joanna_dispatch
data:
trigger_context: "{{ trigger_context }}"
source: "home_assistant_automation.mqtt_open_repair_on_failure"
summary: "MQTT broker endpoint is unreachable"
entity_ids:
- "binary_sensor.mqtt_status_raw"
- "binary_sensor.mqtt_broker_problem"
diagnostics: >-
issue_id={{ issue_id }},
broker_endpoint={{ broker_endpoint }},
mqtt_status_raw={{ mqtt_raw_state }}
request: "Troubleshoot and resolve MQTT broker reachability if possible."
- id: mqtt_clear_repair_on_recovery
alias: MQTT - Clear Repair On Recovery
description: Clear the Spook Repair issue once broker health is stable again.
mode: single
trigger:
- platform: state
entity_id: binary_sensor.mqtt_broker_problem
to: "off"
for: "00:02:00"
action:
- service: repairs.remove
continue_on_error: true
data:
issue_id: "mqtt_broker_unreachable"
- service: script.send_to_logbook
data:
topic: "MQTT"
message: "MQTT broker recovered at 192.168.10.10:1883. Spook repair cleared."