It’s basically the same code as activating a scene but easier. It’s triggered by the same Item but OFF-command instead of ON. The for loop goes through all items controlled by the scene, stores the storeItem name, then sends the i.state to the storeItem.
Hope that is understandable. You can probably write it cleaner than this, I’m a programming noob just copying, cutting and pasting different stuff that I find.
The only problem is that I would like to have the Scene activating item exposed to Google Home enabling activating scenes by voice. But if I for example say ,“Hey google, turn everything off.”, the scene switches would also turn off and erase all previous values stored. But that’s an other issue. For now i just never say, “Turn everything off”.
rule "Lighting Scene Store Generic"
when
Member of LightingScenes received command OFF //Use this line if you're on OpenHAB 2.3 or later
then
// Get the Group of Items that are controlled during this scene
val items = Scene_Items.members.findFirst[ grp | grp.name == triggeringItem.name+"_Items" ] as GroupItem
// Loop through all the Items controlled by this scene
items.members.forEach[ GenericItem i |
// Store scene Item name
val storeItem = triggeringItem.name+"_"+i.name
// sendCommand the Scene state
if(i.state !== null)
{storeItem.sendCommand(i.state.toString)}
]
end
Merry Christmas!