-
Notifications
You must be signed in to change notification settings - Fork 19
/
AlarmThing-AlertSensor.groovy
114 lines (105 loc) · 3.7 KB
/
AlarmThing-AlertSensor.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* AlarmThing Alert Sensor
*
* Copyright 2014 ObyCode
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
definition(
name: "AlarmThing Sensor Alert",
namespace: "com.obycode",
author: "ObyCode",
description: "Alert me when there is activity on one or more of my alarm's sensors.",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
)
preferences {
page(name: "selectAlarm")
page(name: "selectSensors")
page(name: "selectStates")
}
def selectAlarm() {
dynamicPage(name: "selectAlarm", title: "Configure Alarm", nextPage:"selectSensors", uninstall: true) {
section("When there is activity on this alarm...") {
input "theAlarm", "capability.alarm", multiple: false, required: true
}
}
}
def selectSensors() {
dynamicPage(name: "selectSensors", title: "Configure Sensors", uninstall: true, nextPage:"selectStates") {
def sensors = theAlarm.supportedAttributes*.name
if (sensors) {
section("On these sensors...") {
input "theSensors", "enum", required: true, multiple:true, metadata:[values:sensors], refreshAfterSelection:true
}
}
section([mobileOnly:true]) {
label title: "Assign a name", required: false
}
}
}
def selectStates() {
dynamicPage(name: "selectStates", title: "Which states should trigger a notification?", uninstall: true, install: true) {
theSensors.each() {
def sensor = it
def states = []
// TODO: Cannot figure out how to get these possible states, so have to guess them based on the current value
switch(theAlarm.currentValue("$it")) {
case "active":
case "inactive":
states = ["active", "inactive"]
break
case "on":
case "off":
states = ["on", "off"]
break
case "detected":
case "clear":
case "tested":
states = ["detected", "clear", "tested"]
break
case "closed":
case "open":
states = ["closed", "open"]
break
default:
log.debug "value not handled: ${theAlarm.currentValue("$sensor")}"
}
if (states) {
section() {
input "${sensor}States", "enum", title:"For $sensor...", required: true, multiple:true, metadata:[values:states], refreshAfterSelection:true
}
}
}
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
theSensors.each() {
def sensor = it
settings."${it}States".each() {
subscribe(theAlarm, "${sensor}.$it", sensorTriggered)
}
}
}
def sensorTriggered(evt) {
sendPush("Alarm: ${evt.name} is ${evt.value}")
log.debug "Alarm: ${evt.name} is ${evt.value}"
}