"Trinary Switch" - if condition in case rule

Another thing… It’s a bad idea to use Thread::sleep() for long sleep statements, as it would block a rule thread. I would consider to do it with a timer as a very simple state machine:

var Timer tAblauf = null                                                                            // timer of state machine
var Number nSchritt                                                                                 // counter of state machine

rule "Alarmanlage"
when
    Member of GreedALARM changed to OPEN 
then
    if(!(alarmmodus.state instanceof Number)) {                                                     // check null state
        logInfo("Alarm","Alarmmodus not set!")
        return;
    }
    val Number nAl = alarmmodus.state as Number
    val String sModus = switch(nAl){case 0:"AUS" case 1:"AN" case 2:"AUTO"}
    val String sMyLog = "Alarmanlage [" + sModus + "]: Reed ausgelöst" + if(nAl==0) ", aber Modus:AUS - " else " - "
    logInfo("Alarm", sMyLog + triggeringItem.name)
    switch  (nAl) {
        case 0 : {
                                                                                                    // empty :)
        }
        case 1 : {
            nSchritt = 1                                                                            // set counter of state machine
            if(tAblauf !== null) tAblauf.cancel
            tAblauf = createTimer(now, [ |                                                          // start state machine
                switch (nSchritt) {
                    case 1 : {                                                                      // 1st step
                        alarmswitch.sendCommand(ON)
                        out_xiao_gateway_soundvolume.sendCommand(2)
                        out_xiao_gateway_sound.sendCommand(11)
                        tAblauf.reschedule(now.plusSeconds(2))                                      // set timer for next step
                    }
                    case 2 : {                                                                      // 2nd step
                        out_xiao_gateway_sound.sendCommand(10000)
                        out_xiao_gateway_soundvolume.sendCommand(0)
                        tAblauf.reschedule(now.plusSeconds(3))                                      // set timer for next step
                    }
                    case 3: {                                                                       // 3rd step
                        if(alarmswitch.state != OFF) {                                              // alarm stopped?
                            val String sAlarm = if(alarmstill.state == ON) "stiller" else "lauter"
                            logInfo("Alarm", "--> Alarmanlage [AN]: " + sAlarm + " Alarm")
                            // sendPushoverMessage(pushoverBuilder("ALARMANLAGE [AN]: Reed-Kontakt ausgelöst - " + sAlarm + " Alarm").withPriority(1).withSound("spacealarm"))
                            EventLog.postUpdate("Alarmanlage [AN]: " + sAlarm + " Alarm")
						}	
                        tAblauf.reschedule(now.plusSeconds(3))                                      // set timer for next step
                    }
                    case 4: {                                                                       // last step
                        alarmswitch.sendCommand(OFF)
                        tAblauf = null
                    }
                }
                nSchritt += 1                                                                       // count up
            ])
        }
        case 2 : {
                                                                                                    // code for auto-mode tbd
        }
    }
end

rule "Alarmanlage 2"
when
    Item alarmswitch changed to OFF                                                                 // alarm stopped
then
    if(tAblauf !== null && nSchritt > 2) {                                                          // only stop state machine after the 2nd step!
        tAblauf.cancel
        tAblauf = null
    }
end