Presence with MQTT

I tried to manage the Presence with MQTT. The connection to MQTT works fine and the Item “position_stajon_raw” is filled like this:

{
  "link": "http://172.16.0.1:8080/rest/items/position_stajon_raw",
  "state": "{\"cog\":170,\"batt\":30,\"lon\":8.xxxxx,\"acc\":16,\"p\":98.83165740966797,\"vel\":36,\"vac\":3,\"lat\":49.xxxxx,\"t\":\"c\",\"conn\":\"m\",\"tst\":1488211089,\"alt\":119,\"_type\":\"location\",\"tid\":\"AN\"}",
  "type": "String",
  "name": "position_stajon_raw",
  "label": "Rohdaten: Jonathan",
  "tags": [],
  "groupNames": []
}

Now I tried to use this rule:

rule "postion_parse_stajon"
	when
		Item position_stajon_raw changed or
		Item position_stajon_raw received update
	then
		val String json = (position_stajon_raw.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)
			val String acc  = transform("JSONPATH", "$.acc", json)
			val String batt = transform("JSONPATH", "$.batt", json)
			position_stajon_latitude.postUpdate(lat)
			position_stajon_longitude.postUpdate(lon)
			location_stajon.postUpdate(new PointType(lat + "," + lon))
			position_stajon_accuracy.postUpdate(new DecimalType(acc))
			position_stajon_battery.postUpdate(new PercentType(batt))
		}
end

But the Items still empty :frowning:

Anyone with an idea

I don’t know why but after posting this - it works :see_no_evil:

1 Like