MQTT, MQTTitude & OwnTracks

By using a tool like mosquitto_sub (command line) or one of the many UI tools (mqttspy etc).

I tried mosquitto_sub already (see above) and get the messages on the mosquitto server.
playing around yesterday I managed to get some information into my openhab with the current item:
Switch Loc_Home_Enzio "Home" (G_Debug, G_Location) { mqttitude="mosquitto:owntracks/mosquitto/NCOs_iPhone/event:Home" }

But according to the log generated by mosquitto_sub (I write into a file) I obviously get “enter” events switching on my items, but no “leave” events:
owntracks/mosquitto/NCOs_iPhone/event {"t":"c","tst":1447084967,"acc":65,"_type":"transition","event":"enter","lon":xxxx,"lat":xxxx,"wtst":1446458751,"tid":"ES","desc":"Home"}

Accordingly the switch items for the respective Regions will not switch off after leaving.
Is this how it supposed to be?

Additionally I got messages for waypoints I don’t quite understand:
{"_type":"waypoint","tst":1446826767,"lat":xxxx,"lon":xxxx,"rad":200,"desc":"Loc_1"}

This location is setup as a general Region, so what makes a Region to popup as a waypoint?

Not sure why you would see enter events, but not leave.

And as for the Loc_1 waypoint, I can only assume you set this up in your Owntracks app, or you have another device using the same device id?

Loc_1 is only a replacement for my real location name to hide it from the NSA :wink:
It is setup in my iPhone (no other phone used yet) the same way like all the other Regions.

So how do I know, if a Region will be handled like a “Region” (in/out) or a “waypoint” (no information about enter / leave in the message of type “waypoint”)?
Because both are setup the same, but have a different topic, there is not reliable item config possible.

Waypoint pubs are sent when a waypoint is created or edited. The transition pubs are sent when the phone enters or leaves a waypoint. The Mqttitude binding will look for transition events only, and match on the desc field. It will ignore the waypoint events.

you are right.
After I did not get a signal (enter/leave) passing through a region, I adjusted it’s radius. This triggered the “waypoint” message.
I will check on my way home, if I get the triggers (enter / leave) today.

In general the setup seems to be ok:
item:
Switch Loc_City "City" (G_Location) { mqttitude="mosquitto:owntracks/mosquitto/NCOs_iPhone/event:City" }

But it’s not reliable, because some enter / leave events are not received by mosquitto or not sent by iPhone.
Actually the events on the phone are deleted shortly after they have been triggered.
Is this normal or maybe the root cause?
A history of the events would be helpful.

Because the location switches keep staying “ON” in some cases (no leave message), I try to compensate this by rules:
rule “Location City”
when
Item Loc_City changed from OFF to ON
then
postUpdate(Loc_BSL, OFF)
postUpdate(Loc_Home, OFF)
postUpdate(Loc_Kita, OFF)
postUpdate(Ort, “in der City”)
end

But this is not how it supposed to be - or is the reliablility of receiving / sending region events a known issue?

Hi
I’m not sure about the exact topic and the current state of this thread, but for your last post


In fact there seems to be a problem with the current version of the IOS OwnTracks app with sending the notifications. To control it, you can have a look on the app about the identified region (Region: red is active, blue is inactive, or the other way round) and the sent notifications at least for an hour. For me that part works fine, if the notification was sent it will be handled by openhab
 Only problem is that it is quite often not sent :frowning: To solve this problem I have a similar rule than you but hope for an update. Otherwise I might switch over to IFTTT


Regards
Dieter

Hi Dieter,

thanks for your response.
That’s my impression as well, that sometimes Owntracks just don’t send the transition message (it will not appear in the messaging section in owntracks accordingly).
But what do you mean by[quote=“DieterL, post:28, topic:3744”]
and the sent notifications at least for an hour
[/quote]

Is there any setting to tell Owntracks to send the message more than once if it failed?

Best regards,
Enzio

I have just been speaking to the Owntracks iOS developer and he has a new version on its way which should resolve the missing waypoint transition events.

1 Like

Hi

@ben_jones12: Great to hear


@NCO: The most obvious thing with “1 hour” is that they are removed from the list after that time. So you can’t check all events of the day when going to bed. Whether or not there are other (practical) issues I can’t say. Here is just my guess from what I know about other MQ Implementations: Usually topics were removed from the queue after a certain time (here 3600 sec => ttl attribute displayed in the messages in the app). The reason is to prevent a queue overrun. So if you didn’t get the message within this time, it is not available anymore (shouldn’t be a big problem here). It might well be that this tab does not display messages that were sent by the phone, but messages that were currently available in the queue, problably filtered by some attributes


