Hey guys,
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");
}
});
Items
//Testitem für Fensterüberwachung
Group:Switch GroupFensterTimer
Switch TestFenster1 "Testfenster 1"
Switch TestFenster2 "Testfenster 1"
Switch TestFenster1_Timer "Testfenster 1 Timer" (GroupFensterTimer)
Switch TestFenster2_Timer "Testfenster 1 Timer" (GroupFensterTimer)
Here the log
Now i don’t unterstand the second log item. How can i get the right timer item from the group to the var = filtered?
Can everyone help me?