Hi,
I’ve set up MQTT and with this string:
String mqtt_Phone_Position "Phone Position" <zoom> (gGeofencing) { mqtt="<[mosquitto:owntracks/myuser/phone_dries:state:default]" }
This string is regularly updated with information in this format “_type”:“location”,“tid”:“10”,“acc”:1,“batt”:84,“conn”:“m”,“lat”:41.9166374,“lon”:4.4709139,“tst”:1504512115 :
2017-09-04 10:01:59.497 [vent.ItemStateChangedEvent] - mqtt_Phone_Position changed from {"_type":"location","tid":"10","acc":1,"batt":84,"conn":"m","lat":41.9166374,"lon":4.4709139,"tst":1504512115} to {"_type":"location","tid":"10","acc":1,"batt":84,"conn":"m","lat":41.9166374,"lon":4.4709139,"tst":1504512119}
(GPS coordinates modified for obvious reasons)
Using a rule, I wanted to transform that in a proper location-item.
This is my rule:
rule "Locatie Dries berekenen"
when
Item mqtt_Phone_Position changed
then
logInfo("OwnTracks","MQTT update")
val String json = (mqtt_Phone_Position.state as StringType).toString
val String type = transform("JSONPATH", "$._type", json)
if (type == "location") {
logInfo("OwnTracks","The rule never gets to this point")
val String lat = transform("JSONPATH", "$.lat", json)
val String lon = transform("JSONPATH", "$.lon", json)
val String acc = transform("JSONPATH", "$.acc", json)
val String batt = transform("JSONPATH", "$.batt", json)
mqtt_Phone_Latitude.postUpdate(lat)
mqtt_Phone_Longitude.postUpdate(lon)
mqtt_Phone_Location.postUpdate(new PointType(lat + "," + lon))
mqtt_Phone_Accuracy.postUpdate(new DecimalType(acc))
mqtt_Phone_Battery.postUpdate(new PercentType(batt))
}
end
For some reason, the rule never gets to the second loginfo-statement. But type = location, right?
The JSONPATH transformation has been installed via PaperUI.
What am I missing?