Problem getting nested 'if' statements to work

I’ve got a rule that works well, but I’m trying to do some more conditional testing within each execution segment.

If I don’t try and do the second stage of ‘if’ testing, i.e. the if(daylight.state == ON) and if(daylight.state == OFF) sections, the rule works fine. I’ve tried to debug errors with the ‘daylight’ item (it’s driven by Astro, and is working fine in the sitemap) and everything else I can think of. But it looks like it should work to me! What am I missing?

I do get:

2015-12-16 23:42:39.846 [INFO ] [org.openhab.model.script.Alarm] - Partition Disarmed

in the log, but the rule doesn’t get any further.

As I say I get a perfect result if I don’t do the second level of ‘if’ testing:

2015-12-16 23:16:15.697 [INFO ] [org.openhab.model.script.Alarm] - Partition Disarmed
2015-12-16 23:16:18.474 [INFO ] [org.openhab.model.script.Alarm] - Starting delay period of 10 seconds
2015-12-16 23:16:29.449 [DEBUG] [.l.internal.LightwaveRfBinding] - internalReceiveCommand(Light_rm01_kitchen_spots,OFF) is called!
2015-12-16 23:16:29.450 [DEBUG] [.b.l.i.LightwaveRFSenderThread] - Sending command[235,!R1D1F0

Here’s the rule:

rule "Alarm State Change Lighting Actions"
when     Item PARTITION1_ARM_MODE changed or
        Item Light_Test changed
then
    if(PARTITION1_ARM_MODE.state == 0) {
        
        logInfo("Alarm","Partition Disarmed") 
            val message = "The alarm is now\n\nDisarmed and is ready\n\nRegards,\n\nopenHab"
            sendMail(mailTo, "Alarm Disarmed", message)
                
                if(daylight.state == ON)    {
                    logInfo("Alarm","Starting delay period of 10 seconds, it's daylight so lights out")
                        waitTimer1 = createTimer(now.plusSeconds(10), [|
                        night.members.forEach[light |  // for each light
                        light.sendCommand(OFF)   
                    logInfo("Alarm","Light OFF Commands Sent")
                }
                
                if(daylight.state == OFF)    {
                    logInfo("Alarm","Starting delay period of 10 seconds, it's night so lights to normal")
                        waitTimer2 = createTimer(now.plusSeconds(10), [|
                        normal.members.forEach[light |  // for each light
                        light.sendCommand(ON)   
                    logInfo("Alarm","Lights to Normal Commands Sent")
                }    
    }

Where do you close your createTimer and .forEach - squre-brackets?
You only seem to open them!

2 Likes

That’s the one! Midnight coding once again…

Thanks