4 * Author: brian@bevey.org
7 * Watch a series of sensors for any anomalies for securing a safe or room.
12 namespace: "imbrianj",
13 author: "brian@bevey.org",
14 description: "Watch a series of sensors for any anomalies for securing a safe.",
15 category: "Safety & Security",
16 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
17 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
21 section("Things to secure?") {
22 input "contact", "capability.contactSensor", title: "Contact Sensor", required: false
23 input "motion", "capability.motionSensor", title: "Motion Sensor", required: false
24 input "knock", "capability.accelerationSensor", title: "Knock Sensor", required: false
25 input "axis", "capability.threeAxis", title: "Three-Axis Sensor", required: false
28 section("Temperature monitor?") {
29 input "temp", "capability.temperatureMeasurement", title: "Temperature Sensor", required: false
30 input "maxTemp", "number", title: "Max Temperature (°${location.temperatureScale})", required: false
31 input "minTemp", "number", title: "Min Temperature (°${location.temperatureScale})", required: false
34 section("When which people are away?") {
35 input "people", "capability.presenceSensor", multiple: true
38 section("Notifications?") {
39 input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required: false
40 input "phone", "phone", title: "Send a Text Message?", required: false
43 section("Message interval?") {
44 input name: "messageDelay", type: "number", title: "Minutes (default to every message)", required: false
58 subscribe(contact, "contact.open", triggerContact)
59 subscribe(motion, "motion.active", triggerMotion)
60 subscribe(knock, "acceleration.active", triggerKnock)
61 subscribe(temp, "temperature", triggerTemp)
62 subscribe(axis, "threeAxis", triggerAxis)
65 def triggerContact(evt) {
66 if(everyoneIsAway()) {
67 send("Safe Watch: ${contact.label ?: contact.name} was opened!")
71 def triggerMotion(evt) {
72 if(everyoneIsAway()) {
73 send("Safe Watch: ${motion.label ?: motion.name} sensed motion!")
77 def triggerKnock(evt) {
78 if(everyoneIsAway()) {
79 send("Safe Watch: ${knock.label ?: knock.name} was knocked!")
83 def triggerTemp(evt) {
84 def temperature = evt.doubleValue
86 if((maxTemp && maxTemp < temperature) ||
87 (minTemp && minTemp > temperature)) {
88 send("Safe Watch: ${temp.label ?: temp.name} is ${temperature}")
92 def triggerAxis(evt) {
93 if(everyoneIsAway()) {
94 send("Safe Watch: ${axis.label ?: axis.name} was tilted!")
98 private everyoneIsAway() {
101 if(people.findAll { it?.currentPresence == "present" }) {
105 log.debug("everyoneIsAway: ${result}")
111 def delay = (messageDelay != null && messageDelay != "") ? messageDelay * 60 * 1000 : 0
113 if(now() - delay > state.lastMessage) {
114 state.lastMessage = now()
115 if(sendPushMessage == "Yes") {
116 log.debug("Sending push message.")
121 log.debug("Sending text message.")
129 log.info("Have a message to send, but user requested to not get it.")