You Left Something Open App with SmartThings

04 Nov You Left Something Open App with SmartThings

This SmartThings SmartApp checks all your doors when you enter a specific mode like Away or Night and notifies immediately if something is left open.

/**
 * You Left It Open
 *
 * Copyright 2014 Brian Critchlow
 * Based on Its too cold code by SmartThings
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 * for the specific language governing permissions and limitations under the License.
 *
 */

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)
    }
}
No Comments

Post A Comment