Within HabPanel I configured a Selection Widget with the openHAB Item: A Jason
but with this configuration I just get the complete json file as value and not just 23,7 C or 52% (depending on JSONPATH Index)
Hope anyone of you can give me a hint…
I’ve tried with html code and http-binding + Regex … nope …
I’ve tried with json and getvalue.js … nope …
I’ve tried this variant with JSONPATH … nope …
in every case values are NULL or everything
thanks a lot
BR Martin
P.S.: If you have any other ideas don’t hesitate to post here!
I’ve a custom Object and are able to transform this to json or html code or another custom format.
I guess you could use a cron rule to populate the required fields using jsonpath transformation at certain intervals. Some code below to test in a rule
val jsonString = sendHttpGetRequest("http://192.168.6.20/mobilealerts.js")
val temp = transform("JSONPATH","$.[0].Value",jsonString)
val fucht = transform("JSONPATH","$.[1].Value",jsonString)
logInfo("Temp is ",temp)
logInfo("Fucht is ",fucht)
Hi,
thx for your reply, was not able to find a usable documentation (i’m beginner in centos too)
there is no package available on yum and after installing zulu manualy openhab didn’t work.
with install by: yum install java everything seems fine…
may you can give me a hint where i will find a better documentation or post on internet.
thank you
BR Martin
@hmerk: no problem but i think i’ve done the challenge. Now i’m (i hope so) on zulu.
@all: i’ve found an interesting line within logfiles after changing to debug mode:
org.openhab.core.transform.TransformationException: Invalid path ‘$.[1].Value’ in '[
but i’ve no idea why because json validators say everything is fine within json file ?!
EDIT: @MartinKo: I’ve searched through Logfile but did not found any entry like “Temp is” or “Fucht is”.
What i’ve done is creating a file within $openhabdir/conf/rules/test.rules within:
OK… the code I submitted is just the code that is supposed to go into a rule. In other words it is missing the rule skeleton.
You have to provide the rest… like this
rule "update clima"
when
// run every 10 minutes
Time cron "0 0/10 * 1/1 * ? *"
then
val jsonString = sendHttpGetRequest("http://192.168.6.20/mobilealerts.js")
val temp = transform("JSONPATH","$.[0].Value",jsonString)
val fucht = transform("JSONPATH","$.[1].Value",jsonString)
logInfo("Temp is ",temp)
logInfo("Fucht is ",fucht)
end
That only confirms that the json path is OK, but we already knew that. Could you try to modify the rule to the following
rule "update clima"
when
// run every 2 minutes
Time cron "0 0/2 * 1/1 * ? *"
then
val jsonString = "[{\"Room \": \"WZ \",\"SensorID\": \"022 A7F181984\",\"Time\": \"16.01 .2018 13: 18: 50\",\"Data\": \"WZTemperatur\",\"Value\": \"23,7 C\"}, {\"Room \": \"WZ \",\"SensorID\": \"064 C1706F7B7\",\"Time\": \"16.01 .2018 13: 19: 45\",\"Data\": \"WZLuftfeuchtigkeit\",\"Value\": \"52 % \"}]"
val temp = transform("JSONPATH","$.[0].Value",jsonString)
val fucht = transform("JSONPATH","$.[1].Value",jsonString)
logInfo("Temp is ",temp)
logInfo("Fucht is ",fucht)
end
This is to rule out any problems reading the json from the server and to the OpenHab transformation service. When I run this rule I get the result that is expected
For all they want to use powershell:
curl -X PUT --header “Content-Type: text/plain” --header “Accept: application/json” -d “$current_data” “http://:8080/rest/items/<OPENHAB_ITEM>”