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": "",
  "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"
		Item position_stajon_raw changed or
		Item position_stajon_raw received update
		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)
			location_stajon.postUpdate(new PointType(lat + "," + lon))
			position_stajon_accuracy.postUpdate(new DecimalType(acc))
			position_stajon_battery.postUpdate(new PercentType(batt))

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