From 99876821dca175c8c6c6965f8e3c123016a93d1d Mon Sep 17 00:00:00 2001 From: Akbur Ghafoor Date: Fri, 9 Oct 2015 16:13:29 -0500 Subject: [PATCH] MSA-611: A security focused SmartApp which allows you to automatically check if any window with a contact sensor is left accidentally open each night. Sends an SMS if the contact sensor is open at the scheduled time. --- .../check-window-is-closed-at-night.groovy | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 smartapps/akbur/check-window-is-closed-at-night.src/check-window-is-closed-at-night.groovy diff --git a/smartapps/akbur/check-window-is-closed-at-night.src/check-window-is-closed-at-night.groovy b/smartapps/akbur/check-window-is-closed-at-night.src/check-window-is-closed-at-night.groovy new file mode 100644 index 0000000..8183c3b --- /dev/null +++ b/smartapps/akbur/check-window-is-closed-at-night.src/check-window-is-closed-at-night.groovy @@ -0,0 +1,61 @@ +definition( + name: "Check window is closed at night", + namespace: "akbur", + author: "Akbur Ghafoor", + description: "Checks if your window is closed at night - if not, sends an SMS alert.", + category: "Convenience", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/window_contact@2x.png" +) + +preferences { + section("When the window is open at night...") { + input "contact1", "capability.contactSensor", title: "Where?" + } + section("Text me at...") { + input("recipients", "contact", title: "Send notifications to") { + input "phone1", "phone", title: "Phone number? (in interntional format, starting with +, e.g. +447739123456)" + } + } + + section("Time to check at night") { + input "time1", "time" + } +} + +def installed() +{ + subscribe(contact1, "contact", contactHandler) + schedule(time1, checkWindowsHandler) +} + +def updated() +{ + unsubscribe() + subscribe(contact, "contact", contactHandler) + schedule(time1, checkWindowsHandler) +} + +def checkWindowsHandler() +{ + if (state.windowsopen) + { + sendSms(phone1, "WARNING: Your ${contact1.label ?: contact1.name} is OPEN.") + } +} + +def contactHandler(evt) { + + if("open" == evt.value) + { + // contact is open, log it for the night check + log.debug "Contact is in ${evt.value} state" + state.windowsopen = true; + } + if("closed" == evt.value) + { + // contact was closed, log it for the night check + log.debug "Contact is in ${evt.value} state" + state.windowsopen = false; + } +} \ No newline at end of file