Actually you can do this yes. Seems as if the owntracks supports mqtt http://owntracks.org/booklet/tech/mqtt/. So you “just” have to make the HA-Instance and the port 1883 (if default) accessable through the internet, like with duckdns and portforwarding, and then push your location with the build in api of owntracks. Just set the broker address to your duckdns-domain and the port to 1883 (if default) and then use the yaml to read the topic out with your HA.
I was also new to MQTT and just couldn’t figure out how to use the embedded broker. Like so many things with Home Assistant, the documentation always seems to assume you have some previous knowledge on the subject and seem to be missing key bits of information… I ended up using the OwnTracks (via HTTP) component. It was a much more straightforward setup for me.
Well you can use the integrated mosquitto plugin of home assistant and just start the mqtt server. The mqtt-protocol is based on “topics”, for example there is a topic called “geolocation/mobile_device_xy/location” (depends on what you want to call it, no format given, “geolocation” would also work but then all devices will push their information in the same channel). Now you tell the HA to watch (called subscription) this topic. Every information published inside of this topic will get noticed by the HA. Same from the “client” side. You tell the OwnTracks to publish the information of its location to the same topic. Now if the client publishes the information, the server/HA notices it and triggers the desired command. If you can’t imagine that why, just imagine it like a chat channel (btw is mostly also based on websockets which is similar to mqtt). 2 people are in there. One is the server and one the client. Now if the first person writes, the second one get’s a notification and the other way around. So the server can also publish data to the channel, but the client only get’s that, if he also subscribed the topic. In other words:
subscription = receive infos from this channel (in this just the server and if needed for qos also the client)
publish = emit to the channel (in this case the client, your mobile phone or OwnTracks and if needed for the qos also the client)
So as you noticed, there are information in the channel but you can also define the flow of these with qos, means should it be pushed and the receiver has to answer to validate the publish or should it just be pushed and thats it, no guarantee of receiving by the subscribers but less traffic.
The broker address is just the port 1883 and your normal HA duckdns domain. So you just have to forward the port 1883 with your router, then it should work.
It’s getting a little clearer now, thank you for explanation.
So I added mqtt to my config file, thats all I did in the config. I’m sure there is something else I need to add. I forwarded 1883 port and added my DDNS address in the owntracks app.
It shows connected in the app.
Back on the HA it shows my phone as a badge at the top and its showing the correct GPS coordinnates, show battery level and so forth so I know its working, but how to I get it to show up on the map. Also I still don’t know where to put the topics in the config file or the app on my phone.
In owntracks I think you have to use MQTT Private in the settings and go to the configurations. There is a “pubTopicBase”, which could be the track/phone/location for example. This is the general topic where all publishes will be pushed in and then there is the subTopic, which would be for example track/phone/answer (if you use the same topic as in pubTopicBase, then the subTopic will receive the own pushed data too, so dont use the same path. You can also set sub: false if you dont need the qos>0, so if you dont need to receive anything or get answers from the server). Btw seems as if the owntracks uses 8883 by default, so you have to change that to 1883 if you are using this port. From the mqtt plugin of HA:
mqtt:
# Optional, replace port 1883 with following if you want encryption
# (doesn't really matter because broker is public)
port: 8883
Well to use the owntrack via mqtt you need to do the following I think:
Go to settings in owntrack, set it to mqtt private.
Set the host to your duckdns domain and the port to 1883.
Set the username and password, maybe the device and tracker id but I think you dont need it.
Settings inside the Owntracks App are:
Private MQTT https://my.domain.com
8883
My MQTT Auth Details
Device ID
Tracker ID
Installed my Cert from Owntracks Tools
Encryption Key under Advanced with libsodium18 installed on RPi
I’m using Zanzito as a replacement since it has a lot of other abilities to it. One I personally like is switching to a local host when on the same network since my router is screwing up NATing. With Zanzito, it just shows up in my “known_devices.yaml” file.
Are all those entries in the yaml file necessary to get this to work correctly?
The strange thing is that my daughters phone shows up on the HA map but not mine. Also since I came to work my HA will not update my phone location even though owntracks has updated to my current location.
I have put no extra code in the HA config file except for what I listed earlier and somehow its works for her phone?
So I’m beginning to think there is a different setup for Hass.io. Nothing I do seems to work. When It does work it eventually stops working. For example now I cannot get the owntracks app to connect at all. I have changed nothing, so Im’ not sure what the issue is now.
Under Status in the setting portion of the app it says,
idle The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 1.) {
"_kCFStreamErrorCodeKey" = 1;
"_kCFStreamErrorDomainKey" = 12;
}
No idea why this is happening.
I did install DDNS with encryption so would that have anything to do with it?
I have never been able to get OwnTracks working and I dont know why. I have port 1883 forwarded, I have mqtt: in my config and I have
- platform: owntracks
max_gps_accuracy: 200
in my device_tracker.yaml yet OwnTracks always says it has an error connecting. My OwnTracks config has my duckdns address, port 1883 and ‘homeassistant’ as username, and API password entered.
So I’m using Hass.io and I installed the mosquitto addon and added a username and password to the addon confid section. Then I duplicated those credentials on the owntracks app.
When I did this I got an invalid confg error on the HA main page
So I added to the config
mqtt:
broker: 192.168.1.23
which points to the HA IP address and get ride of the invalid config error.
So it connects fine now. I can actually see in the mosquitto add-on log that it is connected.
So this is what I added to the config file after I enabled the mosquitto add-on.
I thought this would be all I needed but…my phone badge would not show up though in HA…
How do I get the badge to show up in HA?
If I add another device tracker it gives me errors I guess because you cannot have two device tracker at the same time? I did fiddle around and got the badge to show up but the problem was after I edited the entry in known_devices and rebooted HA it would duplicate the same device in this case my phone.
Since I dont yet have OwnTracks working, I cant give specific details but i know for my NMAP tracker, my phone is listed in the known_devices.yaml which is where HA gets info for the frontend badge
Correct, but why is it that every time I restart HA it duplicated every entry in the known-devices file? So no matter if I turn scan new devices to false it still duplicated all entries… Drives me crazy. I’m so close to getting this to work.