Skip to content

Instantly share code, notes, and snippets.

@docwisdom
Last active February 25, 2019 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save docwisdom/2f82e9b11aa5ba54ae66 to your computer and use it in GitHub Desktop.
Save docwisdom/2f82e9b11aa5ba54ae66 to your computer and use it in GitHub Desktop.
You Left It Open SmartApp
definition(
name: "You Left It Open",
namespace: "docwisdom",
author: "Brian Critchlow",
description: "Notifies if contact sensors are open when a mode changes",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/bon-voyage%402x.png"
)
preferences
{
section("When I enter these modes") {
input "newMode", "mode", title: "Modes?", multiple: true, required: true
}
section("Check that these are closed") {
input "doors", "capability.contactSensor", multiple: true, required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
if (newMode != null) {
subscribe(location, modeChangeHandler)
}
}
def modeChangeHandler(evt) {
log.debug "Mode change to: ${evt.value}"
// Have to handle when they select one mode or multiple
if (newMode.any{ it == evt.value } || newMode == evt.value) {
checkDoors()
}
}
def checkDoors() {
def open = doors.findAll { it?.latestValue("contact") == "open" }
if(open) {
def msg = "${doors.name} was left open!"
log.info msg
sendPush(msg)
} else {
def msg = "All doors & windows are closed."
log.info msg
sendNotificationEvent(msg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment