-
Notifications
You must be signed in to change notification settings - Fork 20
/
hubitat_envisalink_integration_application.groovy
350 lines (305 loc) · 13.6 KB
/
hubitat_envisalink_integration_application.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/***********************************************************************************************************************
*
* A Hubitat Smart App for creating Envisalink Connection Device and Child Virtual Contact Zones
* http://www.eyezon.com/
*
* Copyright (C) 2018 Doug Beard
*
* License:
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
* Name: Envisalink Integration
* https://github.com/omayhemo/hubitat_envisalink
*
**************************************************************
********** See Release Notes at the bottom ******************
***********************************************************************************************************************/
public static String version() { return "v0.14.0" }
def boolean isDebug
definition(
name: "Envisalink Integration",
namespace: "dwb",
singleInstance: true,
author: "Doug Beard",
description: "Integrate your DSC Alarm system, using Envisalink 3 or 4",
category: "My Apps",
iconUrl: "https://dougbeardrdiag.file.core.windows.net/icons/HomeSecIcon.PNG",
iconX2Url: "https://dougbeardrdiag.file.core.windows.net/icons/HomeSecIcon.PNG",
iconX3Url: "https://dougbeardrdiag.file.core.windows.net/icons/HomeSecIcon.PNG",
)
preferences {
page(name: "mainPage", nextPage: "zoneMapsPage")
page(name: "zoneMapsPage", nextPage: "mainPage")
page(name: "defineZoneMap", nextPage: "zoneMapsPage")
page(name: "editZoneMapPage", nextPage: "zoneMapsPage")
page(name: "aboutPage", nextPage: "mainPage")
}
//App Pages/Views
def mainPage() {
ifDebug("Showing mainPage")
return dynamicPage(name: "mainPage", title: "", install: false, uninstall: true) {
if(!state.envisalinkIntegrationInstalled && getChildDevices().size() == 0) {
section("Define your Envisalink device") {
clearStateVariables()
input "envisalinkName", "text", title: "Envisalink Name", required: true, multiple: false, defaultValue: "Envisalink", submitOnChange: false
input "envisalinkIP", "text", title: "Envisalink IP Address", required: true, multiple: false, defaultValue: "", submitOnChange: false
input "envisalinkPassword", "text", title: "Envisalink Password", required: true, multiple: false, defaultValue: "", submitOnChange: false
input "envisalinkCode", "text", title: "Envisalink Disarm Code", required: true, multiple: false, defaultValue: "", submitOnChange: false
}
}
else {
state.enableHSM = enableHSM
section("<h3>Safety Monitor</h3>") {
paragraph "Enabling Hubitat Safety Monitor Integration will tie your Envisalink state to the state of HSM. Your Envisalink will receive the Arm Away, Arm Home and Disarm commands based on the HSM state. "
input "enableHSM", "bool", title: "Enable HSM Integration", required: false, multiple: false, defaultValue: true, submitOnChange: true
}
section("") {
href (name: "zoneMapsPage", title: "Zones",
description: "Create Virtual Contacts and Map them to Existing Zones in your Envisalink setup",
page: "zoneMapsPage")
}
}
section("") {
href (name: "aboutPage", title: "About",
description: "Find out more about Envisalink Integration",
page: "aboutPage")
}
section("") {
input "isDebug", "bool", title: "Enable Debug Logging", required: false, multiple: false, defaultValue: true, submitOnChange: true
}
}
}
def aboutPage() {
ifDebug("Showing aboutPage")
dynamicPage(name: "aboutPage", title: none){
section("<h1>Introducing Envisalink Integration</h1>"){
paragraph "An EyezOn EnvisaLink module allows you to upgrade your existing security system with IP control ... " +
"Envisalink Integration connects to your Envisalink module via Telnet, using eyezon's public TPI."
paragraph "Evisalink Integration automates installation and configuration of the Envisalink Connection Driver" +
" as well as Virtual Contacts representing the dry contact zones configured in your DSC Alarm system."
paragraph "You must have the Hubitat Envisalink Connection driver already installed before making use of Envisalink Integration application " +
"https://github.com/omayhemo/hubitat_envisalink/blob/master/hubitat_envisalink_connection_driver.groovy"
paragraph "Special Thanks to the Hubitat staff and cuboy29."
}
}
}
def zoneMapsPage() {
ifDebug("Showing zoneMapsPage")
if (getChildDevices().size() == 0 && !state.envisalinkIntegrationInstalled)
{
createEnvisalinkParentDevice()
}
if (state.creatingZone)
{
createZone()
}
/* Maybe coming soon?
if (state.editingZone)
{
editZone()
}
ifDebug("DeleteZone? ${state.deleteZone}")
if (state.deleteZone == true){
section("Deleted Zone"){
paragraph "Deleted your Zone"
state.deleteZone == false
}
}
*/
dynamicPage(name: "zoneMapsPage", title: "", install: true, uninstall: false){
section("<h1>Zone Maps</h1>"){
paragraph "The partition of your Envisalink Installation should be divided into Zones. Should the Zone be fitted with a dry contact, you can map the Zone to a Virtual Contact component device in Envisalink Integration "
paragraph "You'll want to determine the Zone number as it is defined in " +
"your Envisalink setup. Define a new Zone in Envisalink Itegration and the application will then create a Virtual Contact sensor component device, which will report the state of the Envisalink Zone to which it is mapped. " +
" The Virtual Contact sensor components can be used in Rule Machine or any other application that is capable of leveraging the contact capability. Envisalink is capable of 64 zones, your zone map should correspond to the numeric representation of that zone."
}
section("Create a Zone Map") {
href (name: "createZoneMapPage", title: "Create a Zone Map",
description: "Create a Virtual Contact Zone",
page: "defineZoneMap")
}
section("<h2>Existing Zones</h2>"){
def deviceList = ""
getChildDevice(state.EnvisalinkDNI).getChildDevices().each{
href (name: "editZoneMapPage", title: "${it.label}",
description: "Zone Details",
params: [deviceNetworkId: it.deviceNetworkId],
page: "editZoneMapPage")
}
}
}
}
def defineZoneMap() {
ifDebug("Showing defineZoneMap")
state.creatingZone = true;
dynamicPage(name: "defineZoneMap", title: ""){
section("<h1>Create a Zone Map</h1>"){
paragraph "Create a Map for a zone in Envisalink"
input "zoneName", "text", title: "Zone Name", required: true, multiple: false, defaultValue: "Zone x", submitOnChange: false
input "zoneNumber", "number", title: "Which Zone 1-64", required: true, multiple: false, defaultValue: 001, range: "1..64", submitOnChange: false
input "zoneType", "enum", title: "Motion or Contact Sensor?", required: true, multiple: false,
options: [[0:"Contact"],[1:"Motion"]]
}
}
}
def editZoneMapPage(message) {
ifDebug("Showing editZoneMapPage")
ifDebug("editing ${message.deviceNetworkId}")
state.allZones = getChildDevice(state.EnvisalinkDNI).getChildDevices()
def zoneDevice = getChildDevice(state.EnvisalinkDNI).getChildDevice(message.deviceNetworkId)
def paragraphText = ""
//Maybe Editing and Deleting coming soon
//state.editingZone = true;
state.editedZoneDNI = message.deviceNetworkId;
if (zoneDevice.capabilities.find { item -> item.name.startsWith('Motion')}){
paragraphText = paragraphText + "Motion Sensor\n"
}
if (zoneDevice.capabilities.find { item -> item.name.startsWith('Contact')}){
paragraphText = paragraphText + "Contact Sensor\n"
}
dynamicPage(name: "editZoneMapPage", title: ""){
section("<h1>${zoneDevice.label}</h1>"){
paragraph paragraphText
}
/*
section("<h2>Delete this Zone", title: ""){
input "deleteZoneBool", "bool", title: "Are you sure?", required: false, multiple: false, submitOnChange: true
}
*/
}
}
def clearStateVariables(){
ifDebug("Clearing State Variables just in case.")
state.EnvisalinkDeviceName = null
state.EnvisalinkIP = null
state.EnvisalinkPassword = null
state.EnvisalinkCode = null
}
def createEnvisalinkParentDevice(){
ifDebug("Creating Parent Envisalink Device")
if (getChildDevice(state.EnvisalinkDNI) == null){
state.EnvisalinkDNI = UUID.randomUUID().toString()
ifDebug("Setting state.EnvisalinkDNI ${state.EnvisalinkDNI}")
addChildDevice("dwb", "Envisalink Connection", state.EnvisalinkDNI, null, [name: envisalinkName, isComponent: true, label: envisalinkName])
getChildDevice(state.EnvisalinkDNI).updateSetting("ip",[type:"text", value:envisalinkIP])
getChildDevice(state.EnvisalinkDNI).updateSetting("passwd",[type:"text", value:envisalinkPassword])
getChildDevice(state.EnvisalinkDNI).updateSetting("code",[type:"text", value:envisalinkCode])
castEnvisalinkDeviceStates()
}
}
def castEnvisalinkDeviceStates(){
ifDebug("Casting to State Variables")
state.EnvisalinkDeviceName = envisalinkName
ifDebug("Setting state.EnvisalinkDeviceName ${state.EnvisalinkDeviceName}")
state.EnvisalinkIP = envisalinkIP
ifDebug("Setting state.EnvisalinkIP ${state.EnvisalinkIP}")
state.EnvisalinkPassword = envisalinkPassword
ifDebug("Setting state.EnvisalinkPassword ${state.EnvisalinkPassword}")
state.EnvisalinkCode = envisalinkCode
ifDebug("Setting state.EnvisalinkCode ${state.EnvisalinkCode}")
if (getChildDevice(state.EnvisalinkDNI)){
ifDebug("Found a Child Envisalink ${getChildDevice(state.EnvisalinkDNI).label}")
}
else{
ifDebug("Did not find a Parent Envisalink")
}
}
def createZone(){
ifDebug("Starting validation of ${zoneName} ZoneType: ${zoneType}")
String formatted = String.format("%03d", zoneNumber)
String deviceNetworkId
if (zoneType == "0"){
deviceNetworkId = state.EnvisalinkDNI + "_" + formatted
}else{
deviceNetworkId = state.EnvisalinkDNI + "_M_" + formatted
}
ifDebug("Entered zoneNumber: ${zoneNumber} formatted as: ${formatted}")
getChildDevice(state.EnvisalinkDNI).createZone([zoneName: zoneName, deviceNetworkId: deviceNetworkId, zoneType: zoneType])
state.creatingZone = false;
}
def editZone(){
def childZone = getChildDevice(state.EnvisalinkDNI).getChildDevice(state.editedZoneDNI);
ifDebug("Starting validation of ${childZone.label}")
ifDebug("Attempting rename of zone to ${newZoneName}")
childZone.updateSetting("label",[type:"text", value:newZoneName])
newZoneName = null;
state.editingZone = false
state.editedZoneDNI = null;
}
private ifDebug(msg)
{
if (msg && isDebug) log.debug 'Envisalink Integration: ' + msg
}
//General App Events
def installed() {
state.envisalinkIntegrationInstalled = true
initialize()
}
def updated() {
unsubscribe()
initialize()
}
def initialize() {
state.creatingZone = false;
subscribe(location, "hsmStatus", statusHandler)
}
def uninstalled() {
removeChildDevices(getChildDevices())
}
def statusHandler(evt) {
log.info "HSM Alert: $evt.value"
if (evt.value && state.enableHSM)
{
ifDebug("HSM is enabled")
switch(evt.value){
case "armedAway":
ifDebug("Sending Arm Away")
getChildDevice(state.EnvisalinkDNI).ArmAway()
break
case "armedHome":
ifDebug("Sending Arm Home")
getChildDevice(state.EnvisalinkDNI).ArmHome()
break
case "armedNight":
ifDebug("Sending Arm Home")
getChildDevice(state.EnvisalinkDNI).ArmHome()
break
case "disarmed":
ifDebug("Sending Disarm")
getChildDevice(state.EnvisalinkDNI).Disarm()
break
}
}
}
private removeChildDevices(delete) {
delete.each {deleteChildDevice(it.deviceNetworkId)}
}
/***********************************************************************************************************************
* Version: 0.14.0
* Added armedNight Handler
*
* Version: 0.13.0
* Provided Debug switch for less logging if desired.
* Moved this list to bottom of file
*
* Version: 0.12.1
* HSM Integration Changes
*
* Version: 0.11.0
* Added Motion Zone Capability
*
* Version: 0.10.0
*
* Just the basics.
* Creates the Envisalink Connection device and allows definition of Zone Maps, creating virtual contact sensors as child components.
* Allows subscription to HSM to mirror the state of HSM to Envisalink (ArmAway, ArmHome, Disarm)
*/