[SOLVED] Switch multiple timer in succession

Use a simple state machine:

var Timer tLight = null
var Integer iStep = 0

rule "poort loop licht"
when
    Item PO_open_lamp_uit received command ON
then
    tLight?.cancel
    iStep = 0
    tLight = createTimer(now.plusSeconds(5), [
        iStep ++ // or iStep = iStep + 1
        switch iStep {
            case 1: {
                Output11_3.sendCommand(ON)
                tLight.reschedule(now.plusSeconds(2))
            }
            case 2: {
                Output11_4.sendCommand(ON)
                tLight.reschedule(now.plusSeconds(2))
            }
            case 3: {
                Output11_2.sendCommand(ON)
                tLight.reschedule(now.plusSeconds(2))
            }
            case 4: {
                Output12_1.sendCommand(ON)
                tLight.reschedule(now.plusSeconds(2))
            }
            case 5: {
                Output12_2.sendCommand(ON)
                tLight.reschedule(now.plusSeconds(2))
            }
            case 6: {
                Output17_3.sendCommand(ON)
                PO_open_lamp_uit.sendCommand(OFF)
                tLight.reschedule(now.plusSeconds(3))
            }
            default: {
                Output11_2.sendCommand(OFF)
                tLight = null
            }
        }
    ]) 
end
5 Likes