2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
13 * Elder Care: Slip & Fall
21 name: "Elder Care: Slip & Fall",
22 namespace: "smartthings",
23 author: "SmartThings",
24 description: "Monitors motion sensors in bedroom and bathroom during the night and detects if occupant does not return from the bathroom after a specified period of time.",
26 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/calendar_contact-accelerometer.png",
27 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/calendar_contact-accelerometer@2x.png"
31 section("Bedroom motion detector(s)") {
32 input "bedroomMotion", "capability.motionSensor", multiple: true
34 section("Bathroom motion detector") {
35 input "bathroomMotion", "capability.motionSensor"
37 section("Active between these times") {
38 input "startTime", "time", title: "Start Time"
39 input "stopTime", "time", title: "Stop Time"
41 section("Send message when no return within specified time period") {
42 input "warnMessage", "text", title: "Warning Message"
43 input "threshold", "number", title: "Minutes"
45 section("To these contacts") {
46 input("recipients", "contact", title: "Recipients", description: "Send notifications to") {
47 input "phone1", "phone", required: false
48 input "phone2", "phone", required: false
49 input "phone3", "phone", required: false
55 log.debug "Installed with settings: ${settings}"
60 log.debug "Updated with settings: ${settings}"
68 subscribe(bedroomMotion, "motion.active", bedroomActive)
69 subscribe(bathroomMotion, "motion.active", bathroomActive)
72 def bedroomActive(evt) {
73 def start = timeToday(startTime, location?.timeZone)
74 def stop = timeToday(stopTime, location?.timeZone)
76 log.debug "bedroomActive, status: $state.ststus, start: $start, stop: $stop, now: $now"
77 if (state.status == "waiting") {
78 log.debug "motion detected in bedroom, disarming"
79 unschedule("sendMessage")
83 if (start.before(now) && stop.after(now)) {
84 log.debug "motion in bedroom, look for bathroom motion"
85 state.status = "pending"
88 log.debug "Not in time window"
93 def bathroomActive(evt) {
94 log.debug "bathroomActive, status: $state.status"
95 if (state.status == "pending") {
96 def delay = threshold.toInteger() * 60
97 state.status = "waiting"
98 log.debug "runIn($delay)"
99 runIn(delay, sendMessage)
104 log.debug "sendMessage"
105 def msg = warnMessage
108 if (location.contactBookEnabled) {
109 sendNotificationToContacts(msg, recipients)