-
Notifications
You must be signed in to change notification settings - Fork 14
/
CooperEatonRF9500
191 lines (165 loc) · 5.72 KB
/
CooperEatonRF9500
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
/**
* Copyright 2015 SmartThings
*
* 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.
*
*/
metadata {
definition (name: "Cooper RF9500 Stock new", namespace: "lgkapps", author: "[email protected]") {
capability "Switch"
capability "Switch Level"
capability "PushableButton"
capability "Actuator"
//fingerprint deviceId: "0x1200", inClusters: "0x77 0x86 0x75 0x73 0x85 0x72 0xEF", outClusters: "0x26"
}
// simulator metadata
simulator {
// status messages
status "on": "on/off: 1"
status "off": "on/off: 0"
// reply messages
reply "zcl on-off on": "on/off: 1"
reply "zcl on-off off": "on/off: 0"
}
// UI tile definitions
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "off", label: '${name}', action: "switch.on", icon: "st.Home.home30", backgroundColor: "#ffffff"
state "on", label: '${name}', action: "switch.off", icon: "st.Home.home30", backgroundColor: "#79b821"
}
standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
state "default", label:"", action:"refresh.refresh", icon:"st.secondary.refresh"
}
controlTile("levelSliderControl", "device.level", "slider", height: 1, width: 3, inactiveLabel: false) {
state "level", action:"switch level.setLevel"
}
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat") {
state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
}
main "switch"
details(["switch", "refresh", "level", "levelSliderControl"])
}
}
def parse(String description) {
def results = []
if (description.startsWith("Err")) {
results = createEvent(descriptionText:description, displayed:true)
} else {
def cmd = zwave.parse(description, [0x26: 1, 0x2B: 1, 0x80: 1, 0x84: 1])
if(cmd) results += zwaveEvent(cmd)
if(!results) results = [ descriptionText: cmd, displayed: false ]
}
log.debug("Parsed '$description' to $results")
return results
}
def on() {
sendEvent(name: "switch", value: "on")
}
def off() {
sendEvent(name: "switch", value: "off")
}
def levelup() {
//log.debug "in level up"
def curlevel = device.currentValue('level') as Integer
// log.debug "cur level = $curlevel"
if (curlevel <= 95)
setLevel(curlevel + 5);
}
def leveldown() {
//log.debug "in level down"
def curlevel = device.currentValue('level') as Integer
// log.debug "cur level = $curlevel"
if (curlevel > 5)
setLevel(curlevel - 5)
}
def setLevel(value) {
log.trace "setLevel($value)"
sendEvent(name: "level", value: value)
sendEvent(name:"switch.setLevel",value:value)
}
def zwaveEvent(hubitat.zwave.commands.wakeupv1.WakeUpNotification cmd) {
def results = [createEvent(descriptionText: "$device.displayName woke up", isStateChange: false)]
results += configurationCmds().collect{ response(it) }
results << response(zwave.wakeUpV1.wakeUpNoMoreInformation().format())
return results
}
// A zwave command for a button press was received convert to button number
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelStartLevelChange cmd) {
[ descriptionText: "startlevel $cmd"]
log.info "startlevel $cmd"
if (cmd.upDown == true) {
Integer buttonid = 2
leveldown()
checkbuttonEvent(buttonid)
} else if (cmd.upDown == false) {
Integer buttonid = 3
levelup()
checkbuttonEvent(buttonid)
}
}
// The controller likes to repeat the command... ignore repeats
def checkbuttonEvent(buttonid){
if (state.lastScene == buttonid && (state.repeatCount < 4) && (now() - state.repeatStart < 2000)) {
log.debug "Button ${buttonid} repeat ${state.repeatCount}x ${now()}"
state.repeatCount = state.repeatCount + 1
createEvent([:])
}
else {
// If the button was really pressed, store the new scene and handle the button press
state.lastScene = buttonid
state.lastLevel = 0
state.repeatCount = 0
state.repeatStart = now()
buttonEvent(buttonid)
}
}
// Handle a button being pressed
def buttonEvent(button) {
button = button as Integer
log.trace "Button $button pressed"
def result = []
if (button == 1) {
def mystate = device.currentValue('switch');
if (mystate == "on")
off()
else
on()
}
updateState("currentButton", "$button")
// update the device state, recording the button press
result << createEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
result
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicGet cmd) {
[ descriptionText: "$cmd"]
if(1){
Integer buttonid = 1
checkbuttonEvent(buttonid)
}
}
def zwaveEvent(hubitat.zwave.commands.basicv1.BasicSet cmd) {
[ descriptionText: "$cmd"]
if(1){
Integer buttonid = 1
log.info "button $buttonid pressed"
checkbuttonEvent(buttonid)
}
}
def zwaveEvent(hubitat.zwave.commands.switchmultilevelv1.SwitchMultilevelStopLevelChange cmd) {
createEvent([:])
}
def zwaveEvent(hubitat.zwave.Command cmd) {
[ descriptionText: "$cmd"]
}
// Update State
def updateState(String name, String value) {
state[name] = value
device.updateDataValue(name, value)
}