Try to use my OH2 rules on OH3.
But I receive the error “The name ‘ScriptServiceUtil’ cannot be resolved to an item”
Is this no more supported?
Try to use my OH2 rules on OH3.
It’s still there. How are you trying to use it? What language?
Hi Rich, I’m using old fashioned DSL. “ScriptServiceUtil” is imported at start of file.
rule Test when Time cron "0,5,10,15,20,25,30,35,40,45,50,55 * * ? * *" then gRLall.members.forEach[GroupItem actRLgroup | logInfo("Test", "Hallo") val String actGrpName =actRLgroup.name.substring(1,4) val SwitchItem actItemSkip = ScriptServiceUtil.getItemRegistry?.getItem(actGrpName+"_Skip") as SwitchItem ] end
And more simplyfied:
import org.eclipse.smarthome.model.script.ScriptServiceUtil rule Test when Time cron "0,5,10,15,20,25,30,35,40,45,50,55 * * ? * *" then val SwitchItem actItemSkip = ScriptServiceUtil.getItemRegistry.getItem("RL1_Skip") as SwitchItem end
Don’t you see an error for that import?
As was mentioned in the breaking changes when OH 3 was released, there is no more org.eclipse.smarthome anywhere in openHAB any longer. Usually you can replace that with org.openhab.
Sorry - missed that. But still the same problem:
import org.openhab.model.script.ScriptServiceUtil rule Test when Time cron "0,5,10,15,20,25,30,35,40,45,50,55 * * ? * *" then val SwitchItem actItemSkip = ScriptServiceUtil.getItemRegistry.getItem("RL1_Skip") as SwitchItem end
Script execution of rule with UID ‘test-1’ failed: The name ‘ScriptServiceUtil’ cannot be resolved to an item or type; line 8, column 31, length 17 in test
It’s missing the “core” part.
When in doubt, check the JavaDocs.
Sorry, I have the same problem and do not understand how to fix this.
Once again, with the correct path
Oh, sorry, I tried to understand the JavaDocs… Thank you very much Rich
Rich, thanks for your help
I have a similar error trying to import ScriptServiceUtil in my DSL rule :
Script execution of rule with UID 'c6a1251eab' failed: ___ import ___ org.openhab.core.model.script.ScriptServiceUtil
This is the line that I copied from the conversation:
I still get the same error.
I’m on 3.0.1
But where did you put that line?
You can’t do imports inside the body of a rule.
So, in a xxx.rules file you put them standalone at the head of the file.
In a UI entered rule, there is no access to “outside the body”. You can’t do imports in a UI DSL rule.
I put that line at the very top of the rules script in the UI. So does this mean that if I need to access “ScriptServiceUtil” I’ll have to use an external rules file?
No, you can still use stuff without importing them. You just have to use the full name. Where ever you use
ScriptServiceUtil you would use
Both Python (
Java.type("org.openhab....")) allow the imports to occur anywhere, not just the top of the file. So you can import anything at any point in the code.
var MySwitchState = items["Foo_"+event.itemName]
So in practice about the only time you need to access the ItemRegistry is when you want to get the members of a Group or other things that require actually having the Item Object to accomplish.
Additional question: How would I turn debugging on when testing rules built in the UI?
The same way you do now. Modify the log4j.xml file or use the karaf console to change the logging level for the loggers you are using to DEBUG.