Scripting Rules OH3

There is no preferred OH language. They all have advantages and disadvantages. There are also more than just those four languages available and two different (and incompatible) versions of JavaScript. It’s all hopelessly fragmented. The documentation is not uniform. There is really no such thing as future proof.

All interaction between OH and the rules for the JSR223 languages (the three you listed) takes place through Java Classes and Objects. So they pretty much all work the same with the main difference being the syntax of the individual languages. Given that…

https://www.openhab.org/javadoc/latest/org/openhab/core/automation/module/script/rulesupport/shared/simple/simplerule

Which shows execute is inherited from SimpleRuleActionHandler (openHAB Core 4.2.0-SNAPSHOT API)

Which shows that module is Action (openHAB Core 4.2.0-SNAPSHOT API) and input is a java.util.Map<String, Object>.

No matter which of the three languages you are using, you need to create an instance of the Java Class SimpleRule and override the execute method which contains the code that will be executed when the rule is run.

The documentation is there once you realize that it’s all mostly working with Java.

It becomes much easier when using the UI to define rules because most of the effort spent in a text based js or py rule file is spent just defining the rule. In the UI all of that is handled for you and all you have to mess with is that execute method.

There is no simple API Documentation.

1 Like