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..b96c969 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\", \"source_type\": \"bluetooth_le\"}" \ + -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