Regards
Dieter

I am experiencing similar issues with the Owntracks application on Android. I get status updates, including my phone battery and Location. But, the switch is not triggered when I enter, or leave the geofence. I use the new syntax.

Any idea how to solve this?

Hi Dominic

For me, this works fine again but I’m using the IOS app and do not know the Android version. If it behaves similar you should see the geofence status in the region tab of the app, as well as the messages (see my last post). If this happens you might check the events on the server by using the commandline subscriber (mosquitto-sub?) and redirect the output to a file to see whether or not the events were published (in my installation they don’t appear in the MQTT persistance database). If this all works there might be a problem with openhab so check the logfile for successful subscribtion or provide more infos here (e.g. your Item to receive the events).

Regards
Dieter

Hey Dieter,
i like MQTT due to enhanced privacy, therefore i won’t switch back to openpaths.

This is my running configuration:
openhab.cfg:
(Hint: the Openpaths service was just uncommented by a hashkey)

mqtt:mosquitto.url=tcp://127.0.0.1:1883
mqtt:mosquitto.clientId=openhab
mqtt:mosquitto.user=mosquitto
mqtt:mosquitto.pwd=your_password
mqtt:mosquitto.qos=2
mqtt:mosquitto.retain=false
mqtt:mosquitto.async=true

mqttitude:home.lat=51.123456
mqttitude:home.lon=6.123456
mqttitude:work.lat=51.123456
mqttitude:work.long=6.123456
mqttitude:geofence=400

default.items:

Switch	User1PresenceHome	"Handy @Home"	{mqttitude="mosquitto:owntracks/mosquitto/LGG4/event:home"}
Switch	User1PresenceWork	"Handy @Work"	{mqttitude="mosquitto:owntracks/mosquitto/LGG4/event:work"}
Switch	User2PresenceHome	"Tablet @Home"	{mqttitude="mosquitto:owntracks/mosquitto/GalaxyTABS2/event:home"}
Switch	User2PresenceWork	"Tablet @Work"	{mqttitude="mosquitto:owntracks/mosquitto/GalaxyTABS2/event:work"}

But i do not get the geofence item within the owntracks (also nown as mqttitude) application

Hi Dominic Are you sure you use the new Syntax for your system?I have defined the regions within the owntracks app. For your configuration, as far as I can see, you ask openhab for the calculation not your phone to send the events. So there are none available.You might try this as well and see what will happen (owntrack, not openpath)

[quote=“sptzdmnc, post:32, topic:3744, full:true”]
Any idea how to solve this?[/quote]

You get your phone locations and status updates, so it looks like your setup is good to go.
Maybe you should read this part of the wiki about region mode and switch to this mode from your manual mode.

This is a far more powerful mode and gives greater flexibility. It
also stops the issue of location publishes happening just before you get
close enough to ‘home’ and thus being considered outside the geofence,
and then no further updates being sent because you don’t move far enough
to trigger one.

In ‘Region Mode’ the OwnTracks apps detects when you cross a geofence
boundary and ALWAYS sends a location update (either enter or leave),
meaning openHAB should never lose track of your position.

This works without any problems in my case, all enter and leave events are published.

Edit: but don’t forget to set your locations in the owntracks app to “share”.

Ah okay. But why do I need to configure the geofence twice, in the
openhab.cfg and in the Owntracks UI? That makes no sense for me


In region mode you don’t configure the location in openhab.cfg, only in the owntracks app, see the wiki.

Thanks for your advice. Now my Geofence is working.
But, there is still one problem.
If i restart my Openhab instance the states for geofence are undefined.
I set them to OFF on start. Also, if i enter one of my three geofences, the other two were set to OFF.
But this is only a troubleshoot.

Any hints regarding this startup behaviour?
Btw: If i start my phone, or if i got a weak internet connection (Even if i connect again) the MQTT is and stays marked as disconnected.
I have to go to settings and apply the settings again, this also occurs to my waypoints.

If the device is in standby mode, i won’t get any status update. Is there any way to sync the device at least each hour, if its on AC Power maybe each 15 Minutes


I am using an Android device with the latest software.

If you set up persistence and apply the restoreOnStartup strategy, what ever values they were before OH stopped will be restored automatically.