Hi,
I’m very new in the OpenHAB world and I’m stuck with a transform function.
I have Groovy and JSONPath Transformation Service installed.
I also have add jsonpath in the addons.cfg
To do simple, I have a rule, which is triggered by a time event (every minute).
The action is a groovy script which is very simple (for the moment).
here it is :
import org.slf4j.LoggerFactory
def logger = LoggerFactory.getLogger("toto")
logger.info("rule launched")
test = '[{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}]'
val newValue = transform("JSONPATH", "$.device.status.temperature", test)
logger.info("rule OK, newvalue : "+newValue)
This script is supposed to write "rule OK, newvalue : 23.2 in the log.
But I have a first error :
2022-06-26 23:19:00.014 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '7512ebe4da' failed: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script11.groovy: 5: token recognition error at: '.' @ line 5, column 40.
val newValue = transform("JSONPATH", "$.device.status.temperature", test)
^
1 error
So I have to escape the “$” by a “\$”. Then, the 5th line is now
val newValue = transform("JSONPATH", "\$.device.status.temperature", test)
Then a new error occurs :
2022-06-26 23:23:00.702 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '7512ebe4da' failed: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script15.groovy: 5: unable to resolve class val
@ line 5, column 5.
val newValue = transform("JSONPATH", "\$.device.status.temperature", test)
^
1 error
So, if I remove the “val” at the beginning of the line, I have a new error :
[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '7512ebe4da' failed: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.transform() is applicable for argument types: (String, String, String) values: [JSONPATH, $.device.status.temperature, [{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}]]
I’ve also noticed than when I install JSONPath Transformation, I have this warning in the logs, but I don’t know how to solve it and I don’t know if it is related to my problem :
[WARN ] [apache.cxf.jaxrs.utils.ResourceUtils] - No resource methods have been found for resource class javax.ws.rs.core.Response
Anybody could help me knowing what I am doing wrong ?
This very simple example should work but it doesn’t.
I’ve tried to uninstall/reinstall JSONPath Transformation service, my OpenHAB is up to date (3.2.0-1) and I’m running OpenHAB on an LXC container on Proxmox with a debian 11.
Thanks for your help.