Call scripts within rules

I am trying to call a script I created in the scripts section in a rule, this is my script:

and this is how I try to call the script inside my rule:


but I get this error in the logs:

I am trying to do this approach because I want to have a generic script and be able to call that script and pass the desired parameters to it from within rules.

That’s not how Scripts work in OH. A Script is just a special type of rule that lacks triggers and conditions and only includes a single script action. To call a Script from another rule you use rules.runRule() (assuming JS Scripting).

You look like you are trying to create and import a personal library. To do that see JavaScript Scripting - Automation | openHAB. The tl;dr is you need to create a node module and install it under $OH_CONF/automation/js/node_modules.

Note that when using rules.runRule(), if you have two rules calling the same rule at the same time you will see a MultiThreadedException. Scripts and rules.runRule() is not a replacement for creating a library.

1 Like