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

Ok i have putted in a rule, so that is my workarround. But then the question remains why have a script folder if you can’t use it?

Because there’s a bug apparently that needs to be fixed. Has anyone filed an issue?

I’m willing to file the issue if someone could give me a hint where to do that (well. Github is clear, but…). I have no idea atm in which part of OH this could or should be fixed. Thanks!

1 Like

Hi Rich, thanks for the link. The “how-to” was basically clear to me, I might not have been too clear as what I’m unsure about. Sorry for that.
Is it openhab-core, openhab.distro, … that I need to open the issue? I’m not really sure which part of the different parts of OH I need to open the issue with.
Thanks

I’m pretty sure this would be for openhab-core.

Thanks a lot, your siggestion is very much appretiated.

Same problem here, just filed an issue:

3 Likes

Same here, any workaround would be great!

#metoo
This should be mentioned in the Known Issues section: Release openHAB 3.0.0 · openhab/openhab-distro · GitHub until OH3 callScript - scripts are not executed · Issue #1990 · openhab/openhab-core · GitHub is solved.

Tried to copy my 3 scripts into the new framework, but unsure how to use them.
Rule did not find them using callScript():

1 Like

I ended up copying the scripts’ contents into new rules, triggered by dedicated items which I simply send an ON command where I would otherwise call the script. It works quite well as a workaround.

1 Like

Please see OH3 callScript - scripts are not executed · Issue #1990 · openhab/openhab-core · GitHub and try if the workaround fixes it for you on 3.0.0:

According to my tests, there should be a simple workaround:
Simply rename your script files from myfile.script to myfile.script.script and they should be found.

1 Like

Ok Will test this evening let know if it works!

It didn’t work form me still the same error:

image

2020-12-28 17:58:00.492 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

2020-12-28 17:58:20.488 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

2020-12-28 17:58:40.499 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

2020-12-28 17:59:00.489 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

2020-12-28 17:59:20.498 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

2020-12-28 17:59:40.490 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘Time-1’ failed: Script ‘holiday’ cannot be found. in Time

just for the test i let it run every 20s…

Adding “.script” to the name did not work, neither did the removal of the entire extension work. In both cases the same error message is logged:

2020-12-28 18:10:34.172 [INFO ] [rg.openhab.core.model.script.default] - ##### Prüfe, ob heute arbeitsfrei ist
2020-12-28 18:10:34.176 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'zentral-1' failed: Script 'arbeitsfrei' cannot be found. in zentral

“zentral.rules” is the calling script and “arbeitsfrei.script” or “arbeitsfrei.script.script” or “arbeitsfrei” is the script called from within “zentral.rules”

It does work for me, however you need to use callScript('myfile.script'), i.e. add one “.script” to the name of the script you want to call.

That also works for me! Great job guys!

Tinkering with it, I agree, the workaround does work. I was not clear to me that the additional “.script” needs to be applied not only to the script file itself but also to the call in the rule.

To make it clear to everyone:
The filename needs to be changed from
myfile.script
to
myfile.script.script

AND

in the calling rule
callScript('myfile')
needs to be changed to
callScript('myfile.script')

Thanks @bern77 and @Kai

1 Like