-
Notifications
You must be signed in to change notification settings - Fork 2
/
GoGoGate2GarageControllerDriver.groovy
208 lines (172 loc) · 5.91 KB
/
GoGoGate2GarageControllerDriver.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
/**
*
* File: GoGoGate2GarageControllerDriver.groovy
* Platform: Hubitat
*
*
* Requirements:
* 1) GoGoGate2 Garage Controller connected to same LAN as your Hubitat Hub. Use router
* DHCP Reservation to prevent IP address from changing.
* 2) Authentication Credentials for GoGoGate2 Garage Door Open. This is the credentials
* that are used to log on to the opener at it's index.php
*
* Copyright 2019 Robert B. Mergner
*
* 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.
*
* Change History:
*
* Date Who What
* ---- --- ----
* 2019-03-11 Bob Mergner Original Creation
* 2019-03-13 Bob Mergner Cleaned up and refactored. Added every two second polling for more reactive automation chains in rules
* 2019-03-14 Bob Mergner More cleanup
*
*/
def version() {"v0.1.20190314"}
import hubitat.helper.InterfaceUtils
metadata {
definition (name: "GoGoGate2 Garage Controller", namespace: "bcsmart", author: "Bob Mergner") {
capability "Initialize"
capability "Refresh"
capability "DoorControl"
attribute "door", "string"
}
}
preferences {
input("ip", "text", title: "IP Address", description: "[IP Address of your GoGoGate2 Device]", required: true)
input("user", "text", title: "GoGoGate2 Garage User", description: "[GoGoGate2 Username (usually admin)]", required: true)
input("pass", "password", title: "GoGoGate2 Garage Password", description: "[Your GoGoGate2 user's Password]", required: true)
input("door", "text", title: "Garage Door Number", description: "[Enter 1, 2 or 3]", required: true)
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}
def logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("logEnable",[value:"false",type:"bool"])
}
def refresh() {
//log.info "refresh() called"
//initialize()
GetDoorStatus()
}
def doorPollStatus() {
for(int i = 0;i<30;i++) {
refresh()
pauseExecution(2000)
}
}
def installed() {
log.info "installed() called"
updated()
}
def updated() {
log.info "updated() called"
//Unschedule any existing schedules
unschedule()
//Create a 30 minute timer for debug logging
if (logEnable) runIn(1800,logsOff)
currentState = "99"
runEvery1Minute(doorPollStatus)
refresh()
}
def LogOnAndGetCookie(){
def allcookie
def cookie
httpPost("http://${ip}", "login=${user}&pass=${pass}&send-login=Sign+In") { resp ->
allcookie = resp.headers['Set-Cookie']
//log.debug "SetCookieValue: ${allcookie}"
cookie = allcookie.toString().replaceAll("; path=/","").replaceAll("Set-Cookie: ","")
}
return cookie
}
def GetDoorStatus() {
if (currentState == null) {
currentState = "99"
}
//def doorStatus
def cookie = LogOnAndGetCookie()
def params = [uri: "http://${ip}/isg/statusDoorAll.php?status1=10",
headers: ["Cookie": """${cookie}""",
"Referer": "http://${ip}/index.php",
"Host": """${ip}""",
"Connection": "keep-alive"],
requestContentType: "application/json; charset=UTF-8"]
httpGet(params) { resp ->
doorStatus = resp.data.toString().substring(1)
doorStatus = doorStatus.substring(0, doorStatus.length() - 1)
int whichdoor = Integer.parseInt(door,16) - 1
status = doorStatus.split(",")[whichdoor]
doorStatus = status
if ( status.contains("0") && !currentState.contains("0") ) {
sendEvent(name: "door", value: "closed")
currentState = "0"
}
else if ( status.contains("2") && !currentState.contains("2") )
{
sendEvent(name: "door", value: "open")
currentState = "2"
}
}
return cookie
}
def open() {
log.info "Door ${door} received open command from Hubitat Elevation"
def cookie = GetDoorStatus()
//now see if door is open already
if ( doorStatus.contains("0") )
{
toggleDoor(cookie)
doorStatus = "2"
log.info "Open command sent to Door ${door}"
}
else
{
log.info "Door ${door} already open"
}
}
def close() {
log.info "Door ${door} received Close command from Hubitat Elevation"
def cookie = GetDoorStatus()
//now see if door is closed already
if ( doorStatus.contains("2") )
{
toggleDoor(cookie)
doorStatus = "0"
log.info "Close command sent to Door ${door}"
}
else
{
log.info "Door ${door} already closed"
}
}
def toggleDoor(cookie){
def params = [uri: "http://${ip}/isg/opendoor.php?numdoor=${door}&status=0&login=${user}",
headers: ["Cookie": """${cookie}""",
"Referer": "http://${ip}/index.php",
"Host": """${ip}""",
"Connection": "keep-alive"],
requestContentType: "application/json; charset=UTF-8"]
httpGet(params) { resp ->
//log.debug resp.contentType
//log.debug resp.status
//log.debug resp.data
}
}
def initialize() {
state.version = version()
currentState = "99"
runEvery1Minute(doorPollStatus)
log.info "initialize() called"
if (!ip || !user || !pass || !door) {
log.warn "GoGoGate2 Garage Door Controller required fields not completed. Please complete for proper operation."
return
}
refresh()
}