Create scripts in JS Scripting in file based mode

I’m using OH4 with the JS Scripting module.

I’m writing my rules in file-based mode, creating individual rules using the command rules.JSRule() and inserting the files inside the /conf/automation/js folder.

How can I create the scripts in javascript for the Scripts section in file-based mode? I haven’t found any information that can help me.

Thank you, Massimo.

I’m not sure why you would want to. If you are using file based rules creating “Scripts” like that doesn’t do anything for you. You’d be better off creating a personal library of functions to call.

A “Script” is just a special case of a rule:

  • no triggers
  • no conditions
  • “Script” is a tag on the rule

I understand that a script is an triggerless rule but creating a library could not be invoked from a widget. If I insert a button in a panel, I can invoke a script/rule when pressed. If I create a library, I couldn’t run it.

Thanks so much for the suggestion. This example is cataloged as a Script and not as a Rule:

id: “script_test”,
name: “Test”,
triggers: ,
execute: (event) => {
tags: [ “Script” ]

You can call any rule from a UI widget, not just Scripts. So having it categorized as a Script is not required. The “Script” tag is not required.

yes true, in fact I had written script/rule, meaning both categories.