OwnTracks - Thing definition with variable topic content

I am trying to implement presence detection by using OwnTrack.
Everything is working so far, with the exception of some warnings like:

2023-07-26 15:26:22.271 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path '$.SSID' in '{"_type":"location","acc":11,"alt":198,"batt":67,"bs":1,"cog":17,"conn":"m","lat":48.228935,"lon":17.042565,"m":2,"tid":"SL","tst":169037794

The reason is that the JSON payload is not constant and misses values when they do not make sense.

In my example, I am monitoring the two values for

“connection” with possible values “w” for WiFi" and “m” for mobile

and “SSID” which may contain the SSID of the WiFi or is not existing at all when “connection” is “m”

here is the things file content:

Thing mqtt:topic:vevedock:owntracks_sasha "OwnTracks Sasha" (mqtt:broker:4739c61702) @ "iPhones"   {
    Channels:
            Type string : connection "Connection" [ stateTopic="owntracks/openhab/sasha", transformationPattern="JSONPATH:$.conn" ]
            Type string : ssid "SSID" [ stateTopic="owntracks/openhab/sasha", transformationPattern="JSONPATH:$.SSID" ]

}
Thing mqtt:topic:vevedock:owntracks_iveta "OwnTracks Iveta" (mqtt:broker:4739c61702) @ "iPhones"   {
    Channels:
            Type string : connection "Connection" [ stateTopic="owntracks/openhab/iveta", transformationPattern="JSONPATH:$.conn" ]
            Type string : ssid "SSID" [ stateTopic="owntracks/openhab/iveta", transformationPattern="JSONPATH:$.SSID" ]

}

Is there any way to have a conditional transformation pattern in order to eliminate warnings and assign an empty value as a result?

There are definitely other solutions like getting the whole topic into a rule and parsing it there, which I would not like to do.

Good luck. I’ve been there and it never was reliable enough.

Chain a REGEX transformation in frond of the JSONPATH. Only if the REGEX matches will the message get passed on to the JSONPATH, effectively filtering out those messages that the JSONPATH can’t handle. See MQTT 2.5 M1+ How to implement the equivalent to MQTT1 REGEX filters

That is the solution, at least not getting any warnings.

What were the biggest problems you had?

So what do you use?

I am currently using a combination of several, trying to take advantage of their individual strengths and weaknesses:

Network Presence Detection: pro - rapid response to presence. con - cannot be relied upon to indicate absence because devices (especially iOS) can drop offline even if you are still present for a longer time than is useful. Also, unless you turn off private network, you keep getting a new MAC ID and hence new IP address. And it seems like some iOS update, especially for watches, turn private mode back on without being asked.

iCloud location. pro - when it works, accurate location data. con - frequent connection failures. I understand our binding uses an unsupported connection, so things get changed that require an adjustment to the binding more often than one would like. Also, location data are updated every 5 minutes, so it isn’t useful for a rapid detection. (I use Network Presence change and a garage door opening to force iCloud location updates. If you do 2 forced refreshes 20 seconds apart, the 2nd one will be almost current).

OwnTracks: pro: great when it works. con - sometimes it just doesn’t trigger. Not often, but 99% isn’t good enough. More often it fails because of a problem with the Cloud Connector to myopenhab.org upon which I rely to get the message to openHAB. (Cloud Connector has been much more reliable lately).

I have rules that consider changes to the each of the above in light of the others, considering whether inputs are stale or unavailable. But I’m not satisfied with it.

Timeliness and accuracy. It never would detect when I got home soon enough to reliably trigger anything when I arrive or leave. This was a combination between inaccuracies inherent in GPS and because of those inaccuracies the geofence for “home” had to be made unreasonable large or else I would bounce between home and away.

It also took a noticeable toll on the phone batteries.

I used to use all sorts of stuff including network hpings and OwnTracks and Tasker profiles but now I just use the Android apps’ ability to push the SSID name of the connected Wi-Fi to an Item to detect when I’m home. That has worked better than anything else I’ve ever used to the extent that I’ve dropped everything else.

If I wanted to make it a little more robust, I could use Tasker’s SSID Near profile to push a command to an Item using the openHAB plug-in. Then my phone wouldn’t have to connect to detect that I’m home, but the connection happens soon enough I’ve not needed to go outside the Android app.

I find it works much more reliably with a lot less complexity this way. All I need is one Item per person and a setting in the Android app which they have anyway. Less loss of battery on the phone also. But of course this only works with Android. I don’t know what equivalents are available on iPhone. We are an all Android house.

The hping approach can usually avoid this as it first sends a packet that causes the phone to wake up and then pings it.

Thanks.

Should I be able to do that with the openHAB iOS app?

I don’t know. It’s a separate app with a separate set of developers and capabilities. I don’t even know if Apple allows apps to even know what SSID the phone is connected to. I’m not even sure if the iOS app supports MainUI yet.

Yes, I have installed the iOS OwnTracks app and pointing to my own MQTT server. I am getting following information:

{
    "_type": "location",
    "acc": 11,
    "alt": 200,
    "batt": 50,
    "bs": 1,
    "BSSID": "cc:ce:1e:e6:c6:27",
    "cog": 166,
    "conn": "w",
    "created_at": 1690390673,
    "lat": 40.228885,
    "lon": 10.042517,
    "m": 2,
    "p": 98.821,
    "SSID": "veverickaBA",
    "t": "t",
    "tid": "SL",
    "tst": 1690383903,
    "vac": 4,
    "vel": 0
}

my “home” logic is that conn:“w” and SSID:“veverickaBA”

I’m talking about the iOS openHAB app, not OwnTracks. The openHAB Android app will update/command Items based on stuff going on on the phone, such as the call status, next alarm, SSID connected to, battery level, etc. independently of OwnTracks. I don’t have OwnTracks installed at all.