If any 1 door is open. Total Doors Open will show 1. and so on…
Now i want to use this Group Feature in Security System. If security system is armed. I want to execute rule which will check if Count is > 0. Then it will turn on Test Switch and if 0 (all doors are closed) it will turn off switch.
rule "Alert If Any Door is Opened"
when
Item doorsecsys received update
then
if(doorsecsys != 0)
{
dummytest.sendCommand(ON)
}
else
{
if(doorsecsys == 0)
{
dummytest.sendCommand(OFF)
}
}
end
Switch Gets on when count is not equal to 0. But it doesn’t get off when count is 0.
A Group Item of Type Contact has up to three status, OPEN, CLOSED and NULL (the latter is “No status yet”)
Yes, you can get the Number of members in Status OPEN, but this is only for dynamic Label.
Your rule would be like this:
rule "Alert If Any Door is Opened"
when
Item doorsecsys changed
then
if(doorsecsys.state != CLOSED) {
dummytest.sendCommand(ON)
} else {
dummytest.sendCommand(OFF)
}
end
Please pay attention to the fact, that you don’t need the second if(), as there is either CLOSED or OPEN (the Item changed, it’s very unlikely that the Item will become NULL)
Further, pay attention to the .state.
doorsecsys -> Item itself (Last Update time stamp and actual Status)
doorsecsys.state -> Status of the item
If you want to get the number of opened doors, you have to use another method:
logInfo("myrule","Number of open doors is {}",doorsecsys.members.filter[m|m.state == OPEN].size)