Setting up OwnTracks with 2 MQTT (mosquitto) brokers bridged for use with the MQTT bridge for SmartThings
I successfully tied in OwnTracks to HASS and SmartThings while using authentication for external access.
The MQTT bridge doesn’t support authentication so I set up 2 MQTT instances.
Here are the steps I performed… Hopefully it saves someone else some time.
It seems to be working pretty well but if anyone sees something incorrect in my config, please let me know.
This is my first real interaction with MQTT so if anyone seems something incorrect in my config, please let me know.
Here’s a summary of my setup
2 Docker instances of MQTT
– 1 for internal use (the MQTT bridge for SmartThings - no authentication)
– 1 for external use ( with authentication - for OwnTracks)
All Docker config files are on my NAS so the docker can be destroyed with affecting my actual config files.
Docker setup for the mosquitto internal instance… no auth… for use with the mqtt bridge
docker run -ti -p 1883:1883 \
-v /volume1/data/mosquitto-int/config:/mqtt/config:ro \
-v /volume1/data/mosquitto-int/log:/mqtt/log \
-v /volume1/data/mosquitto-int/data/:/mqtt/data/ \
--name mosquitto-int -d toke/mosquitto
Docker setup for the mosquitto external instance… with auth… for use with the owntracks
docker run -ti -p 1884:1883 \
-v /volume1/data/mosquitto-ext/config:/mqtt/config:ro \
-v /volume1/data/mosquitto-ext/log:/mqtt/log \
-v /volume1/data/mosquitto-ext/data/:/mqtt/data/ \
-v /volume1/data/mosquitto-ext/etc:/etc/mosquitto \
--name mosquitto-ext -d toke/mosquitto
Here are the config files:
/volume1/data/mosquitto-int/config/mosquitto.conf
connection mosquitto-ext
persistence_file mosquitto.db
try_private true
address 10.0.0.20:1884
start_type automatic
username test
password test
notifications true
topic owntracks/# in
log_type all
log_dest file /mqtt/log/mqtt.log
log_facility 5
/volume1/data/mosquitto-ext/config/mosquitto.conf
connection mosquitto-int
persistence_file mosquitto.db
try_private true
address 10.0.0.20:1883
start_type automatic
username test
password test
notifications true
topic owntracks/# out
log_type all
log_dest file /mqtt/log/mqtt.log
log_facility 5
allow_anonymous false
password_file /etc/mosquitto/pwfile
create a password for mosquitto-ext
docker exec -it mosquitto-ext /bin/bash
cd /etc/mosquitto/
mosquitto_passwd -c /etc/mosquitto/pwfile <userID>
Config in HASS
from: https://home-assistant.io/components/device_tracker.owntracks/
# Example configuration.yaml entry
device_tracker:
platform: owntracks
max_gps_accuracy: 200
# Example in known_devices.yaml
mqttuserid_deviceid <---- <part of EntityID as seen in <hostname/dev-state>: ie: device_tracker.<this part>
name: <Name to appear on map>
mac: <MAC address>
picture:
track: yes
hide_if_away: no
OwnTracks settings - for Android
Preferences / Connection / Mode - Private MQTT
Preferences / Connection / Host
Fill out the following:
Host
Identification
Security: TLS disabled
Preferences / Connection / Identification
Authentication (enable)
Username (username entered with mosquitto_passwd command)
Password (password entered with mosquitto_passwd command
Device ID (will be used in the Entity ID in HASS)
Tracker ID (will be used for object tracking in MQTT)
Confirm messages are making it to your server
mosquitto_sub -h <hostname> -p <port> -v -t "owntracks/#" -u <username> -P <password>
Output should appears as follows:
owntracks/<username>/<Device ID> {"_type":"location","acc":22,"batt":60,"lat":<lat>,"lon":<lon>,"tid":"<Tracker ID>","tst":1472491902}
Using Tasker to monitor and restart OwnTracks when it crashes
I’ve found that OwnTracks will periodically crash so I’ve used Tasker to monitor and restart when this happens
Profile screen
Enter an interval to check for the OwnTracks process
Task screen
Task - Step 1
Task - Step 2
Task - Step 3
Task - Step 4 - (Optional but used to track when Tasker restarts OwnTracks)
Task - Step 5
Add the End If
Be sure to save you changes by backing out to Exit and Selecting “Save First”
Note: Location images do not show up on the map when the entities are home