Openhab2 Version: (2.3.0-1)
I have the following rule:
rule "Get Data from vzlogger"
when
Time cron "0/1 * * * * ?"
then
var String json = sendHttpGetRequest("http://vzlogger:8080")
var String bezug_1 = transform("JSONPATH", "$.data[0].tuples[0][1]", json)
var String einspeisung_1 = transform("JSONPATH", "$.data[2].tuples[0][1]", json)
var String bezug_2 = transform("JSONPATH", "$.data[1].tuples[0][1]", json)
var String einspeisung_2 = transform("JSONPATH", "$.data[3].tuples[0][1]", json)
var String test5 = transform("JSONPATH", "$.data", json)
logInfo("Test5", test5)
sendCommand(StromZaehler_Bezug_1, DecimalType.valueOf(bezug_1))
sendCommand(StromZaehler_Einspeisung_1, DecimalType.valueOf(einspeisung_1))
sendCommand(StromZaehler_Bezug_2, DecimalType.valueOf(bezug_2))
sendCommand(StromZaehler_Einspeisung_2, DecimalType.valueOf(einspeisung_2))
end
But it doen’t work. Even test5 isn’t returning the parsed json subsequence, but the full json string. What am i doing wrong?
My json string:
{ “version”: “0.6.1”, “generator”: “vzlogger”, “data”: [ { “uuid”: “0eff247c-0126-4fe4-932e-31a511ec3f1d”, “last”: 1532895484257, “interval”: -1, “protocol”: “d0”, “tuples”: [ [ 1532895466613, 0.496 ] ] }, { “uuid”: “e17bee37-102e-443e-98dc-18593f908bd1”, “last”: 1532895484315, “interval”: -1, “protocol”: “d0”, “tuples”: [ [ 1532895466662, 15187.200000000001 ] ] }, { “uuid”: “41b95812-3c4f-451e-879e-41be8eb098e3”, “last”: 1532895491277, “interval”: -1, “protocol”: “d0”, “tuples”: [ [ 1532895473743, 0 ] ] }, { “uuid”: “5700f7fa-4d99-4f92-afb4-5e41a0f57727”, “last”: 1532895491332, “interval”: -1, “protocol”: “d0”, “tuples”: [ [ 1532895473791, 37168 ] ] } ] }
parsed with jsonpath.com every parser should work…