Just to give a detailed example of an implementation of Workaround 1 in the doc.
(remember to install the expire binding)
.items
Switch vPersistRestoreTimer { expire="15s,command=OFF" }
.rules
rule "System start"
when
System started
then
logInfo("System", "System started (or a rule changed)");
vPersistRestoreTimer.sendCommand(ON) // start timer
end
rule "vPersistRestoreTimer expired"
when
Item vPersistRestoreTimer received command OFF
then
logInfo("System", "vPersistRestoreTimer expired")
HouseGuests.postUpdate(if (HouseGuests.previousState().state==ON) ON else OFF)
end
And finally I want to advertise for the Member of feature, that really makes the handling of grouped items a breeze. For instance, if you want to log and handle events from a group of Switches:
.items
Group:Switch groupSwitches
Switch All (groupSwitches)
Switch AllLR (groupSwitches)
Switch AllDR (groupSwitches)
Switch AllK (groupSwitches)
.rules
rule 'groupSwitches changes'
when Member of groupSwitches received command OFF or
Member of groupSwitches received command ON
then
logInfo("groupSwitches", triggeringItem.name + " State=" + triggeringItem.state)
switch(triggeringItem.name) {
case "All": {
sendCommand(lights, if (All.state==ON) ON else OFF);
}
case "AllLR": {
sendCommand(livingRoom, if (AllLR.state==ON) ON else OFF);
AllLR.state = if (AllLR.state==ON) ON else OFF;
}
case "AllDR": {
sendCommand(diningRoom, if (AllDR.state==ON) ON else OFF);
AllDR.state = if (AllDR.state==ON) ON else OFF;
}
case "AllK": {
sendCommand(kitchen, if (AllK.state==ON) ON else OFF);
AllK.state = if (AllK.state==ON) ON else OFF;
}
}
end
This can really cut down on the number of rules