mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-08 05:31:56 +00:00
Compare commits
2 Commits
PROD_2017.
...
MSA-1779-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a29df7693 | ||
|
|
2c4a177630 |
@@ -0,0 +1,73 @@
|
||||
definition(
|
||||
name: "Shut the windows!",
|
||||
namespace: "nick257",
|
||||
author: "Nick Mahon",
|
||||
description: "Notifies when last person leaves without closing doors or windows.",
|
||||
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("As the last of these persons leaves") {
|
||||
input "people", "capability.presenceSensor", multiple: true
|
||||
}
|
||||
section("Check that these are closed") {
|
||||
input "doors", "capability.contactSensor", multiple: true
|
||||
}
|
||||
section("Send Push Notification?") {
|
||||
input "sendPush", "bool", required: false,
|
||||
title: "Send Push Notification when Opened?"
|
||||
}
|
||||
section("Send a text message to this number (optional)") {
|
||||
input "phone", "phone", required: false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def installed() {
|
||||
log.debug "Installed with settings: ${settings}"
|
||||
initialize()
|
||||
}
|
||||
|
||||
def updated() {
|
||||
log.debug "Updated with settings: ${settings}"
|
||||
unsubscribe()
|
||||
initialize()
|
||||
}
|
||||
|
||||
def initialize() {
|
||||
subscribe(people, "presence", presence)
|
||||
}
|
||||
|
||||
def presence(evt)
|
||||
{
|
||||
log.debug "evt.name: $evt.value, $evt.deviceId"
|
||||
if (evt.value == "not present") {
|
||||
log.debug "isSomeonePresent()? ${isSomeonePresent()}"
|
||||
log.debug "isDoorsOpen()? ${isDoorsOpen()}"
|
||||
if (!isSomeonePresent() && isDoorsOpen()) {
|
||||
def device = people.find { it.id == evt.deviceId }
|
||||
log.debug "${device.displayName} left ${location.name} without closing ${isDoorsOpen().join(", ")}"
|
||||
|
||||
def message = "${device.displayName} left ${location.name} without closing ${isDoorsOpen().join(", ")}"
|
||||
if (sendPush) {
|
||||
sendPush(message)
|
||||
}
|
||||
if (phone) {
|
||||
sendSms(phone, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def isSomeonePresent() {
|
||||
log.debug "presence: $people.currentPresence"
|
||||
people.findAll{it.currentPresence == "present"}
|
||||
}
|
||||
|
||||
def isDoorsOpen() {
|
||||
log.debug "doorss: $doors.currentContact"
|
||||
doors.findAll{it.currentContact == "open"}
|
||||
}
|
||||
Reference in New Issue
Block a user