-
Notifications
You must be signed in to change notification settings - Fork 27
/
DeviceTamperAlarm.groovy
67 lines (59 loc) · 1.76 KB
/
DeviceTamperAlarm.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
/**
* Device Tamper Alarm
*
* Author: Mitch Pond, SmartThings
* Date: 2013-03-20
*/
definition(
name: "Device Tamper Alarm",
namespace: "mitchpond",
author: "Mitch Pond",
description: "Receive notification when a device is tampered with. Currently supports Quirky Tripper.",
category: "Safety & Security",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Solution/[email protected]",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Solution/[email protected]",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Solution/[email protected]"
)
preferences {
section("Choose devices..."){
input "contact", "capability.contactSensor", title: "Devices supporting tamper", required: false, multiple: true
}
section("Via a push notification and/or an SMS message"){
input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false
input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes","No"]
}
section("Sound these alarms..."){
input "alarms", "capability.alarm", title: "Alarm Devices", required: false, multiple: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
subscribeToEvents()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribeToEvents()
}
def subscribeToEvents() {
subscribe(contact, "tamper.tampered", eventHandler)
}
def eventHandler(evt) {
String msg = "${evt.displayName} has been tampered with!"
log.debug msg
sendMessage(msg)
alarms ?: soundAlarms(alarms)
}
private sendMessage(msg) {
if (!phone || pushAndPhone != "No") {
log.debug "sending push"
sendPush(msg)
}
if (phone) {
log.debug "sending SMS"
sendSms(phone, msg)
}
}
private soundAlarms(alarms){
alarms?.both()
}