Some MQTT OwnTracks region setup help please?

I’m trying to have OwnTracks update some presence items and can’t figure it out.

I have OwnTracks and MQTT updating well for my latitude, longitude, battery, and accuracy values so I know that my broker is setup right.

What I would like to do is simple but I have two problems, and in the end I only really need to do one but can’t get either to work, so yeah. shrug.

I simply want a switch or item to update when I enter a new region. I’m sure I had this working before I fiddled with my setup to get the location mapping working.

I think it should be as simple as:

Switch    presence_PaulHome    "Paul is at Home (OwnTracks)"    {mqtt="mosquitto:owntracks/paul/Paul/event:melrose" }

Where the region melrose is already shared and setup in the OwnTracks app.

But I have no mention of any regions in my logs, and the switch never changes.

So I tried to do it a different way by subscribing to:

String    ownTracks_PaulWaypoint    "Paul Waypoint Data [%s]"   {mqtt="<[mosquitto:owntracks/paul/Paul/waypoint/event:default]"}

And then converting the (confirmed received) JSON with:

// Owntracks Paul Waypoint description conversion

rule "OwnTracks Waypoint Paul"
  when
    Item ownTracks_PaulWaypoint changed
  then
  logInfo("MQTT", "OwnTracks waypoint updated for Paul")
    val String json = (ownTracks_PaulWaypoint.state as StringType).toString
    val String type = transform("JSONPATH", "$._type", json)
    if (type == "transition") {
      val String desc = transform("JSONPATH", "$.desc", json)
      ownTracks_PaulDesc.postUpdate(desc)
      logInfo("OwnTracks", "Paul is at " + desc)
    }
end

And finally using the item:

String    ownTracks_PaulDesc    "Paul is at [%s]" 

This should give my sitemap a simple text item which indicates which waypoint I am at. I figure I could then use another rule to determine presence state based on whether the string = whatever

I can see the waypoint JSON comes in fine, however the conversion doesn’t work. But I can’t see a problem. I’ve tried tinkering with the …postUpdate(desc) to be …postUpdate(new StringType(desc)) and so on, but nothing appears to work here.

Any tips?

You should be using the mqttitude binding, not mqtt, in your first example - this binding will parse the \event pub and handle the switch updates for you.

Thanks @ben_jones12

I really don’t recall the answer to this i’m afraid, but do I need to scour through the old openhab.cfg and edit the mqttitude section there, even though my mqtt binding is already set up?

So simple there’s no wonder I didn’t see/think of that…

@pahansen

Hi Paul,

What you are looking for is via mqtt=

String JCWayPointData "WayPoint Data %s" (persist) { mqtt="<[mosquitto:owntracks/jcid/jay-cell/waypoints:state:default]" }

That will give you the string you need to parse in your rule…

Also change transition to waypoints cause well that’s what “type” it is :wink: