One Switch Controlling a Changing Configuration of Lights

I have a shop with 24 Lights. Depending on the project I want to contol which lights come on and off when I am working. And I wanted to remember the last configuration. I have a Z-Wave wall switch that controls an entry light. I have 24 shop lights that are just switchable Z-Wave wall receptacles.
So here is the strategy I used to address this.
When the controlling light switch is ON, I mark the controlled lights as Managed or UnManaged if they are tuned on or off respectively.
When the controlling light changes state, I also set all of the managed devices to the same state.
And I wanted a minimal amount of things added to the UI.
[hr]
And here is the details of the implementation:

I create a Scene called Shop Light Controller
This scene has 2 * 24 + 2 or 50 Events.

[ul][li]24 On Events, 1 for each controlled light[/li]
[li]24 Off Events, 1 for each controller light[/li]
[li]Controlling Switch On Event[/li]
[li]Controlling Switch Off Event[/li][/ul]

In my case the Controlling Switch Device is 30.
For the sake of this example the Controlled Lights have Device IDs 31 thru 54
What I did was to add Luup code to each of the EVENTS of the Scene (not the Scene Itself)
Here is the code for each:

[ul][li]24 Controlled Light On Events:

SwPwrSvs = "urn:upnp-org:serviceId:SwitchPower1"; ConStatus = luup.variable_get(SwPwrSvs, "Status", 30) if (ConStatus == "1") then luup.variable_set(SwPwrSvs, "Managed", 1, 31) end
And replace 31 with the Device ID of the Light that this is an event for. [/li] [li]24 Controlled Light Off Events:
SwPwrSvs = "urn:upnp-org:serviceId:SwitchPower1"; ConStatus = luup.variable_get(SwPwrSvs, "Status", 30) if (ConStatus == "1") then luup.variable_set(SwPwrSvs, "Managed", 0, 31) end
And replace 31 with the Device ID of the Light that this is an event for. [/li] [li]Controlling Switch On Event:
SwPwrSvs = "urn:upnp-org:serviceId:SwitchPower1" ConStatus = luup.variable_get(SwPwrSvs, "Status", 30) Table = {31, 32, 33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54} for i,dev in ipairs(Table) do mv = luup.variable_get(SwPwrSvs, "Managed", dev) if (mv == "1") then luup.call_action(SwPwrSvs, "SetTarget", {newTargetValue=ConStatus}, dev) end end
I used a table because chances are the devices will not have sequential device IDs. [/li] [li]Controlling Switch Off Event: Use the same code as the On Event[/li][/ul]