Loading scripts defined in UI from rules defined in UI

I’ve been migrating to openHAB 3 and rewriting all rules using the Main UI (in JavaScript).

I read the load keyword can be used to specify a file system path to a script that should be included in a rule. However I cannot find any information on how to include a script defined in the Main UI (so it is stored in JSON DB, not as a standalone file).

I was able to use the Main UI to add an additional “run script” step when running the rule. That caused the script to execute before the rule, but there doesn’t appear to be any mechanism to declare functions in the script and then access those functions in the rule.

Even using ctx.put in the script does not appear to allow arbitrary data (eg string keys to string values) to be shared between a script and a rule defined in the Main UI.

Does anyone know how to reference a Main UI defined script using the load keyword (or some equivalent approach)? I would prefer to not need to use the file system at all for this installation given everything else is working perfectly via Main UI and I find it easier and more convenient to manage access to HTTPS endpoints than file systems.

That’s because it can’t be done.

Just to make it clear in terminology. It is all “the rule”. So in this case running the script is a part of the rule, it doesn’t run before the rule.

Also, in the UI, a Script is just a special case of a rule. It’s basically a rule containing one a single Script Action, no triggers or conditions, and it’s tagged with Script. It really isn’t something different from a rule at all. It’s just another rule.

What you want can’t be done. You can run another rule from a rule which you appear to have discovered already. But you cannot define a library in the UI. The load function can only load from a file.

1 Like

Thanks for the quick response, Rich.