@bastiaan_van_h sorry did not read it properly, thought you wrote i get an error.
Does one of those work? So does the http binding return something?
When you use this, at least something should apear int the log when Hue_Brightness_Woonkamer changes. I changed it to a string for testing and removed the json querry.
Item Milight_ID1_G1_EspMilightHub changed
var sJSONBLOB = Milight_ID1_G1_EspMilightHub.state.toString
var sMODE = transform("JSONPATH","$.bulb_mode", sJSONBLOB)
var sSTATE= transform("JSONPATH","$.state", sJSONBLOB)
var sLEVEL= transform("JSONPATH","$.level", sJSONBLOB)
var Number iLEVEL= Integer::parseInt(sLEVEL).intValue //convert the string to an int.
if(sMODE=="white") // Code to handle a white JSON blob
var sCTEMP=transform("JSONPATH","$.color_temp", sJSONBLOB)
var iTempScaled=(((Integer::parseInt(sCTEMP)/2.17)-171)*-1).intValue //Dirty but seems to work. Converts string to int and scale range.
Milight_ID1_G1_CTemp.postUpdate(iTempScaled) //send CT to globe
Milight_ID1_G1_Brightness.postUpdate(iLEVEL) //send new brightness to globe
else if(sMODE=="color") // Code to handle a colour JSON blob
var String sHUE = transform("JSONPATH","$.hue", sJSONBLOB)
var String sSATURATION = transform("JSONPATH","$.saturation", sJSONBLOB)
Milight_ID1_G1_Brightness.postUpdate(iLEVEL) //update main dimmer item
Milight_ID1_G1_Hue.postUpdate(sHUE+","+sSATURATION+","+sLEVEL) //update color item
You are using an indefinite path in your JSONPATH, which will return a List, not a string. Indefinite paths can’t be used in JSONPATH for Items/Labels, and take special handling in rules.
There was a relatively recent ESH PR to resolve an issue that has made its way into the OH snapshot build, where the first element of the List would be returned, if there is only one element in it. There are some unfortunate side affects to this that I am hoping will be addressed.
To resolve your issue, you could update OH to the snapshot, or use a JS transform to parse the JSON.
Item Test_1 changed
// filter applied on proxy item
var test1= transform( "JSONPATH",
logInfo("Test ", test1.substring(1, test2.length-1) )
// Strip off the brackets and
// Post result to Number Item
Test_2.postUpdate( test2.substring(1, test2.length-1) )
The way I understand it, $.groups[?(@.name=='Woonkamer')].action.bri searches the children of groups, and there is no child of “groups” with key “name”. But $.groups.1[?(@.name=='Woonkamer')].action.bri has a child with key “name”, so it is found. The deep scan (recursive descent) searches the whole tree, so also finds “name”.
Correct. His issue should be solved by what I posted earlier. I just saw your reply and thought I’d try to help. You hadn’t found an issue with using the JSONPATH transformation in rules… the expression you were using just wasn’t returning a result. But read through the issue I linked… as written, there are definitely some things that can be improved!
Jayway (used by OH) is a Java port of Goessner, so there could be differences. There could also be differences in the versions. Sorry… nothing definitive.