Match name of similiar items in two different groups

This is a great implement of the Associated Items Design Pattern. Thanks for sharing!

I do something almost identical for my lighting. The biggest difference is I went ahead and created a Group for all the times of day (two Groups actually, one for entering a time of day and one for exciting) and left them empty if I didn’t have anything to be done during that time period.

Note, I assume the above is pseudo code and you are actually using sendCommand to change the states of your Items.

Here is my code for the curious.

rule "Set lights based on Time of Day"
when
  Item vTimeOfDay changed
then
  // reset overrides
  gLights_WEATHER_OVERRIDE.postUpdate(OFF)

  val offGroupName = "gLights_OFF_"+vTimeOfDay.state.toString
  val onGroupName = "gLights_ON_"+vTimeOfDay.state.toString

  logInfo(logName, "Turning off lights in " + offGroupName)
  val GroupItem offItems = gLights_OFF.members.filter[g|g.name == offGroupName].head as GroupItem
      offItems.members.filter[l|l.state != OFF].forEach[l | l.sendCommand(OFF)
  ]

  logInfo(logName, "Turning on lights for " + onGroupName)
  val GroupItem onItems = gLights_ON.members.filter[g|g.name == onGroupName].head as GroupItem
      onItems.members.filter[l|l.state != ON].forEach[l | l.sendCommand(ON)
  ]

end