But I always get an error log when executing the rule like:
Script execution of rule with UID 'solar-5' failed: The name 'osgi' cannot be resolved to an item or type
I tried using: “import org.osgi.framework” in front of rule file. But no success
The same problem occurs with any other example code using “Java.type(…)” calls telling me Java not known.
Strange thing is, that in VS Code all the autocompletion stuff on these work beatiful, suggesting proper methods etc. But my rules do not know these
Thanks for helping me on a such a basic question!
I am confused, I not use scripts but rules. In openhab UI under rules it says:
application/vnd.openhab.dsl.rule
I have not installed any seperate plugin for running scripts.
So how do I find out which way works for me?
Thx
Didn’t find anything in https://www.openhab.org/addons/automation/jsscripting/#things which leads me back to the question: what scripting engine to I have to include with OpenHab 4.2.2 in order to prevent the error:
Script execution of rule with UID ‘Tibberswitch-1’ failed: The name ‘osgi’ cannot be resolved to an item or type
I want to use var thingMgr = osgi.getService(‘org.openhab.core.thing.ThingManager’) in a rule but cannaot figure out the required package to make this work.
If the ID of the rule is Tibberswitch-1 that means you’ve defined the rule in a file named Tibberswitch.rules under `$OH_CONF/rules. Only Rules DSL is supported in this type of file in this location. Everything you need to know to write rules here is documeted at Textual Rules | openHAB.
osgi.getService doesn’t exist in Rules DSL. I’m not sure if you can get access to the ThingManger in Rules DSL.
If you want to use JS Scripting, you must follow the requuirements for that language which are documented at JavaScript Scripting - Automation | openHAB. The tl;dr is you must define the rules using rule builder or JSRule in a file ending in .js at $OH_CONF/automation/js.
What are you looking for there?
What are you trying to accomplish? You don’t need osgi to access Things in JS Scripting. For example, to get all the Things that are OFFLINE:
var offlineThings = things.getThings().filter( t -> t.status == "OFFLINE");
thingsis your interface to the ThingManager. You already have access to it.