Good morning at all, I’m new to openhab.
I just installed on Raspberry Pi.
I would like to read every hour an HTTP service that returns a JSON string.
The string contains an array and I want the last value (the most recent one).
I created insertion in the “items” file and then a transformation into the “rules” file.
Below the entries:
ITEMS:
String Sensor “My_Sensor” {http = "<[url? Param1=%1$tY-%1$tm-%1$tdT%1$tH:00¶m2=%1$tY-%1$tm-%1$tdT%1$tH:59:60000:JSONPATH($.Array[(@.Length-1)])]}
RULES:
Import java.lang.String
Rule “Sensor1"
When
Time cron “0 0/1 * 1/1 *? *“
then
Var String FP_data = My_Sensor.toString
Var String FP_d = FP_data.substring (FP_data.indexOf (”[”] + 1, FP_data.indexOf (”]"))
LogInfo ("— RULE — Sensor1: JSON", FP_d)
Var String v_tm = transform (“JSONPATH”, “$ .datetime_utc”, FP_d)
Var String v_l = transform (“JSONPATH”, “$ .light”, FP_d)
Var String v_batt = transform (“JSONPATH”, “$ .battery”, FP_d)
LogInfo ("— RULE — Time__", v_tm)
LogInfo ("— RULE — Light_", v_l)
LogInfo ("— RULE — Batt__", v_batt)
PostUpdate (FP_Time, v_tm)
PostUpdate (FP_Light, v_l)
PostUpdate (FP_Batt, v_batt)
end
The first problem is that the service parameters are in UTC and I’m using Local Time. How can I send UTC Time into ITEM?
Secondly,in the ITEM [ JSONPATH($.Array[(@.Length-1)])] if the response string is empty, I get an error.
How do I handle it and not send anything?
What I did is the correct parameterization?
Thank you
Matteo