How recursive program?

#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()
}
}

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

2 Likes

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.

3 Likes

@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.