Hello!
I’m sorry if this question might sound stupid but I couldn’t find it in the docs or in the samples:
I want to implement a rule like:
rule "Security State Sensor"
when
Item Openingcontacts changed or
Item Tamperswitches changed
then
Security_Last_Change.postUpdate( now.toString() )
if ( Security_Alarmanlage.state == ON ) {
if ( ( Security_OpenWindows.state <= Openingcontacts.state ) || (Tamperswitches.state >= 1 ) ) { // someone opened a door or window
logInfo("AlarmanlageRule", "Windows opened during alarm active. Security_OpenWindows: [{}], Openingcontacts: [{}], Tamperswitches: [{}]", Security_OpenWindows.state, Openingcontacts.state, Tamperswitches.state)
Alarm_Security.postUpdate(ON)
} else if ( Security_OpenWindows.state >= Openingcontacts.state ) { // someone closed a door or window while the alarm is active
logInfo("AlarmanlageRule", "Window closed. Security_OpenWindows: [{}], Openingcontacts: [{}], Tamperswitches: [{}]", Security_OpenWindows.state, Openingcontacts.state, Tamperswitches.state)
Security_OpenWindows.postUpdate(Openingcontacts.state.format("%d"))
}
}
end
//----------------------------------------------------------
// Set how many Windows are open at the time of activation.
//
rule "Alarmanlage wird aktiviert"
when
Item Security_Alarmanlage changed
then
if ( Security_Alarmanlage.state == ON) {
logInfo("AlarmanlageRule", "Security_OpenWindows: [{}], Openingcontacts: [{}]", Security_OpenWindows.state, Openingcontacts)
Security_OpenWindows.postUpdate(Openingcontacts.state.format("%d"))
} else {
Security_OpenWindows.postUpdate(0)
}
end
Items:
Group:Contact:OR(OPEN, CLOSED) Security "Security [(%d)]" <shield> (All)
Group:Contact:OR(OPEN, CLOSED) Openingcontacts "Öffnungssensoren [(%d)]" <contact> (Security)
Group:Contact:OR(OPEN, CLOSED) Tamperswitches "Sabotagekontakte [(%d)]" <contact> (Security)
Number Security_OpenWindows
I would expect that if the alarm is enabled, the Openingcontacts.state
would hold the current number of open windows, but it is OPEN
. I saw the $group?.members.filter function but I guess there is a quicker way
Thanks for your help!