Give this a try. Didn’t test it myself so give it a test and let me know if it works or not
/**
* Left two open?
*
* Copyright 2014 Tim Slagle
*
* 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: "Left two open?",
namespace: "tslagle13",
author: "Tim Slagle",
description: "Checks two sets of doors to see if one or omre doors are left open from each set of doors.",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
)
preferences {
section("Which mode changes trigger the check?") {
input "newMode", "mode", title: "Which?", multiple: true, required: false
}
section("Which doors, windows, and locks should I check?"){
input "contacts1", "capability.contactSensor", title: "1st set of doors?", multiple: true, required: true
input "contacts2", "capability.contactSensor", title: "2nd set of doors?", multiple: true, required: false
}
section("Via a push notification and/or an SMS message"){
input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false
input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes","No"]
}
section("Settings"){
input "sendPushUnsecure", "enum", title: "Send a SMS/push notification when home is unsecure?", metadata:[values:["Yes","No"]], required:true
input "sendPushSecure", "enum", title: "Send a SMS/push notification when house is secure?", metadata:[values:["Yes","No"]], required:true
input "lockAuto", "enum", title: "Lock door(s) automatically if found unsecure?", metadata:[values:["Yes","No"]], required:false
}
section(title: "More options", hidden: hideOptionsSection()) {
input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
input "modes", "mode", title: "Only when mode is", multiple: true, required: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
unschedule()
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) {
def delay = (falseAlarmThreshold != null && falseAlarmThreshold != "") ? falseAlarmThreshold * 60 : 2 * 60
runIn(delay, "checkDoor")
}
}
def checkDoor(evt) {
if(allOk){
log.debug("checkDoor")
def openContacts1 = contacts1.findAll { it?.latestValue("contact") == 'open' }
def openContacts2 = contacts2.findAll { it?.latestValue("contact") == 'open' }
if (openContacts1 && openContacts2){
if (openContacts && openLocks){
def message = "ALERT: ${openContacts.join(', ')} and ${openLocks.join(', ')} are open"
sendUnsecure(message)
}
}
else if (!openContacts && !openLocks){
def message = "Both sets of doors are closed"
sendSecure(message)
}
}
}
private sendSecure(msg) {
log.debug("checking push")
if(sendPushSecure != "No"){
if (!phone || pushAndPhone != "No") {
log.debug "sending push"
sendPush(msg)
}
if (phone) {
log.debug "sending SMS"
sendSms(phone, msg)
}
}
else {
log.debug("Home is secure but settings don't require push")
}
log.debug(msg)
}
private sendUnsecure(msg) {
log.debug("checking push")
if(sendPushUnsecure != "No") {
log.debug("Sending push message")
if (!phone || pushAndPhone != "No") {
log.debug "sending push"
sendPush(msg)
}
if (phone) {
log.debug "sending SMS"
sendSms(phone, msg)
}
}
else {
log.debug("Home is unseecure but settings don't require push")
}
log.debug(msg)
}
private getAllOk() {
modeOk && daysOk && timeOk
}
private getModeOk() {
def result = !modes || modes.contains(location.mode)
log.trace "modeOk = $result"
result
}
private getDaysOk() {
def result = true
if (days) {
def df = new java.text.SimpleDateFormat("EEEE")
if (location.timeZone) {
df.setTimeZone(location.timeZone)
}
else {
df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
}
def day = df.format(new Date())
result = days.contains(day)
}
log.trace "daysOk = $result"
result
}
private getTimeOk() {
def result = true
if (starting && ending) {
def currTime = now()
def start = timeToday(starting).time
def stop = timeToday(ending).time
result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
}
log.trace "timeOk = $result"
result
}
private hhmm(time, fmt = "h:mm a")
{
def t = timeToday(time, location.timeZone)
def f = new java.text.SimpleDateFormat(fmt)
f.setTimeZone(location.timeZone ?: timeZone(time))
f.format(t)
}
private getTimeIntervalLabel()
{
(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
}
private hideOptionsSection() {
(starting || ending || days || modes) ? false : true
}