From 6ab260cde4ab9b71e53cd63bc55539a689e87c52 Mon Sep 17 00:00:00 2001 From: inukiwi Date: Wed, 27 Nov 2024 13:10:29 +0000 Subject: [PATCH 1/2] Add Home Assistant discovery --- monitor.sh | 3 +++ support/mqtt | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/monitor.sh b/monitor.sh index f37e973..2123322 100755 --- a/monitor.sh +++ b/monitor.sh @@ -206,6 +206,9 @@ for addr in "${known_static_addresses[@]^^}"; do #FOR DEBUGGING printf "%s\n" "> ${GREEN}$addr${NC} confidence topic: $pub_topic (has $is_connected to $PREF_HCI_DEVICE)" [ "$PREF_DEVICE_TRACKER_REPORT" == 'true' ] && printf "%s\n" "> ${GREEN}$addr${NC} device_tracker topic: $pub_topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH [$PREF_DEVICE_TRACKER_AWAY_STRING or $PREF_DEVICE_TRACKER_HOME_STRING]" + + #PUBLISH HOMEASSISTANT DISCOVERY CONFIG + [ "$PREF_DEVICE_TRACKER_REPORT" == 'true' ] && mqtt_homeassistant_discovery $mqtt_topic_branch $pub_topic/$PREF_DEVICE_TRACKER_TOPIC_BRANCH done # ---------------------------------------------------------------------------------------- diff --git a/support/mqtt b/support/mqtt index 624dac2..848535c 100644 --- a/support/mqtt +++ b/support/mqtt @@ -72,6 +72,21 @@ mqtt_echo(){ -q "2" 2>&1) } +# ---------------------------------------------------------------------------------------- +# MQTT HOMEASSISTANT DISCOVERY +# ---------------------------------------------------------------------------------------- +mqtt_homeassistant_discovery() { + #ADD DISCOVERY CONFIG + mqtt_error_handler $($mosquitto_pub_path \ + -I "$mqtt_publisher_identity" \ + $mqtt_version_append \ + $mqtt_ca_file_append \ + -L "${mqtt_url}homeassistant/device_tracker/$mqtt_publisher_identity/$1/config" \ + -m "{\"state_topic\": \"$2\", \"name\": \"$1\", \"payload_home\": \"$PREF_DEVICE_TRACKER_HOME_STRING\", \"payload_not_home\": \"$PREF_DEVICE_TRACKER_AWAY_STRING\", \"unique_id\": \"$1_${mqtt_publisher_identity}_monitor\"}" \ + -r \ + -q "2" 2>&1) +} + # ---------------------------------------------------------------------------------------- # CLEAR RETAINED @@ -402,4 +417,4 @@ publish_cooperative_scan_message () { } #SHOULD CLEAN? -[ "$PREF_CLEAN_MQTT" == true ] && mqtt_broker_clean +[ "$PREF_CLEAN_MQTT" == true ] && mqtt_broker_clean \ No newline at end of file From 830ad0255f4975543599b0eac7f827b2c87ef422 Mon Sep 17 00:00:00 2001 From: inukiwi Date: Wed, 27 Nov 2024 14:04:36 +0000 Subject: [PATCH 2/2] Set device tracker source to 'bluetooth_le' --- support/mqtt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support/mqtt b/support/mqtt index 848535c..b96c969 100644 --- a/support/mqtt +++ b/support/mqtt @@ -82,7 +82,7 @@ mqtt_homeassistant_discovery() { $mqtt_version_append \ $mqtt_ca_file_append \ -L "${mqtt_url}homeassistant/device_tracker/$mqtt_publisher_identity/$1/config" \ - -m "{\"state_topic\": \"$2\", \"name\": \"$1\", \"payload_home\": \"$PREF_DEVICE_TRACKER_HOME_STRING\", \"payload_not_home\": \"$PREF_DEVICE_TRACKER_AWAY_STRING\", \"unique_id\": \"$1_${mqtt_publisher_identity}_monitor\"}" \ + -m "{\"state_topic\": \"$2\", \"name\": \"$1\", \"payload_home\": \"$PREF_DEVICE_TRACKER_HOME_STRING\", \"payload_not_home\": \"$PREF_DEVICE_TRACKER_AWAY_STRING\", \"unique_id\": \"$1_${mqtt_publisher_identity}_monitor\", \"source_type\": \"bluetooth_le\"}" \ -r \ -q "2" 2>&1) }