2 * Copyright 2017 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.
15 * Author: Juan Pablo Risso
22 namespace: "smartthings",
23 author: "SmartThings",
24 description: "Receive notifications when anything happens in your home.",
25 category: "SmartSolutions",
26 iconUrl: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/Cat-SafetyAndSecurity.png",
27 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/SafetyAndSecurity/Cat-SafetyAndSecurity@2x.png",
32 page name: "mainPage", install: true, uninstall: true
36 dynamicPage(name:"mainPage") {
37 section("Choose one or more, when..."){
38 input "smokeDevices", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true
39 input "carbonMonoxideDevices", "capability.carbonMonoxideDetector", title: "Carbon Monoxide Detected", required: false, multiple: true
41 section("Turn off these thermostats"){
42 input "thermostatDevices", "capability.thermostat", title: "Thermostats", required: true, multiple: true
44 section("Send this message (optional, sends standard status message if not specified)"){
45 input "messageText", "text", title: "Message Text", required: false
48 if (location.contactBookEnabled || phone) {
49 section("Via a push notification and/or an SMS message"){
50 input("recipients", "contact", title: "Send notifications to") {
51 input "phone", "phone", title: "Enter a phone number to get SMS", required: false
52 paragraph "If outside the US please make sure to enter the proper country code"
53 input "pushAndPhone", "enum", title: "Notify me via Push Notification", required: false, options: ["Yes", "No"]
57 section("Via a push notification"){
58 input "pushAndPhone", "enum", title: "Notify me via Push Notification", required: false, options: ["Yes", "No"]
61 section("Minimum time between messages (optional, defaults to every message)") {
62 input "frequency", "decimal", title: "Minutes", required: false
68 log.debug "Installed with settings: ${settings}"
73 log.debug "Updated with settings: ${settings}"
78 def subscribeToEvents() {
79 subscribe(smokeDevices, "smoke.detected", eventHandler)
80 subscribe(smokeDevices, "smoke.tested", eventHandler)
81 subscribe(smokeDevices, "carbonMonoxide.detected", eventHandler)
82 subscribe(carbonMonoxideDevices, "carbonMonoxide.detected", eventHandler)
85 def eventHandler(evt) {
86 log.debug "Notify got evt ${evt}"
87 // Turn off thermostat
88 thermostatDevices*.setThermostatMode("off")
90 def lastTime = state[evt.deviceId]
91 if (lastTime == null || now() - lastTime >= frequency * 60000) {
100 private sendMessage(evt) {
101 String msg = messageText
105 msg = '{{ triggerEvent.descriptionText }}'
106 options = [translatable: true, triggerEvent: evt]
108 log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'"
110 if (location.contactBookEnabled) {
111 sendNotificationToContacts(msg, recipients, options)
114 options.phone = phone
115 if (pushAndPhone != 'No') {
116 log.debug 'Sending push and SMS'
117 options.method = 'both'
119 log.debug 'Sending SMS'
120 options.method = 'phone'
122 } else if (pushAndPhone != 'No') {
123 log.debug 'Sending push'
124 options.method = 'push'
126 log.debug 'Sending nothing'
127 options.method = 'none'
129 sendNotification(msg, options)
132 state[evt.deviceId] = now()