forked from ekimmagrann/hubitat-elkm1
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Elk-M1-Driver-Output-DoorControl.groovy
151 lines (137 loc) · 4.87 KB
/
Elk-M1-Driver-Output-DoorControl.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
/***********************************************************************************************************************
*
* A Hubitat Child Driver supporting Elk M1 Output as a Door Control.
*
* 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.
*
* Name: Elk M1 Driver Output Door Control
* Description: This is a driver for an output connected to a door opener that has a contact assigned to a zone
*
*** See Release Notes at the bottom***
***********************************************************************************************************************/
public static String version() { return "v0.1.6" }
metadata {
definition(name: "Elk M1 Driver Output-DoorControl", namespace: "captncode", author: "captncode") {
capability "Actuator"
capability "GarageDoorControl"
capability "Momentary"
command "report", ["bool", "string"]
command "refresh"
}
preferences {
input name: "transitionTime", type: "enum", title: "Transition time", required: true,
options: [[5: "5 seconds"], [15: "15 seconds"], [30: "30 seconds"], [90: "90 seconds"]]
input name: "zoneNumber", type: "number", title: "Door contact zone 1-208", required: true, range: "1..208"
input name: "txtEnable", type: "bool", title: "Enable descriptionText logging", defaultValue: true
}
}
void updated() {
log.warn "${device.label} Updated..."
log.warn "${device.label} description logging is: ${txtEnable}"
log.warn "${device.label} door contact zone is: ${zoneNumber}"
parent.unRegisterZoneReport(device.deviceNetworkId)
parent.registerZoneReport(device.deviceNetworkId, String.format("%03d", zoneNumber.intValue()))
}
hubitat.device.HubAction installed() {
log.warn "${device.label} Installed..."
device.updateSetting("txtEnable", [type: "bool", value: true])
refresh()
}
void uninstalled() {
parent.unRegisterZoneReport(device.deviceNetworkId)
}
void parse(String description) {
if (txtEnable && description == "on")
log.info "${device.label} was pushed"
}
void parse(List description) {
log.warn "${device.label} parse(List description) received ${description}"
}
void report(String deviceDNID, boolean violated) {
state.contactOpen = violated
if (violated) {
setStatus("opening")
runIn(transitionTime.toInteger(), "setStatus", [data: "open"])
} else {
setStatus("closed")
}
}
void setStatus(String status) {
if (status == "open" && state.contactOpen != null && !state.contactOpen) {
status = "closed"
} else if (status == "open") {
state.open = true
}
if (status == "closed") {
state.open = false
}
if (device.currentState("door")?.value == null || device.currentState("door").value != status) {
String descriptionText = "${device.label} was ${status}"
if (txtEnable)
log.info descriptionText
sendEvent(name: "door", value: status, descriptionText: descriptionText)
}
}
hubitat.device.HubAction push() {
String output = device.deviceNetworkId
output = output.substring(output.length() - 3).take(3)
parent.sendMsg(parent.ControlOutputOn(output.toInteger(), '00001'))
if (state.open != null && state.open)
setStatus("closing")
else if (state.open == null || !state.open)
setStatus("opening")
}
hubitat.device.HubAction close() {
if (state.open == null || state.open) {
push()
}
}
hubitat.device.HubAction open() {
if (state.open == null || !state.open) {
push()
}
}
hubitat.device.HubAction refresh() {
parent.refreshZoneStatus()
}
/***********************************************************************************************************************
*
* Release Notes (see Known Issues Below)
*
* 0.1.6
* Changed DoorControl capability to GarageDoorControl for compatibility with the Amazon Echo skill
* Strongly typed commands
*
* 0.1.5
* Enhanced open and closed events to for reliability
*
* 0.1.4
* Updated push to work with parent driver change
*
* 0.1.3
* Minor cleanup of descriptionText on events
*
* 0.1.2
* Changed logging and events to only occur when state changes
*
* 0.1.1
* Added Refresh Command
* Simplified logging and event code
*
* 0.1.0
* New child driver to Elk M1 Output-DoorControl
*
***********************************************************************************************************************/
/***********************************************************************************************************************
*
* Feature Request & Known Issues
*
*
***********************************************************************************************************************/