4 * Author: brian@bevey.org
7 * Let me know when someone knocks on the door, but ignore
8 * when someone is opening the door.
13 namespace: "imbrianj",
14 author: "brian@bevey.org",
15 description: "Alert if door is knocked, but not opened.",
16 category: "Convenience",
17 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
18 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
22 section("When Someone Knocks?") {
23 input name: "knockSensor", type: "capability.accelerationSensor", title: "Where?"
26 section("But not when they open this door?") {
27 input name: "openSensor", type: "capability.contactSensor", title: "Where?"
30 section("Knock Delay (defaults to 5s)?") {
31 input name: "knockDelay", type: "number", title: "How Long?", required: false
34 section("Notifications") {
35 input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required: false
36 input "phone", "phone", title: "Send a Text Message?", required: false
51 subscribe(knockSensor, "acceleration.active", handleEvent)
52 subscribe(openSensor, "contact.closed", doorClosed)
56 state.lastClosed = now()
60 if((openSensor.latestValue("contact") == "closed") &&
61 (now() - (60 * 1000) > state.lastClosed)) {
62 log.debug("${knockSensor.label ?: knockSensor.name} detected a knock.")
63 send("${knockSensor.label ?: knockSensor.name} detected a knock.")
67 log.debug("${knockSensor.label ?: knockSensor.name} knocked, but looks like it was just someone opening the door.")
71 def handleEvent(evt) {
72 def delay = knockDelay ?: 5
73 runIn(delay, "doorKnock")
77 if(sendPushMessage != "No") {
78 log.debug("Sending push message")
83 log.debug("Sending text message")