var motion= getEMParam("motion"); var seconds1= getEMParam("seconds"); log("motion Value "+ motion); var minutes= getEMParam("minutes"); log("motion Value "+ minutes); var light= getEMParam("light"); var time_left= getEMParam("time_left"); log("motion Value "+ light); var currentMinutes= 0; function countDown(){ currentMinutes= currentMinutes-1; log("currentMinutes "+ currentMinutes); setValue(time_left,currentMinutes); if(currentMinutes==0){ setValue(light, 0); log("light "+ light); log ("Stop countdown"); removeInterval("countDown"); } } function motion_detection(){ var sensor = getValueAsBoolean(motion); log("sensor Value " + sensor); var turnOn = getValueAsBoolean(light); log("turnOn Value " + turnOn); if(sensor==true){ log("sensor true "); setValue(light, 1); log ("Stop countdown"); removeInterval("countDown"); }else{ log("sensor false "); currentMinutes= getValueAsInt(seconds1); setValue(time_left,currentMinutes); setInterval(1, "countDown"); } } setTrigger(motion, "motion_detection");