#You read code, help me!
Definition(
name: “Alarm when motion active in Period time”,
namespace: “KichBan”,
author: “Võ Thanh Minh”,
description: “cenario-based device driver habits, preferences and orders”,
category: “Safety & Security”,
iconUrl: “https://s3.amazonaws.com/vtmsmartthings/vtms60.png”,
iconX2Url: “https://s3.amazonaws.com/vtmsmartthings/vtms120.png”,
iconX3Url: “https://s3.amazonaws.com/vtmsmartthings/vtms120.png”)
preferences {
section("Enable or Disable this action ")
{
input name:“sel”,type:“enum”, title:“Select [on/off]”, options: [“on”,“off”], defaulValue:“off”
}
section(“Select period time this action”)
{
input name: “timeB”, type: “time”, title: "Set time start"
input name: “timeE”, type: “time”, title: “Set time end”
}
section(“Alarm”)
{
input(“alamH”,“capability.alarm”,title:“Alarm”)
}
}
section(“Motion sensor”)
{
input(“motionCD”, “capability.motionSensor”,title:“Select motion sensor”)
}
def installed()
{
init()
}
def updated()
{
init()
}
def init()
{
subscribe(motionCD,“motion”,motion_CD)
subscribe(alamH,“alarm”,alam_H)
}
def motion_CD(evt)
{
if (evt.value==“active”)
{
if ((now()>=timeB)&&(now()<=timeE)&&(sel=="on"))
{
alamH.both();
schedule(now()+10000,alamF) // turn off in 10 second
}
}
}
def alamF()
{
alamH.off()
}