-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathSmartThings-TotalConnect-Device.groovy
248 lines (232 loc) · 11 KB
/
SmartThings-TotalConnect-Device.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
* TotalConnect Device API
*
* Copyright 2015 Brian Wilson
*
* 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.
*
* This Device is based on work by @mhatrey (https://github.com/mhatrey/TotalConnect/blob/master/TotalConnect.groovy)
* The goal of this is to expose the TotalConnect Alarm to be used in other routines and in modes. To do this, I setup
* both lock and switch capabilities for it. Switch On = Armed Stay, Lock On = Armed Away, Switch/Lock Off = Disarm.
* There are no tiles because I don't need them, but feel free to add them. Also, you'll have to use @mhatrey's tester
* tool to get your deviceId and locationId. See his thread for more info:
* https://community.smartthings.com/t/new-app-integration-with-honeywell-totalconnect-alarm-monitoring-system/
*
*/
preferences {
// See above ST thread above on how to configure the user/password. Make sure the usercode is configured
// for whatever account you setup. That way, arming/disarming/etc can be done without passing a user code.
input("userName", "text", title: "Username", description: "Your username for TotalConnect")
input("password", "password", title: "Password", description: "Your Password for TotalConnect")
// get this info by using https://github.com/mhatrey/TotalConnect/blob/master/TotalConnectTester.groovy
input("deviceId", "text", title: "Device ID - You'll have to look up", description: "Device ID")
// get this info by using https://github.com/mhatrey/TotalConnect/blob/master/TotalConnectTester.groovy
input("locationId", "text", title: "Location ID - You'll have to look up", description: "Location ID")
input("applicationId", "text", title: "Application ID - It is '14588' currently", description: "Application ID")
input("applicationVersion", "text", title: "Application Version - use '3.0.32'", description: "Application Version")
}
metadata {
definition (name: "TotalConnect Device", namespace: "bdwilson", author: "Brian Wilson") {
capability "Lock"
capability "Refresh"
capability "Switch"
attribute "status", "string"
}
simulator {
// TODO: define status and reply messages here
}
tiles {
standardTile("toggle", "device.status", width: 2, height: 2) {
state("unknown", label:'${name}', action:"device.refresh", icon:"st.Office.office9", backgroundColor:"#ffa81e")
state("Armed Stay", label:'${name}', action:"switch.off", icon:"st.Home.home4", backgroundColor:"#79b821", nextState:"Disarmed")
state("Disarmed", label:'${name}', action:"lock.lock", icon:"st.Home.home2", backgroundColor:"#a8a8a8", nextState:"Armed Away")
state("Armed Away", label:'${name}', action:"switch.off", icon:"st.Home.home3", backgroundColor:"#79b821", nextState:"Disarmed")
state("Arming", label:'${name}', icon:"st.Home.home4", backgroundColor:"#ffa81e")
state("Disarming", label:'${name}', icon:"st.Home.home2", backgroundColor:"#ffa81e")
}
standardTile("statusstay", "device.status", inactiveLabel: false, decoration: "flat") {
state "default", label:'Arm Stay', action:"switch.on", icon:"st.Home.home4"
}
standardTile("statusaway", "device.status", inactiveLabel: false, decoration: "flat") {
state "default", label:'Arm Away', action:"lock.lock", icon:"st.Home.home3"
}
standardTile("statusdisarm", "device.status", inactiveLabel: false, decoration: "flat") {
state "default", label:'Disarm', action:"switch.off", icon:"st.Home.home2"
}
standardTile("refresh", "device.status", inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
main "toggle"
details(["toggle", "statusaway", "statusstay", "statusdisarm", "refresh"])
}
}
// Login Function. Returns SessionID for rest of the functions
def login(token) {
log.debug "Executed login"
def paramsLogin = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/AuthenticateUserLogin",
body: [userName: settings.userName , password: settings.password, ApplicationID: settings.applicationId, ApplicationVersion: settings.applicationVersion]
]
httpPost(paramsLogin) { responseLogin ->
token = responseLogin.data.SessionID
}
log.debug "Smart Things has logged In. SessionID: ${token}"
return token
} // Returns token
// Logout Function. Called after every mutational command. Ensures the current user is always logged Out.
def logout(token) {
log.debug "During logout - ${token}"
def paramsLogout = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/Logout",
body: [SessionID: token]
]
httpPost(paramsLogout) { responseLogout ->
log.debug "Smart Things has successfully logged out"
}
}
// Gets Panel Metadata. Takes token & location ID as an argument
Map panelMetaData(token, locationId) {
def alarmCode
def lastSequenceNumber
def lastUpdatedTimestampTicks
def partitionId
def getPanelMetaDataAndFullStatus = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/GetPanelMetaDataAndFullStatus",
body: [ SessionID: token, LocationID: locationId, LastSequenceNumber: 0, LastUpdatedTimestampTicks: 0, PartitionID: 1]
]
httpPost(getPanelMetaDataAndFullStatus) { response ->
lastUpdatedTimestampTicks = response.data.PanelMetadataAndStatus.'@LastUpdatedTimestampTicks'
lastSequenceNumber = response.data.PanelMetadataAndStatus.'@ConfigurationSequenceNumber'
partitionId = response.data.PanelMetadataAndStatus.Partitions.PartitionInfo.PartitionID
alarmCode = response.data.PanelMetadataAndStatus.Partitions.PartitionInfo.ArmingState
log.debug response.data.PanelMetadataAndStatus.Zones.inspect()
}
//log.debug "AlarmCode is " + alarmCode
//log.debug response.data.PanelMetadataAndStatus.Partitions.PartitionInfo.inspect()
return [alarmCode: alarmCode, lastSequenceNumber: lastSequenceNumber, lastUpdatedTimestampTicks: lastUpdatedTimestampTicks]
} //Should return alarmCode, lastSequenceNumber & lastUpdateTimestampTicks
// Arm Function. Performs arming function
def armAway() {
def token = login(token)
def locationId = settings.locationId
def deviceId = settings.deviceId
def paramsArm = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/ArmSecuritySystem",
body: [SessionID: token, LocationID: locationId, DeviceID: deviceId, ArmType: 0, UserCode: '-1']
]
httpPost(paramsArm) // Arming Function in away mode
def metaData = panelMetaData(token, locationId) // Get AlarmCode
if (metaData.alarmCode == 10201) {
log.debug "Status is: Already Armed Away"
sendEvent(name: "status", value: "Armed Away", displayed: "true", description: "Refresh: Alarm is Armed Away")
} else if (metaData.alarmCode == 10203) {
log.debug "Status is: Armed Stay - Please Disarm First"
sendEvent(name: "status", value: "Armed Stay", displayed: "true", description: "Refresh: Alarm is Armed Stay")
} else {
log.debug "Status is: Arming"
httpPost(paramsArm) // Arming Function in away mode
}
logout(token)
}
def armStay() {
def token = login(token)
def locationId = settings.locationId
def deviceId = settings.deviceId
def paramsArm = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/ArmSecuritySystem",
body: [SessionID: token, LocationID: locationId, DeviceID: deviceId, ArmType: 1, UserCode: '-1']
]
httpPost(paramsArm) // Arming function in stay mode
def metaData = panelMetaData(token, locationId) // Gets AlarmCode
if (metaData.alarmCode == 10203) {
log.debug "Status is: Already Armed Stay"
sendEvent(name: "status", value: "Armed Stay", displayed: "true", description: "Refresh: Alarm is Armed Stay")
} else if (metaData.alarmCode == 10201) {
log.debug "Status is: Armed Away - Please Disarm First"
sendEvent(name: "status", value: "Armed Away", displayed: "true", description: "Refresh: Alarm is Armed Away")
} else {
log.debug "Status is: Arming"
httpPost(paramsArm) // Arming function in stay mode
}
logout(token)
}
def disarm() {
def token = login(token)
def locationId = settings.locationId
def deviceId = settings.deviceId
def paramsDisarm = [
uri: "https://rs.alarmnet.com/TC21API/TC2.asmx/DisarmSecuritySystem",
body: [SessionID: token, LocationID: locationId, DeviceID: deviceId, UserCode: '-1']
]
httpPost(paramsDisarm)
def metaData = panelMetaData(token, locationId) // Gets AlarmCode
if (metaData.alarmCode == 10200) {
log.debug "Status is: Already Disarmed"
sendEvent(name: "status", value: "Disarmed", displayed: "true", description: "Refresh: Alarm is Disarmed")
} else {
log.debug "Status is: Disarming"
httpPost(paramsDisarm)
}
logout(token)
}
def refresh() {
def token = login(token)
def locationId = settings.locationId
def deviceId = settings.deviceId
log.debug "Doing refresh"
//httpPost(paramsArm) // Arming function in stay mode
def metaData = panelMetaData(token, locationId) // Gets AlarmCode
//log.debug metaData
if (metaData.alarmCode == 10200) {
log.debug "Status is: Disarmed"
sendEvent(name: "status", value: "Disarmed", displayed: "true", description: "Refresh: Alarm is Disarmed")
} else if (metaData.alarmCode == 10203) {
log.debug "Status is: Armed Stay"
sendEvent(name: "status", value: "Armed Stay", displayed: "true", description: "Refresh: Alarm is Armed Stay")
} else if (metaData.alarmCode == 10201) {
log.debug "Status is: Armed Away"
sendEvent(name: "status", value: "Armed Away", displayed: "true", description: "Refresh: Alarm is Armed Away")
}
logout(token)
sendEvent(name: "refresh", value: "true", displayed: "true", description: "Refresh Successful")
}
// parse events into attributes
def parse(String description) {
log.debug "Parsing '${description}'"
}
// handle commands
def lock() {
log.debug "Executing 'Arm Away'"
armAway()
sendEvent(name: "lock", value: "lock", displayed: "true", description: "Arming Away")
sendEvent(name: "status", value: "Arming", displayed: "true", description: "Updating Status: Arming System")
runIn(15,refresh)
}
def unlock() {
log.debug "Executing 'Disarm'"
disarm()
sendEvent(name: "unlock", value: "unlock", displayed: "true", description: "Disarming")
sendEvent(name: "status", value: "Disarming", displayed: "true", description: "Updating Status: Disarming System")
runIn(15,refresh)
}
def on() {
log.debug "Executing 'Arm Stay'"
armStay()
sendEvent(name: "switch", value: "on", displayed: "true", description: "Arming Stay")
sendEvent(name: "status", value: "Arming", displayed: "true", description: "Updating Status: Arming System")
runIn(15,refresh)
}
def off() {
log.debug "Executing 'Disarm'"
disarm()
sendEvent(name: "switch", value: "off", displayed: "true", description: "Disarming")
sendEvent(name: "status", value: "Disarmed", displayed: "true", description: "Updating Status: Disarming System")
runIn(15,refresh)
}