Transform not working in a scheduled rule

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")"rule launched")
test = '[{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}]'
val newValue = transform("JSONPATH", "$.device.status.temperature", test)"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

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.

Either use the UI or use addons.cfg. Never try to use both because the addons.cfg will always take precedence, meaning anything not listed there will be removed.

I don’t use Groovy and there is not a lot of documentation. But I wonder if you are trying to write Rules DSL in a Groovy file, which isn’t going to work. Groovy doesn’t have a val.

Once you have the basic Groovy syntax right, you’ll find that you have to import transform to use it too. org.openhab.core.transform.actions.Transformation.transform()

I strongly recommend that unless you already know Groovy as a language that you choose almost any of the other languages. They are better documented and there are helper libraries so you don’t have to do so much with imports and such.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.