2 * AlarmThing Alert Sensor
4 * Copyright 2014 ObyCode
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "AlarmThing Sensor Alert",
18 namespace: "com.obycode",
20 description: "Alert me when there is activity on one or more of my alarm's sensors.",
21 category: "Safety & Security",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
27 page(name: "selectAlarm")
28 page(name: "selectSensors")
29 page(name: "selectStates")
33 dynamicPage(name: "selectAlarm", title: "Configure Alarm", nextPage:"selectSensors", uninstall: true) {
34 section("When there is activity on this alarm...") {
35 input "theAlarm", "capability.alarm", multiple: false, required: true
41 dynamicPage(name: "selectSensors", title: "Configure Sensors", uninstall: true, nextPage:"selectStates") {
42 def sensors = theAlarm.supportedAttributes*.name
44 section("On these sensors...") {
45 input "theSensors", "enum", required: true, multiple:true, metadata:[values:sensors], refreshAfterSelection:true
48 section([mobileOnly:true]) {
49 label title: "Assign a name", required: false
55 dynamicPage(name: "selectStates", title: "Which states should trigger a notification?", uninstall: true, install: true) {
59 // TODO: Cannot figure out how to get these possible states, so have to guess them based on the current value
60 switch(theAlarm.currentValue("$it")) {
63 states = ["active", "inactive"]
67 states = ["on", "off"]
72 states = ["detected", "clear", "tested"]
76 states = ["closed", "open"]
79 log.debug "value not handled: ${theAlarm.currentValue("$sensor")}"
83 input "${sensor}States", "enum", title:"For $sensor...", required: true, multiple:true, metadata:[values:states], refreshAfterSelection:true
91 log.debug "Installed with settings: ${settings}"
96 log.debug "Updated with settings: ${settings}"
105 settings."${it}States".each() {
106 subscribe(theAlarm, "${sensor}.$it", sensorTriggered)
111 def sensorTriggered(evt) {
112 sendPush("Alarm: ${evt.name} is ${evt.value}")
113 log.debug "Alarm: ${evt.name} is ${evt.value}"