I’m trying to move my rules from Rule DSL to JSR223/Javascript… I’ve got most things working but I"m struggling with how to implement the equivalent of the following…
Currently, there’s nothing like this in JS… only for Jython. Once OH is compatible with JDK9, which has ES6, I plan to build the same functionality into the JS helper libraries. This could probably be done now, but will be easier with class support. But I’ll also be working on a new scripting API that will replace the need for using the helper libraries too. Not sure which will come first. The raw API is ugly!
i also trying to move my rules from Rule DSL to JSR223/Javascript.
I want to move the window reminder Rule from here :
But i fail in de group members action.i
In Rule DSL val timer = FHTfensterTimer.members.filter[t | t.name == fenster.name+"_Timer"].head as SwitchItem
To move it to javascript i tried the way from @rlkoshak here https://community.openhab.org/t/experimental-next-gen-rules-engine-documentation-4-of-writing-scripts
/55963 var filtered = group.members.stream().filter(function(i){ return <boolean expression>; }).toArray(); where <boolean expression> is the filtering conditional.
Here my rule
load(Java.type("java.lang.System").getenv("OPENHAB_CONF")+'/automation/jsr223/jslib/JSRule.js');
JSRule({
name: "Fensterüberwachung",
description: "Diese Regel überwacht die Fenster und gibt Alarme in bestimtmen Zeitfenstern aus",
triggers: [
TimerTrigger("0/10 * * * * ?")//Enable/Disable Rule
],
execute: function( module, input){
var logname = "FENSTERÜBERWACHUNG";
//Fenster Item aus TriggerEvent holen
var fenster = getItem("TestFenster1"); //dieses Item als Test -> Muss durch TriggerItem ausgetauscht werden
logInfo(fenster.getName() +" hat die Regel ausgelöst")
//TimerItem zu Fensteritem
var group = getItem("GroupFensterTimer");
var filtered = group.members.stream().filter(function(i){ return i.getName() == fenster.getName() +"_Timer" ; }).toArray();
logInfo(filtered +" ist das Timer-Item");
}
});