Dimm room lights, but how to dim back on?

So we have several downlights(color items) but also so normal wall lights(switch items). We then have a dimmer item to dim the lights, however my wife wants now to switch off the wall lights if lights are dimmed below 50%. This is fine, however I can not figure out how to dim they back on, if we dim them down to 30% and then later back up to 70%. My rule is as follows:

rule "Update dimmers"
when
    Member of Group_Dimmers changed 
then
    logInfo("Notification", "Dimmer changed: " + triggeringItem.name.split("_").get(0))
    val roomName= triggeringItem.name.split("_").get(0) as String
    val group =ScriptServiceUtil.getItemRegistry.getItem("Group_"+roomName +"_Lights") as GroupItem
    val dimmer=ScriptServiceUtil.getItemRegistry.getItem(roomName +"_Dimmer") as DimmerItem

    if(group === null) {
        logError("admin", "Cannot find Item " +roomName +"_Dimmer")
        return;
    }

    group.members.forEach[ i | 
        if (i.state!=OFF){
            if(i instanceof SwitchItem) {
                if (dimmer.state<50){
                    i.sendCommand(OFF)
                }
            }
            else if(i instanceof DimmerItem) {
                
            }
            else if(i instanceof ColorItem) {
            }
            else{

            }
            
        }
            
        ]


end

the problem is here:
i.sendCommand(OFF)… here I need to remember which light I switched off so that I later can turn it back on… Is this super special feature even feasible? Make a nested dictionary with room name and all the items switched off?

Why do you need to remember which lights were switched off? Can’t you just use the same rule to turn on the lights in the group if the dimmer is >50?

skatun
Kim Skatun
18h
So we have several downlights(color items) but also so normal wall lights(switch items). We then have a dimmer item to dim the lights, however my wife wants now to switch off the wall lights if lights are dimmed below 50%. This is fine, however I can not figure out how to dim they back on, if we dim them down to 30% and then later back up to 70%. My rule is as follows:

rule "Update dimmers"
when
    Member of Group_Dimmers changed 
then
    logInfo("Notification", "Dimmer changed: " + triggeringItem.name.split("_").get(0))
    val roomName= triggeringItem.name.split("_").get(0) as String
    val group =ScriptServiceUtil.getItemRegistry.getItem("Group_"+roomName +"_Lights") as GroupItem
    val dimmer=ScriptServiceUtil.getItemRegistry.getItem(roomName +"_Dimmer") as DimmerItem

    if(group === null) {
        logError("admin", "Cannot find Item " +roomName +"_Dimmer")
        return;
    }

    group.members.forEach[ i | 
            if(i instanceof SwitchItem) {
                if (dimmer.state<50){
                    i.sendCommand(OFF)
                } else {
                    i.sendCommand(ON)
                }
            }
            else if(i instanceof DimmerItem) {
                
            }
            else if(i instanceof ColorItem) {
            }
            else{

            }
            
            
        ]


end

Solved it more or less, only minor bug if scene=0 and you dim to on, the scene in UI does not get updated…

rule "Update dimmers"
when
	Member of Group_Dimmers changed 
then
	logInfo("Notification", "Dimmer changed: " + triggeringItem.name.split("_").get(0))
	val roomName= triggeringItem.name.split("_").get(0) as String
	val group =ScriptServiceUtil.getItemRegistry.getItem("Group_"+roomName +"_Lights") as GroupItem
	val dimmer=ScriptServiceUtil.getItemRegistry.getItem(roomName +"_Dimmer") as DimmerItem

	if(group === null || dimmer === null) {
        logError("admin", "Cannot find Item " +roomName +"_Dimmer or Group_"+roomName +"_Lights")
        return;
    }

	group.members.forEach[ i | 
		// We need to grab active scene, transform it to group
		val scene =ScriptServiceUtil.getItemRegistry.getItem(roomName +"_Scene") as NumberItem 
		//Just a nifty touch to update UI
		//if (scene.state==0 ){
			//scene.postUpdate(1)
		//}
		val sceneGroup = ScriptServiceUtil.getItemRegistry.getItem( "Group_"+roomName +"_Lights" +transform("MAP", roomName+ ".map", ""+scene.state) ) as GroupItem
		// only dim lights if its a member of the selected group
		if (i.getGroupNames.contains(sceneGroup.name)){
			//Coloritems and dimmer items
			if(i instanceof ColorItem || i instanceof DimmerItem) {
				logInfo("Notification", "Icolor/dimmeritem: " + i.name)
				i.sendCommand(dimmer.state)	
			}
			//Switch item
			else if(i instanceof SwitchItem) {
				logInfo("Notification", "Iswitchitem: " + i.name)
				// So normal lights get switched off when dim value passes 50%
				if (dimmer.state<50){
					i.sendCommand(OFF)
				}
				//it could have been dimmed below 50% and then dimmed back up again
				else{
					i.sendCommand(ON)
				}
			}
			//In case someone added light group to non light item
			else{
				logError("admin", "item in wrong group " +i.name)
			}	
		}		
	]
end