Combine different rules and triggers into 1 rule

Hi everyone, I have a bunch of Xiaomi door/window sensors on external doors and have just made a bunch of rules to turn on lights when doors are opened after dark. Although untested yet, think they will work.
I would like to combine them into 1 rule. Here are the rules.

var Timer sdtimer = null

rule "Open Front Glass Door"

when
    Item Front_Glass_Door_Status changed to OPEN 
  then
    
    if(NightTime.state == (ON)) {
        SW2_02_1.sendCommand(ON)
        SW2_02_2.sendCommand(ON)
        if(Rule_Disable != (ON)) {
        sdtimer?.cancel
        sdtimer = createTimer(now.plusSeconds(300)) [|
        SW2_02_1.sendCommand(OFF)
        SW2_02_2.sendCommand(OFF)
    ]
    }
    }
end

And this one

var Timer bdtimer = null

rule "Open Back Glass Door"

when
    Item Back_Door_Status changed to OPEN
then
    
    if(NightTime.state == (ON)) {
        T2_02_2.sendCommand(ON)
        T2_01_1.sendCommand(ON)
        if(Rule_Disable != (ON)) {
        bdtimer?.cancel
        bdtimer = createTimer(now.plusSeconds(300)) [|
        T2_02_2.sendCommand(OFF)
        T2_01_1.sendCommand(OFF)
    ]
    }
    }
end

And this one for example

var Timer fdtimer = null

rule "Open Front Door"

when
    Item Front_Door_Status changed to OPEN
then
          
    if(NightTime.state == (ON)) {
		SW2_01_1.sendCommand(ON)
		SW2_01_2.sendCommand(ON)
		if(Rule_Disable != (ON)) {
		fdtimer?.cancel
		fdtimer = createTimer(now.plusSeconds(300)) [|
  		SW2_01_1.sendCommand(OFF)
		SW2_01_2.sendCommand(OFF)
	]
	}
	}
end

The sensors are all members of a group so I think I could use

when member of group Door_Sensors changed to OPEN

as the trigger, but really have little idea what to do after that. From what others have shown me over the last few days, I need if triggering.item == something do xyz. but rather than use multiple if statements I would like to use the switch case but have no idea how.
as always, any help appreciated.
James

See this:
You’ll have to rename some items…

I have created a rule for this. The idea bhind my rule is, that if i open a door a light is switched on and if the door is closed the light is switched off after a certain amount of time.

Contacts , corresponding lights and switchoff time is stored in an array.

//---------------------------------------------------------------------------------------------------------------------
//
//  Imports
//
//---------------------------------------------------------------------------------------------------------------------
import org.eclipse.smarthome.model.script.ScriptServiceUtil
import java.util.Map
import java.util.List


//---------------------------------------------------------------------------------------------------------------------
//
//  Global constants and variables
//
//---------------------------------------------------------------------------------------------------------------------
val IDX_TIMEOUT     = 0 // Timeout value in seconds. After this time the target should change from ON-State to OFF-State
val IDX_TARGET      = 1 // Name of the target item

val EDGE_NOTHING    = 0
val EDGE_RISING     = 1
val EDGE_FALLING    = 2

val Map<String, List<String>> actionMap = newHashMap (
                                                        "GF_GT_Multisensor"         ->  newArrayList("300", "GF_GT_CeilingLight_State"),
                                                        "GF_HW_CellarDoorContact"   ->  newArrayList("300", "CE_EC_DoubleSwitch_State01"),
                                                        "CE_EC_MotionSensor"        ->  newArrayList("300", "CE_EC_DoubleSwitch_State01"),
                                                        "CE_LD_Multisensor"         ->  newArrayList("300", "GF_HW_Stairlight_State"),
                                                        "GF_BA_Multisensor"         ->  newArrayList("300", "GF_BA_CeilingRGB_State"),
                                                        "PR_ME_MotionSensor"        ->  newArrayList("300", "PR_ME_WallLight_State")
                                                     )

val Map<String, Timer> actionTimer = newHashMap


//---------------------------------------------------------------------------------------------------------------------
//
//  Rule:   Triggered Lighting
//
//---------------------------------------------------------------------------------------------------------------------
rule "Triggered Lighting"
when
    
    Member of gPIRTrigger changed or 
    Member of gContactTrigger changed

then
    
    val String ruleIdentifier = "userule.TriggeredLighting"

    var Integer edgeKey = EDGE_NOTHING

    var String triggerKey = triggeringItem.name.substring(0, triggeringItem.name.lastIndexOf('_'))
    var String targetKey = actionMap.get(triggerKey).get(IDX_TARGET)
    var GenericItem targetItem = ScriptServiceUtil.getItemRegistry.getItem(targetKey) as GenericItem
    var Integer timeoutValue = Integer::parseInt(actionMap.get(triggerKey).get(IDX_TIMEOUT))


    // Determine if we have the rising edge or the falling edge
    if (((triggeringItem instanceof ContactItem) && (triggeringItem.state == OPEN)) || ((triggeringItem instanceof SwitchItem) && (triggeringItem.state == ON))) {

        edgeKey = EDGE_RISING

    } else if (((triggeringItem instanceof ContactItem) && (triggeringItem.state == CLOSED)) || ((triggeringItem instanceof SwitchItem) && (triggeringItem.state == OFF))) {

        edgeKey = EDGE_FALLING

    }

    // Now we know  what to do
    switch edgeKey {
        case EDGE_RISING : {

            actionTimer.get(targetKey)?.cancel()
            targetItem.sendCommand(ON)
            
            logInfo(ruleIdentifier, "Rising edge detected: Running timer canceled and target {} set to ON!", targetKey)

        }

        case EDGE_FALLING : {

            actionTimer.put(targetKey, createTimer(now.plusSeconds(timeoutValue)) [ |

                actionTimer.put(targetKey, null)
                targetItem.sendCommand(OFF)
                
                logInfo(ruleIdentifier, "Target {} has been set to OFF after {} seconds!", targetKey, timeoutValue.toString)

            ])
            
            logInfo(ruleIdentifier, "Falling edge detected: Target {} will be set to OFF after {} seconds!", targetKey, timeoutValue.toString)

        }

        default : {

            logError(ruleIdentifier, "Argh, this line should never be executed - Something must have gone wrong!")

        }

    }

end

may this is a little inspiration. Do not hestitate and ask questions.

Thomas