One unique thing about my setup, is that I have certain rules which only happen seasonally, or under certain circumstances. For instance, one of my outdoor modules controls the fountain in the summer, and Christmas lights in the winter. Each use case applies a different set of rules, and I can’t have my fountain timings setting off Christmas lights, or vice versa.
To make this work, my Items file includes several “mode” switches, not associated with physical things:
/**
* Modes
*/
Switch XmasMode "Christmas Mode" <settings>
Switch FountainMode "Fountain Mode" <settings>
Then I created some “master” switches, switch groups, and of course the physical switch.
// Master Switches
Switch FountainMaster "Fountain Master" <water>
Switch XmasExtMaster "Christmas Exterior Master" <light>
// Switch Groups
Group:Switch:AND(ON,OFF) gFountain "Fountain" <water>
Group:Switch:AND(ON,OFF) gXmasExt "Christmas Exterior" <light>
// Physical Switch
Switch Courtyard_Outdoor_FountainXmas "Fountain" <water> (gFountain, gXmasExt) { channel="zwave:device:4ff68761:node27:switch_binary" }
The “master” switches have rules which check the state of the “mode” switch, and conditionally turn on/off the switch group:
/**
* Fountain Master Switch
*/
rule "Fountain Master ON"
when
Item FountainMaster received command ON
then
if (FountainMode.state == ON) {
sendCommand(gFountain, ON)
}
end
rule "Fountain Master OFF"
when
Item FountainMaster received command OFF
then
if (FountainMode.state == ON) {
sendCommand(gFountain, OFF)
}
end
By doing it this way, my time-based rules can be really simple. They don’t include any conditional code, because they simply trigger the master switch which handles the conditional bits:
/**
* Timers
*/
rule "Fountain ON Timer"
when
// Sunday, 8:30 a.m.
Time cron "0 30 8 ? * SUN *"
or
// Wednesday, 6:30 p.m.
Time cron "0 30 18 ? * WED *"
then
sendCommand(FountainMaster, ON)
end
rule "Fountain OFF Timer"
when
// Every night at 9 p.m.
Time cron "0 0 21 1/1 * ? *"
then
sendCommand(FountainMaster, OFF)
end
Effectively, the “master” switches are emulating the notion of “scenes,” as they are called in the Vera world. I can automate scenes via rules as shown above, or include the master switches in my site map definition, to trigger them manually. Either way, I know that if Fountain Master is triggered, it’s only going to change the switch if Fountain Mode is enabled. That’s a really powerful abstraction that drastically simplifies rule creation.
You may be wondering why I bothered with the groups. Well, I have other mode-based master switches which control multiple devices. I left them out of my example for simplicity. But in those cases it’s nice to have the master switch control a group. So I always use a group for each mode, just for consistency’s sake.