Question about MQTT Device Tracker

Dear experts,

I am struggling with MQTT setup in Home Assistant and make it work. I am failing to understand exactly how the device_tracker component like owntracks or mqtt device tracker works!

Following the documentation and the lot of Googling, so far I have understood that to work with MQTT, I need a broker first then mobile app like owntracks(or any mqtt client) which can send location update to the broker then hass as a client will pick the information and set the user’s location. Sounds pretty simple but in reality, it never worked. Specially I didn’t get the idea of known_devices manipulation part totally.

More to my confusion, there is a mqtt device_tracker component which I really didn’t understand will work with what ?

Currently, my Netgear component works good but it has some drawbacks like if the users are using 4G for a bad WiFi service, then the status is obviously not reflected correctly and real trouble is lot of automation process just screwed up :frowning: I myself can avoid that knowing what automation or what system is not going to work if I switch to 4G. But it seems odd if I force others to stick to the WiFi because my automated light wont come up in the evening :slight_smile:

However, long story short, can anyone please explain a bit clearly for a novice like me how to add any of the MQTT system (device_tracker ) so that it will update the location based on phone location using any system e.g. OwnTracks.

I am trying to install the broker in my rpi (running hassbian) and getting some error (following the instruction from Owntracks) but I believe I can get away with those errors by searching net. So, this point of time, not willing to bother the experts with this silly thing. Rather, it would be a lot of help if anyone provide me a clear steps how to add the mqtt device_tracker in hass.

This MQTT component is pretty important for me due to another fact that I already had ordered a lot of arduino and relevant kits to follow some of the mysensors projects inspired by the crazy good project of @Mihai.

Best Regards

Hi,

Novice here. I am working through the same setup, and wanted to collaborate on this and understand where you are having issues

The link below relates to your setup. I will be tracking changes on other devices via MQTT. I am not following where you are stuck. Did you follow any of these links? I am working through the guides at the moment.


Thanks a lot @akaribasic for asking to help.

I am stuck at understanding the concept completely. And yes I configured following the same link you had provided me. Okay let me clarify what I have done so far…

Step 1: Installed mosquitto broker in the same pi where hass is installed. Testes with basic commands like mosquitto_pub/sub.

Step 2: Followed the first link you had provided to integrate mqtt inside hass. But didnt understand clearly what this step is doing exactly ? Is it subscribing hass to the broker ? If this is the case, then what topic it is subscribed to ?

Step 3: Installed Owntracks in my Android phone and edited the configuration yaml file to include the device_tracker owntracks platform.

Step 4: Configure the owntracks app in phone and then it can’t connect to the private broker I had specified.
… From owntracks perspective, this is the end. I tried several times the same thing but no success. However, as I was reading few other documents, they mentioned to add a username in mqtt config file which I didn’t do. Should this be an issue if I also disabled authentication in owntracks settings ?

Okay second part, after failing with the owntracks device_tracker, tried to work with some other available setup. Then I found the mqtt device_tracker which I didn’t understand at all how this should work…Please find the link here…

What app should publish the location or is it a part of some other setup ?

Regards

I had problems using owntrack (mqtt) , could take upto 15 mins to update my location to the MQTT server and sometime the wrong location.

In the end i used the Android App Tasker to publish a MQTT message that looks like an Owntrack Message. I still used the owntrack component within HASS to subscribe to the devices i want to monitor. The battery level is also included in the tasker app and inserted into the MQTT message.
I setup up a geo fence within Tasker for my home, a radius of 30m.
The MQTT is received via the MQTT server and processed within HASS within seconds and the lights turn on as i open the door etc… :slight_smile:

Therefore HASS works ok , it just the external feed. You could be able to replicate the MQTT message to feed directly into HASS

refer :
https://www.reddit.com/r/homeautomation/comments/4iaxi9/augmenting_location_reporting_with_tasker_and/

check out Bens video too

1 Like

Thanks a lot @leeb98 . But mate to me you are talking some alien language :yum:

Jokes apart, I had read about the possibility of tasker and mqtt combination into hass… the slogan is kind of nothing is impossible… But, that is the last resort for me to try out if there is really no other means available.

However, your reply actually answered one of my question already, tasker is the missing piece which can be used to send the location message via MQTT and hass would be updated if MQTT device_Tracker is being used… Is that so ? okey dokey… that kinda make sense…

