Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ----------------------------------------------------------------------------------------
Expand Down
17 changes: 16 additions & 1 deletion support/mqtt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -402,4 +417,4 @@ publish_cooperative_scan_message () {
}

#SHOULD CLEAN?
[ "$PREF_CLEAN_MQTT" == true ] && mqtt_broker_clean
[ "$PREF_CLEAN_MQTT" == true ] && mqtt_broker_clean