Im dont understand how to recieve JSON data. Here code:
rule "Request data from narodmon"
when
Time cron "0/30 * * * * ?"
then
var String json = ("http://narodmon.ru/api?cmd=sensorsValues&sensors=30241&uuid=9168dd80decbff888f85412c98adacee&api_key=34FKx6G9hhodY").toString
var String var1= transform("JSONPATH", "$", json)
postUpdate(temp1, var1)
end
In console write:
temp1 state updated to http://narodmon.ru/api?cmd=sensorsValues&sensors=30241&uuid=9168dd80decbff888f85412c98adacee&api_key=34FKx6G9hhodY
How to get “id” and "value, if result of this url issue this:
var String data = Sensor_Data.state.toString
var String id = transform("JSONPATH", "$.sensors[0].id", data)
var String value = transform("JSONPATH", "$.sensors[0].value", data)
That’s it.
And don’t post any credentials on a forum…
var String json = sendHttpGetRequest("http://narodmon.ru/api?cmd=sensorsValues&sensors=30241&uuid=9168dd80decbff888f85412c98adacee&api_key=34FKx6G9hhodY")
var String value = transform("JSONPATH", "$.sensors[0].value", json)
You can capture a value directly in item configuration using a regular expression. But in this case we capture the whole response and parse it in the rule.
Sorry for humping this old thread - but I just found it looking for a good way to get JSON data in an OpenHAB item and I think I can still contribute something for people like myself who show up looking for help or answers…
Number VT_Http_YouLess_Total "Stroomverbruik totaal [%,.3f kWh]" <energy> { http="<[http://youless/a?f=j:10000:JSONPATH($.cnt)]" }
Number VT_Http_YouLess_Current "Stroomverbruik actueel [%,.0f Watt]" <energy> { http="<[http://youless/a?f=j:10000:JSONPATH($.pwr)]" }
Number VT_Http_YouLess_Signal "Stroomverbruik signaal [%.0f %%]" <energy> { http="<[http://youless/a?f=j:10000:JSONPATH($.lvl)]" }
Using the JSONPATH transformation, you can get JSON data directly from a REST API like the one I use to get my YouLess power readings in OpenHAB.