Owntracks Presence Detection and Location Display on Google Map Tutorial

I suppose you could try different owntracks-openhab connection method… Switch owntracks connection type to http and connect to myopenhab with your login and pw, install GPStracker binding - it works like a charm and can be configured in PapearUI in few minutes… Can share more info tomorrow if you need help.

With this aproach you dont need any transformations…

Read binding info first, it is easy to understand…

Maybe double check that your mqttPositionJoshRaw item is subscribed to the correct mqtt topic?

Here is my item from the file

String mqttPositionJoshRaw "Josh's Raw Data [%s]" { mqtt="<[mosquitto:owntracks/openhabian/phone_Josh:state:default]" }

the topic is owntracks/yourMqttUsername/yourDeviceID

these two values can be found/set in owntracks app>preferences>connection>identification

What does your Map.html look like?
I received the map and the home icon. but not my positions from cell phones via myopenhab.org

this is mine…

String mqttPositionVailPhoneRaw “Vail-Phone’s Raw Data [%s]” { mqtt="<[mosquittooldskool:owntracks/aarondvail/Vail-Phone:state:default]" }

the mosquitooldskool is the broker name… and it works for the mqttitude objects…

I assume Vail-phone is your device Id in the owntracks app? If you do a mosquitto_sub on that topic then publish your location from owntracks, are you seeing the message?

yes that’s the ID and yes I see the messages

You got me stumped on this one. I’m not sure what else you could be missing.

OK, I think I figured out a bit more… the mqttitude subscribes to …Phone/event and MQTT is supposed to subscribe to …Phone. In reviewing the MQTT broker logs, it appears that the MQTT Subscription doesn’t happen, BUT it does “log in” and pings periodically… Both are using the same ACL account… I’m going to try a different acct for the MQTT and see what that does for me… will update in a couple of hours

OK, I think I’ve found the problem… versioning… I’m running OpenHAB 2.4 with the MQTT Binding version 2.4… How it handles things is a little (a whole lot) different than the previous version…

I’ve made more progress… MQTT Binding 2.4 was a little bit of a pain, but once I got it configured to connect to my MQTT host, I just needed to modify my “RAW” string like this:

`String  mqttPositionVailPhoneRaw     "Vail-Phone's Raw Data [%s]"  { channel="mqtt:topic:OpenHABClientV3:owntracks:mqttPositionVailPhoneRaw2" }`

for the MQTT Binding I had to create a thing below:

Bridge mqtt:broker:OpenHABClientV3 [host="host.redacted.com", secure=false, username="redacted", password="cmVkYWN0ZWQ=", qos=1, clientID="OpenHABClientV3"]
{
    Thing topic owntracks{
        Channels:
            Type string : mqttPositionVailPhoneRaw2     "Vail-Phone's Raw Data [%s]"  [stateTopic="owntracks/aarondvail/Vail-Phone"]
	}
}

Note: the only reason the stings end in numbers is because of troubleshooting. I could go back and remove them… but “if it ain’t broke, don’t fix it”

Now the only problem I have left is the Google Map not parsing the location correctly

actually looking at it when it loads, it appears that it is getting the location on the map as i see the pin right before it crashes… I’ll review my Map.html

UPDATE… the Map is working… I fat Fingered the API Key :expressionless:

This is great and I have been using it for some time so thank you.
I am however trying to make a minor improvement as I don’t always get the Event messages.

Looking at what owntracks sends

mqttPositionJonathanRaw changed from {"_type":"lwt","tst":1565864196} to {"_type":"location","acc":15,"alt":0,"batt":91,"conn":"w","inregions":["Home"],"lat":50.181328,"lon":-0.2540099,"tid":"1","tst":1565864416,"vac":0,"vel":0}

You have the inregions which would solve the issue if the event notification didn’t make it to the server.

so My though was modify the rules:

 rule "MqttPostionParseJonathan"
    when
    Item mqttPositionJonathanRaw changed
  then
    val String json = (mqttPositionJonathanRaw.state as StringType).toString
    val String type = transform("JSONPATH", "$._type", json)
    if (type == "location") {
      val String lat  = transform("JSONPATH", "$.lat", json)
      val String lon  = transform("JSONPATH", "$.lon", json)
      val String acc  = transform("JSONPATH", "$.acc", json)
      val String batt = transform("JSONPATH", "$.batt", json)
      val String inregions = transform("JSONPATH", "$.events", json)

and the item:

//MQTT Binding
String  mqttPositionJonathanRaw     "Jonathan's Raw Data [%s]"  { mqtt="<[mosquitto:owntracks/openhabian/Jb:state:default]" }
DateTime mqttJonathanLastUpdated     "Jonathan's last update [%1$tm/%1$td/%1$tY %1$tH:%1$tM:%1$tS]"      <clock> { mqtt="<[ mosquitto:owntracks/openhabian/Jb:state:JS(mqttitude-tstamp.js)]" }
Location   locationJonathan
String  mqttJonathanLatitude
String  mqttJonathanLongitude
String  mqttJonathanEvents
String  mqttJonathanAccuracy  "Jonathan's Accuracy [%s]"
String  mqttJonathanBattery "Jonathan's Android Battery [%s%%]" <battery>       (Phone,MQTT)
Switch jonathan_moving "Notify on motion" <siren>
Number jonathanDistanceFromHome "Miles from home [%.1f]"

However I am having little luck. Would someone be able to point me in the right direction?

Hi @iamjoshwilson

i added your maps.html to my oH and got it almost working.
Currently the zoom when everybody is at home is so far in that i just see the house and nothing else.
It´s the maxed zoom that google maps offers.
I tried to change the zoom value under map_options but no value helps.
I tried everything from 1 to 1000000…

Any ideas what i´m doing wrong?

kind regards
Michael

Hi.

How do you get more than one person with position into the map?
And how do you realize the presence timeline?

pr0

Are you aware that owntracks changed recommendation to use HTTP(S) instead of MQTT and that the gpstracker binding has replaced mqttitude to connect owntracks ?
It has a lastLocation channel to contain the position.

And are you aware that you can use this (and possibly your existing) item to display presence on a map using the “Mapview” display type in sitemap? It’s using openStreetMap data.

Hi Markus, thanks for the hint. I like the GPSTracker Binding. It’s a fast and solid solution, but I can’t use it at the moment. I struggle with my own OpenHAB Cloud.
I am not able to reach the /gpstracker/gpslogger site there. (Maybe I have to reinstall the OpenHAB Cloud, because I don’t find a way to upgrade it).
I don’t want to make my local network accessible without a OpenHAB Cloud and I don’t like to use https://home.myopenhab.org because I want to use my own servers.
Using a MQTT broker is also a good and safe solution, so I don’t understand why to use HTTPS.

Run a reverse proxy to handle authentication, too. nginx is included with openHABian.

how can I do it? Is it possible to give a little detailed explanation on this subject? i’m new to this.