According to the documentation, the location must be a comma-separated string. I am trying to concatenate lat and lon using a JSONPATH expression but that throws an error:
16:37:45.369 [WARN ] [tt.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: Invalid path 'concat($.lat$,",",.lon)' in '{"_type":"location","acc":83,"alt":154,"batt":60,"conn":"w","inregions":["Home"],"lat":XX.XXX,"lon":Y.YYY,"t":"u","tid":"1","tst":1603463865,"vac":2,"vel":1}'
Is there any way to map that json I receive to a Location item?
I’ve never seen a JSONPATH in OH like that. I do know that OH does not support full JSONPATH and perhaps concat is not supported. All I can recommend is to either use a Rule or use the GPSTracker add-on which works with OwnTracks natively without MQTT.
You might use a javascript transformation to parse JSON, pull out two bits, and stick them together. You do have to return a single string, but that’s fine here.
Lets assume you have an item named mqttPositionRaw that has that json string in it. You also have a location item MY_location
You can have a Rule something like
rule "Mqtt Postion Parse"
when
Item mqttPositionRaw changed
then
val String json = (mqttPositionRaw.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)
MY_location.postUpdate(new PointType(lat + "," + lon))
}
end