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?