Thanks a lot again for the reply…

“used to send the location message via MQTT”
yes , refer previous link

"hass would be updated if MQTT device_Tracker is being used… "
yes , i got owntracks working and copies the message details and used the info from the previous link… it was basic a copy and paste to my andriod device (used pushbullet to get it from PC to Nexus)

my message received on the server
{"_type": “location”,“acc”: 54,“batt”: 57,“lat”: -**.21390282,“lon”: ***.97779766,“t”: “a”,“tid”: “nexus6”,“tst”: 1475816138}

do not over complicate things , just break it down into small pieces. Sorry old programmer coming out in me lol

for example:

  1. use a mqtt client to talk to MQTT and post fake message and get HASS working.
  2. setup tasker to post a fake MQTT message to the MQTT server , and then onto HASS
  3. read up on extracting or using tasker variables and merging them in to a string , there is also a split variable function (location) into two string variable ( ie long and lat)
  4. post a real message via tasker
  5. add a geo fence and uses the real message from above

i’m away for 4 days , but if you need examples of how to setup tasker i will post when i get back

note: i just changed the lat figure during testing to move outside my home geo fence …

1 Like

Thanks a lot for your detailed reply. Now I am feeling tasker needs a second chance… I will update how it goes…

Not sure if this will help you, but I followed the guidance here and installed mosquitto
Im running ubuntu server with HASS - no tasker
https://www.digitalocean.com/community/questions/how-to-setup-a-mosquitto-mqtt-server-and-receive-data-from-owntracks

I then installed owntracks on my mobile device and gave it the details it needs to send messages to my mosquitto server.
If you then add MQTT to your configuration.yaml (MQTT - Home Assistant) with correct credentials etc… you should be able to see your phone reporting into it.
Then, you can check the MAP on your HASS server, and you should see yourself on there.

This guy, has some good tutorials on this (and other things)

It took me a good few hours to get this working for mine and my wifes phone, but once you get it, it works brilliantly.

Persist, and youll get there :slight_smile:

Hope this helps

2 Likes

Thanks @elPaulio… Your provided link is a good one… Though, it wasn’t fixed straightway, after several times installing/uninstalling and tinker with the mosquitto config file and the app, finally it worked.

Interestingly, when it works, its awesome, simply awesome! I still have some confusion though. I have two zones configured in my setup, but it looks the owntracks reported accuracy doesn’t meet the criteria of zone, hence is not updating the zones very reliably.

The confusion is with the usage of two device tracker simulatanously (in my case Netgear and Owntracks). The known_devices.yaml file is filled with two entries one from Netgear component another from owntracks component; I then followed the documentation of owntracks to fill the _ entry. After this part, two issues arise, one is a warning that reports that duplicated entries found, second is there is two entity_id to represent a device now, I am not sure what entity should I use to show in the frontend. So, I configured the group to show owntracks_device entity_id for showing my location and Netgear entity_id to represent my other users. Can anyone suggest here ?

And last thing is, as I went through a lot of hassle and good amount of time to set this thing properly, I would like to write up a summary steps for future reference for the novice like me…

Summary Steps:

Assumptions:

Home-assistant is running on raspberry-pi and the OS is very recent hassbian.

  1. Install Mosquitto-Server in Raspberry-pi either by following these two commands:

sudo apt-get install mosquitto
sudo apt-get install mosquitto-client

Or completely following the link provided in step 2. In my case, I finally installed in this way as I was having trouble to auto start mosquitto server by following the steps mentioned in the post.

  1. Then configure the mosquitto server by following the link provided by @elPaulio ( Question | DigitalOcean ). If more than one person is going to use this setup, then create users accordingly but in this case the command should be a bit different (omit -c switch). e.g. mosquitto /etc/mosquitto/pwfile yourusername instead of mosquitto /etc/mosquitto…

Note: If step 1 is followed, only the user creation part,config file creation and Testing part should be copied.

  1. For hassbian OS, MQTT is disabled, expert Linux users might do it differently/accurately but I did it whatever I understood :slight_smile: remove the mosquitto.override by sudo rm /etc/init/mosquitto.override

  2. Test the MQTT setup by mosquitto_pub/sub command , reference would be found in the link.

  3. If all good, then configure the home-assistant configuration yaml file by following the mqtt component and. This configuration will set hass as a mqtt client. Restart the machine which should auto start mosquitto server and hass server if all is well so far. And you shouldn’t see any mqtt related error in the log.

  4. Now time to install the owntracks app in device, I found the app configuration is somewhat clumsy. So, it’s worth a few words. In the app configuration, go to mqtt private mode and fill in the host, port [uncheck websocket], in Identification fill in user/pass with the device ID. In security, unless you have set up certificates to use, just uncheck TLS (I found this damn thing auto enabled itself if just clicked which causes a lot of trouble, so make sure it is unchecked). Then in this configuration window, you should see a notification (connected/not connected) if clicked the tick symbol. Then go back , you are good to go for the owntracks configuration in hass now.

  5. In hass configuration under device_tracker, follow the owntracks component in the documentation, it should be straight forward. However, if you modify some part e.g. waypoint: True then must fill up the Waypoint whitelisting entities. Those entities should be the mqtt usernames exactly you created during mosquitto_password setup. Time to restart hass once again.

  6. Now time to check the known_devices.yaml and look for the entry similar to “user_device”, if you didn’t find it yet, try to manually push a notification from the app by pressing the up arrow button in the home page. Once you found the entry, all good unless you have another entry with the same device with under some other device_tracker (e.g. Netgear/NMAP), in that case dont remove the entries rather copy the MAC address from the previous entry to the blank field of new entry. Time to restart hass one more time.

  7. If you had followed so far, the next part is the easiest. Check for the entity_ID in hass /dev-state. Look for a new entry like device_tracker.username_deviceid. If there is one, just add this entity to show in the front end. If no default_view is configured, it should be shown automatically, if configured, you already know how to show it in frontend, so not going further in this part.

  8. Some handy commands:

To manually start and test the server in case auto start is not happening:

sudo mosquitto -c /etc/mosquitto/mosquitto.conf
sudo mosquitto_sub -h server_ip_address -v -t owntracks/# -u username -P password

To create and/or update password of a single user:

sudo mosquitto_passwd -c /etc/mosquitto/passwd username

To add another user:

sudo mosquitto_passwd /etc/mosquitto/passwd username

Hopefully, this steps would save some time for the future novices like me who is roaming like a headless chicken :slight_smile:

Thanks all for your responses… You guys really rock.

ElPaulio

What sort of update frequency do you run OwnTracks in? I tried it with the recommended “Significant location change mode” on IOS and the updates did not happen fast enough (entering the home zone) to make this useful.

@tarikul
Great steps. and yes, Owntracks is great
Your question, using more than one tracker?

I dont have this set up, as I find that Owntracks works very well for myself and the wife with just a few zones. Work, and Home. But it says you can do it, its just a matter of putting the MAC address into the owntracks device, and not the netgear device

@Dropbear

Mine is set to 900 seconds in the Android app
Note, Android.

Im not sure about iOS, presumably the actual app is identical. however, I have seen somewhere that iOS puts its radio and/or wlan? to sleep after certain amounts of inactivity and this can cause a background process to become suspended. It doesnt sound like the issue, as you seem to have it reporting successfully, just not fast enough. I guess youve played with the ‘Locator’ settings? (Android, Preferences -> Advanced)
Im not much help there, I own zero apple devices, may be worth a search on the good old internet for this type of thing

Guys,

Using owntracks for couple of days now. It’s really good when works properly. In fact, I removed other tracker configuration (Netgrar/Nmap for my case) completely. However, there are some caveats which I would like to ask the community if someone has some easy fix…

First: the accuracy parameter, Problem is if I set it less than 500, most of the time, hass ignores the update as the accuracy requirement doesn’t meet. And if I set it as wild as 1000m, it covers the other defined zone in my case, so isn’t very effective either. So, does anyone have a suggestion for the right/optimal spot ?

Second: I configured waypoints, my thought was, if these waypoints are triggered then other trigger(automatic timed update which can be very battery hungry if configured with low intertval) is not required to update hass. I am not sure, if this is the case really. Can anyone explain the behavior please?

Third: I saw some people were talking about remote commands to get the update in hass instead of timed update. Can anyone please briefly suggest the procedure, I was unable to understand it clearly.

Finally: To my thinking, the ideal solution with owntracks would be timed remote command (May be 15min or so) with owntracks reporting interval is set to 30 min or more. But whenever waypoints are triggered, it should notify hass. Is it possible to achieve ?

Thanks