Scripts in OH3

Well, the error is it can’t find the script so either:

  • you didn’t move your scripts over
  • they are in the wrong folder
  • the “right” folder may have moved
  • there is a bug and openHAB is looking in the wrong location.

Someone experiencing this problem needs to file an issue.

As a work around, depending on what your scripts do, you can achieve the same thing in Jython/JavaScript/Groovy by creating a library. Or you can implement them in a rule and use OH 3 Examples: Writing and using JavaScript Libraries in MainUI created Rules. Or you can write rules that call other rules. This is particularly easy to do in UI rules as there is an “execute another rule” Action you can choose. But you can do it in code as well.

In JavaScript it would look something like:

// Run another rule
var FrameworkUtil = Java.type("org.osgi.framework.FrameworkUtil");
var _bundle = FrameworkUtil.getBundle(scriptExtension.class);
var bundle_context = _bundle.getBundleContext()
var classname = "org.openhab.core.automation.RuleManager"
var RuleManager_Ref = bundle_context.getServiceReference(classname);
var RuleManager = bundle_context.getService(RuleManager_Ref);
RuleManager.runNow("tocall");
var map = new java.util.HashMap();
map.put("test_data", "Passed data to called function!")
RuleManager.runNow("tocall", true, map); // second argument is whether to consider the conditions, third is a Map<String, Object> 

Notice how you can pass data to the other rule. Much of the stuff in the above code is done for you in the Helper Libraries.

Unfortunately you can’t do this from Rules DSL as far as I know.

2 Likes