Great post! Thanks for sharing!
This is a really nice use of proxy Items.
Here are some more advanced ways you can further simplify this code.
They can be made even simpler.
rule "Fountain Master"
when
Item FountainMaster received command
then
if(gFountain.state != receivedCommand) gFountain.sendCommand(receivedCommand)
end
I bet these could all be merged into a single Rule as well. Let’s make the names a little easier to split apart and rebuild.
Group:Switch gProxies
// Master Switches
Switch Fountain_Master "Fountain Master" <water> (gProxies)
Switch XmasExt_Master "Christmas Exterior Master" <light> (gProxies)
// Switch Groups
Group:Switch:AND(ON,OFF) gFountain "Fountain" <water>
Group:Switch:AND(ON,OFF) gXmasExt "Christmas Exterior" <light>
Then you can combine all the Master rules into a single Rule
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "Master"
when
Member of gProxies received command
then
val grp = ScriptServiceUtil.getItemRegistry.getItem("g"+triggeringItem.name.split("_").get(0))
if(grp.state != receivedCommand) grp.sendCommand(receivedCommand)
end
This concept is documented in Design Pattern: Associated Items.