-
Notifications
You must be signed in to change notification settings - Fork 19
/
ring-alarm-app.groovy
139 lines (125 loc) · 4.55 KB
/
ring-alarm-app.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* Ring Alarm State
* Licence Details.
* https://opensource.org/licenses/MIT
*
* Copyright 2019 Asish Soudhamma
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
definition(
name: "Ring Alarm State",
namespace: "asishrs",
author: "Asish Soudhamma",
description: "Automatically sets the Ring Alarm alarm state based on the Smartthings mode",
category: "My Apps",
iconUrl: "https://cdn.shopify.com/s/files/1/2922/1686/t/2/assets/ring_logo.png?8137716793231487980",
iconX2Url: "https://cdn.shopify.com/s/files/1/2922/1686/t/2/assets/ring_logo.png?8137716793231487980"
)
preferences {
page(name: "selectProgram", title: "Ring Alarm State", install: false, uninstall: true,
nextPage: "Notifications") {
section("Use this Alarm...") {
input "alarmsystem", "capability.alarm", multiple: false, required: true
}
section("Set alarm to 'Off' when mode matches") {
input "modealarmoff", "mode", title: "Select modes for 'Disarmed'", multiple: true, required: false
}
section("Set alarm to 'Away' when mode matches") {
input "modealarmaway", "mode", title: "Select modes for 'Armed Away'", multiple: true, required: false
}
section("Set alarm to 'Home' when mode matches") {
input "modealarmhome", "mode", title: "Select modes for 'Armed Home'", multiple: true, required: false
}
}
page(name: "Notifications", title: "Notifications Options", install: true, uninstall: true) {
section("Notifications") {
input "sendPushMessage", "enum", title: "Send a push notification?", options: ["Yes", "No"],
required: false
input "phone", "phone", title: "Send a Text Message?", required: false
}
section([mobileOnly:true]) {
label title: "Assign a name", required: false
}
}
}
def installed() {
init()
}
def updated() {
unsubscribe()
unschedule()
init()
}
def init() {
subscribe(app, onAppTouch)
subscribe(location, "mode", modeaction)
subscribe(alarmsystem, "alarm", alarmstate)
}
def onAppTouch(event) {
log.debug("Running App Manually")
state.locationmode = location.mode
setalarmmode()
}
def modeaction(evt) {
state.locationmode = evt.value
setalarmmode()
}
def setalarmmode() {
log.debug("Setting Ring Alarm mode ${alarmsystem}")
state.alarmstate = alarmsystem.currentState("alarm").value.toLowerCase()
log.debug("Current alarm state is: ${state.alarmstate}")
if(state.locationmode in modealarmoff && state.alarmstate !="off") {
log.debug("Location mode: $state.locationmode")
setalarmoff()
} else if(state.locationmode in modealarmaway && state.alarmstate !="away") {
log.debug("Location mode: $state.locationmode")
setalarmaway()
} else if(state.locationmode in modealarmhome && state.alarmstate !="home") {
log.debug("Location mode: $state.locationmode")
setalarmhome()
} else {
log.debug("No actions set for location mode ${state.locationmode} or ${alarmsystem.displayName} already set to ${state.alarmstate} - aborting")
}
}
def setalarmoff() {
def message = "Ring Alarm is DISARMED"
log.info(message)
send(message)
alarmsystem.off()
}
def setalarmaway() {
def message = "Ring Alarm is Armed AWAY"
log.info(message)
send(message)
alarmsystem.away()
}
def setalarmhome() {
def message = "Ring Alarm is Armed HOME"
log.info(message)
send(message)
alarmsystem.home()
}
private send(msg) {
if (sendPushMessage != "No") {
log.debug("sending push message")
sendPush(msg)
}
if (phone) {
log.debug("sending text message")
sendSms(phone, msg)
}
log.debug msg
}