JSR223 Scripting (Reuse Code)

Hi and a great new Year to everybody,

I have read the whole JSR223 Scripting | openHAB
And as far as I understand using DSL it totally outdated.

JSR223 itself it not very complicated, as far as I common with Groovy. But I dit not get into with OpenHAB.

First of all, is there a way to paste such a script inside the gui?
Second, what is the difference of the Scripts that I create inside the (gui) rules and the ones called “Scripts” direct under “Rules”? (I can not pick/select them inside of a rule, what is realy a pitty.

Last and (for me) most important question: What are the interfaces to get into a script? Lets say I have following simple testScript

events.sendCommand('temperature_living0', 17);

where livig0 is a semantic group with seven temperature controllers and I want to replace “17” wit a variable from outside.
Same way around, can I call a Script from another script and derivate objects or variables?

Would be very nice if anybody could sort my thoughts in this dilemma :slight_smile:
Greatings Oekel

The Tutorials and Solutions category is a place to post tutorials, not request help. I’ve moved this post to a more appropriate category.

Rules DSL is not outdated. However, it does have limitations.

UI rules are a little different from rules defined in text files. But yes, Groovy, Nashorn JavaScript (i.e. ECMAScript 5.1), and Jython all can be used in the UI. But all you write as code is the code that runs when the rule executes. The triggers and the other rule stuff is defined through the UI.

In the UI, a Script is just a special type of rule that consists of only a single Script Action. When you build rules in the UI, you can define multiple triggers, conditions, and actions. In text files you can only create a rule with triggers and a single action (no conditions).

The script folder under /etc/openhab is something specific to Rules DSL. You can forget about that.

Yes indeed you can call another rule from a rule. Probably the easiest way to see how to do that is to look at the code generated by Blockly to see how it does it. At a basic level you have to get a reference to the RuleManager and then you can call another rule by ID.

A Script in the UI doesn’t do much on its own. You can call it from another rule or you can run it manually.

Again, you can look at the code generated by Blockly for calling a rule and pass data to the called rule. Though creating a library is probably a more appropriate approach that gets imported and used by the rule to do something like that. Calling another rule can be useful for “fire and forget” type actions but it’s not blocking and you can’t get a return value from it.

However, note that unless you’ve refined temperature_living0 to have a Number type, sending a command to it will not do anything. A Group needs to have a type in order to send a command to it and have that command forwarded to the Group’s members.

Does allready its Job. So exetuting this line works as exspected (is a number:tempertare)
And yes I always start with blockly to get sure having not typo in selecting my item :wink:

But I can not see the stuff for calling another script there. Under “function” or “openHAB” ?

Check the reference docs. Blockly Reference

The blocks are under run and process.

Allright, just updated from 3.1 → 3.2 (was not there before)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.