-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathRyobi_GDO200_DH.groovy
229 lines (202 loc) · 7.57 KB
/
Ryobi_GDO200_DH.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
/*
* Author: Justin Dybedahl
* Ryobi GDO200/GDO201/GDO500 Device Handler
* v2.6
* Thanks to @Projectskydroid for the modifications.
*/
def clientVersion() {
return "2.6"
}
preferences {
section("Configuration Parameters"){
input "email", "email", title: "Email Address",required: true
input "pass","password", title: "Password",required:true
input "internal_ip", "text", title: "Internal IP", required: true
input "internal_port", "text", title: "Internal Port (default is 3042)", required: true
input title: "", description: "Ryobi GDO200 Device Handler v${clientVersion()}", displayDuringSetup: false, type: "paragraph", element: "paragraph", required: true
input title: "", description: "http://www.github.com/Madj42/RyobiGDO", displayDuringSetup: false, type: "paragraph", element: "paragraph"
input "pollInterval", "number", title: "Polling Interval", description: "Change polling frequency (in minutes)", defaultValue:4, range: "1..59", required: true, displayDuringSetup: true
}
}
metadata {
definition (name: "Ryobi Garage Door", namespace: "madj42", author: "Justin Dybedahl") {
capability "Actuator"
capability "Door Control"
capability "Garage Door Control"
capability "Switch"
capability "Sensor"
capability "Polling"
capability "Momentary"
capability "Relay Switch"
capability "Refresh"
capability "Battery"
}
attribute "switch", "string"
command "on"
command "off"
command "open"
command "close"
// simulator metadata
simulator {
}
// UI tile definitions
tiles {
multiAttributeTile(name: "door", type: "lighting", width: 6, height: 4, canChangeIcon: false) {
tileAttribute("device.door", key: "PRIMARY_CONTROL") {
attributeState "closed", label: 'Door Closed', action: "door control.open", icon: "st.Home.home2", backgroundColor: "#ffffff"
attributeState "open", label: 'Door Open', action: "door control.close", icon: "st.Home.home2", backgroundColor: "#79b821"
attributeState "closing", label:'Door Closing', action:"door control.close", icon:"st.Home.home2", backgroundColor:"#00a0dc"
attributeState "opening", label:'Door Opening', action:"door control.open", icon:"st.Home.home2", backgroundColor:"#79b821"
}
}
standardTile("button2", "device.switch", width: 1, height: 1, canChangeIcon: false) {
state "off", label: 'Light Off', action: "switch.on", icon: "st.Lighting.light11", backgroundColor: "#ffffff"
state "on", label: 'Light On', action: "switch.off", icon: "st.Lighting.light11", backgroundColor: "#79b821"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", action:"refresh", icon:"st.secondary.refresh"
}
valueTile("battery", "device.Battery", inactiveLabel: false, decoration: "flat", width: 2, height: 1) {
state "Battery", label: 'Battery: ${currentValue}%'
}
valueTile("icon", "device.icon", inactiveLabel: false, decoration: "flat", width: 2, height: 1) {
state "default", label: '', icon: "https://logo-png.com/logo/ryobi-logo.png"
}
standardTile("open", "device.door", inactiveLabel: false, decoration: "flat") {
state "default", label:'open', action:"door control.open", icon:"st.Home.home2"
}
standardTile("close", "device.door", inactiveLabel: false, decoration: "flat") {
state "default", label:'close', action:"door control.close", icon:"st.Home.home2"
}
main "door"
details (["door","button","button2","refresh","battery","icon","open","close"])
}
}
def poll() {
getStatus()
}
def refresh() {
poll()
}
def updated() {
runIn(3, "updateDeviceNetworkID")
schedule("0 0/${settings.pollInterval} * * * ?", poll)
}
def parse(String description){
//log.debug "Parse called"
def msg = parseLanMessage(description)
if (msg.body.startsWith("status:")) {
def batstatus = msg.body.split(':')[3]
def doorstatus = msg.body.split(':')[2]
def lightstatus = msg.body.split(':')[1]
if (batstatus == "255") {
sendEvent(name: "Battery", value: 0)
} else if (batstatus == null) {
sendEvent(name: "Battery", value: 0)
} else if (batstatus == 'NA') {
sendEvent(name: "Battery", value: 0)
} else {
sendEvent(name: "Battery", value: batstatus)
}
if (lightstatus == "false") {
//log.debug "Light OFF"
sendEvent(name: "switch", value: "off")
} else if (lightstatus == "true") {
//log.debug "Light ON"
sendEvent(name: "switch", value: "on")
}
if (doorstatus == "0") {
//log.debug "Door Closed"
sendEvent(name: "door", value: "closed")
} else if (doorstatus == "1") {
//log.debug "Door Open"
sendEvent(name: "door", value: "open")
} else if (doorstatus == "2") {
//log.debug "Door Closing"
sendEvent(name: "door", value: "closing")
} else if (doorstatus == "3") {
//log.debug "Door Opening"
sendEvent(name: "door", value: "opening")
}
}
}
def on() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?name=lighton&doorid=${doorid}&apikey=${apikey}&email=${email}&pass=${pass}",
headers: [
HOST: "${internal_ip}:${internal_port}"
]
)
sendHubCommand(result)
sendEvent(name: "switch", value: "on")
runIn(5,getStatus)
log.debug "Turning light ON"
}
def off() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?name=lightoff&doorid=${doorid}&apikey=${apikey}&email=${email}&pass=${pass}",
headers: [
HOST: "${internal_ip}:${internal_port}"
]
)
sendHubCommand(result)
sendEvent(name: "switch", value: "off")
runIn(5,getStatus)
log.debug "Turning light OFF"
}
def open() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?name=dooropen&doorid=${doorid}&apikey=${apikey}&email=${email}&pass=${pass}",
headers: [
HOST: "${internal_ip}:${internal_port}"
]
)
sendHubCommand(result)
sendEvent(name: "door", value: "opening")
runIn(5,getStatus)
runIn(17,getStatus)
log.debug "OPENING Garage Door"
}
def close() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?name=doorclose&doorid=${doorid}&apikey=${apikey}&email=${email}&pass=${pass}",
headers: [
HOST: "${internal_ip}:${internal_port}"
]
)
sendHubCommand(result)
sendEvent(name: "door", value: "closing")
runIn(5,getStatus)
runIn(21,getStatus)
log.debug "CLOSING Garage Door"
}
def getStatus() {
def result = new physicalgraph.device.HubAction(
method: "GET",
path: "/?name=status&doorid=${doorid}&apikey=${apikey}&email=${email}&pass=${pass}",
headers: [
HOST: "${internal_ip}:${internal_port}"
])
sendHubCommand(result)
log.debug "Getting Status"
}
private String convertIPtoHex(ipAddress) {
String hex = ipAddress.tokenize( '.' ).collect { String.format( '%02x', it.toInteger() ) }.join()
//log.debug "IP address entered is $ipAddress and the converted hex code is $hex"
return hex
}
private String convertPortToHex(port) {
String hexport = port.toString().format( '%04x', port.toInteger() )
//log.debug hexport
return hexport
}
def updateDeviceNetworkID() {
log.debug "Executing 'updateDeviceNetworkID'"
def iphex = convertIPtoHex(internal_ip).toUpperCase()
def porthex = convertPortToHex(internal_port).toUpperCase()
device.setDeviceNetworkId(iphex + ":" + porthex)
}