After deleting the single quotes around the URL I’m getting a 404 now, which means the data option is not getting passed through or something is going wrong there.
After doing some TCP dumps I saw the difference and the solution was deleting the single qutoes around the curly brackets.
The item gets populated with the JSON now but that brings up a new question:
Can you process an item and split it in different new items without using rules? I was thinking of creating a JSONSMA-item and make “sub-items” which point to the “main” item and process that main item with JSONPATH so the sub-items get populated…?
You could use the JSONPATH transform in the thing but that gives you only one item
unfortunately you can’t do that without a rule
see:
rule "jsonpath"
when
Item SMAJSON changed
then
val jsonString = SMAJSON.state.toString
Item1.postUpdate(transform("JSONPATH",".$.path.path1", jsonString))
Item2.postUpdate(transform("JSONPATH",".$.path.path2", jsonString))
Item3.postUpdate(transform("JSONPATH",".$.path.path3", jsonString))
end
Thanks for the quick reply, it confirmed my fears I should start writing a rule again.
Continuing with this story, I implemented your rule (changed the variables names to match my naming convention)
rule "Process JSON from SMA Inverter"
when
Item JSON_SMA changed
then
logInfo("RULE", "JSON from SMA inverter changed!")
logInfo("RULE", "---------------------------------------------------------------------------------")
logInfo("RULE", "-----------------------------WRITING THE ITEM TO LOG-----------------------------")
logInfo("RULE", "---------------------------------------------------------------------------------")
logInfo("RULE", JSON_SMA.state.toString)
val jsonString = JSON_SMA.state.toString
logInfo("RULE", "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-")
logInfo("RULE", "++++++++++++++++++++++++++++WRITING THE STRING TO LOG++++++++++++++++++++++++++++")
logInfo("RULE", "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-")
logInfo("RULE", jsonString)
number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.XXXX-XXXXXXXX.XXXX_XXXXXXXX.1.0.val", jsonString))
However, the logging shows:
2018-03-18 00:37:24.078 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘Process JSON from SMA Inverter’: The argument ‘state’ must not be null or empty
So I checked if it really was empty or null, which it isn’t. I’m outputting both the item defined in the items file to the log and the jsonString val object and they both return the JSON in the log file…
If I comment out the number_SMA… transform rule, the error disappears in the logging. Additional strange thing is that I have multiple of these code-lines (vermogen means power in Dutch, so I have power,amperage,voltage etc) but I’m seeing the error only once though I would expect to see it the amount of times I have defined a statement to process a value…
val jsonString = JSON_SMA.state.toString
if (jsonString != null) {
number_SMA_DCVermogenA.postUpdate(transform("JSONPATH","$.result.XXXX-XXXXXXXX.XXXX_XXXXXXXX.1.0.val", jsonString))
}
2018-03-18 08:09:37.300 [INFO ] [.eclipse.smarthome.model.script.RULE] - JSON from SMA inverter changed!
2018-03-18 08:09:37.301 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Process JSON from SMA Inverter': The argument 'state' must not be null or empty.
jsonString is not “”, that’s what we proved by outputting them to the log here, no?
So I checked if it really was empty or null, which it isn’t. I’m outputting both the item defined in the items file to the log and the jsonString val object and they both return the JSON in the log file…
If I comment out the number_SMA… transform rule, the error disappears in the logging. Additional strange thing is that I have multiple of these code-lines (vermogen means power in Dutch, so I have power,amperage,voltage etc) but I’m seeing the error only once though I would expect to see it the amount of times I have defined a statement to process a value…
The empty rule log line is coming from the
logInfo("RULE", tester)
And tester should contain the transformed value but something is going wrong there I think, or am I misunderstanding you?