rossko57
(Rossko57)
September 18, 2021, 11:16am
2
Bearing in mind there may be more than one window open when ou try to set the alarm, you’d want to iterate through the Group and filter for OPEN states.
That would produce a list.
Edit: Updates for OH 4, inclusion of JS Scripting and Blockly examples, removed the doors example as it’s superfluous.
Please see Design Pattern: What is a Design Pattern and How Do I Use Them for how to read and use DPs.
Problem Statement
One powerful way to consolidate code in rules is to use array/list manipulation operations on the members of a Group. For example, filter down to just those members that are ON, get a list of the labels of those Items that are NULL, etc.
Concept
[image]
T…
an example
Hey,
My setup looks like this:
items:
/* activegroup: Open Windows */
Group:Contact:OR(OPEN, CLOSED) agFenster_open
"offene Fenster [(%s)]"
<contact>
(gFenster)
Then you have to add each window contact to that group and run the following rule:
import org.openhab.core.library.items.SwitchItem
import java.util.StringBuilder
val StringBuilder sb = new StringBuilder
val offeneFenster = agFenster_open.members.filter(s|s.state==OPEN).size
if(offeneFenster > 0){
…