How recursive program?


(Võ Thanh Minh) #1

#I can call recursively lightOFF?

def lightOFF()
{
def t=motionCD.currentValue(“motion”)
if(t==“active”)
{
def timeP=timeofP*60
runIn(timeP,lightOFF) //call recursive
}
else
{
sw1.off()
}
}


(John) #2

That’s not recursive. That just asks for lightOFF() to be called again in the future by the scheduler.


(Tim Slagle) #3

I would recommend something like this.

....    
def lightTurnedOn() {
        schedule("0 0/"${timeofP}" * 1/1 * ? *", lightCheck)
}

def lightCheck() {
        def t=motionCD.currentValue("motion")
        if(t != "active") {
                sw1.off()
                unschedule(lightCheck)
        } else {
                log.info "Motion is active, not turning off the light"
        }
}

....

This way your concerns are separated and scheduling is handled outside of the method.


(Võ Thanh Minh) #4

@slagle and all help me

I want to write the following program

if (motion senser active < 1 munites) then alarm is strobe()
if if (motion senser active > 1 munites) then alarm is siren()

Thanks.