-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathPhilioSmartColorButton.groovy
215 lines (185 loc) · 7.35 KB
/
PhilioSmartColorButton.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
/**
* Copyright 2016 AdamV
*
* 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: "Smart Color Button PSR04", namespace: "Philio", author: "AdamV") {
capability "Actuator"
capability "Switch"
capability "Switch Level"
capability "Refresh"
capability "Sensor"
capability "Configuration"
capability "Battery"
fingerprint deviceId: "0x1801", inClusters: "0x5E, 0x80, 0x85, 0x70, 0x72, 0x86, 0x84, 0x59, 0x73, 0x5A, 0x8F, 0x98, 0x7A, 0x5B", outClusters: "0x20"
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
}
tiles {
multiAttributeTile(name:"button", type:"lighting", width:6, height:4) {
tileAttribute("device.button", key: "PRIMARY_CONTROL"){
attributeState "default", label:'Controller', backgroundColor:"#44b621", icon:"st.Home.home30"
attributeState "held", label: "holding", backgroundColor: "#C390D4"
}
tileAttribute ("device.battery", key: "SECONDARY_CONTROL") {
attributeState "battery", label:'${currentValue} % battery'
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
// tileAttribute ("device.level", key: "SECONDARY_CONTROL") {
// attributeState "level", label: 'Level is ${currentValue}%'
//}
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("configure", "device.button", width: 2, height: 2, decoration: "flat") {
state "default", label: "configure", backgroundColor: "#ffffff", action: "configure"
}
main "button"
details (["button", "refresh", "configure"])
}
}
def parse(String description) {
def result = []
if (description.startsWith("Err")) {
result = createEvent(descriptionText:description, isStateChange:true)
} else {
def cmd = zwave.parse(description, [0x20: 1, 0x84: 1, 0x98: 1, 0x56: 1, 0x60: 3])
if (cmd) {
result += zwaveEvent(cmd)
}
log.debug("This is what I receive: $cmd")
}
return result
}
def updated() {
response(zwave.wakeUpV1.wakeUpNoMoreInformation())
}
def zwaveEvent(physicalgraph.zwave.commands.wakeupv1.WakeUpNotification cmd) {
[ createEvent(descriptionText: "${device.displayName} woke up"),
response(zwave.wakeUpV1.wakeUpNoMoreInformation()) ]
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
if (cmd.value == 0) {
createEvent(name: "switch", value: "off")
} else if (cmd.value == 255) {
createEvent(name: "switch", value: "on")
} else {
[ createEvent(name: "switch", value: "on"), createEvent(name: "switchLevel", value: cmd.value) ]
}
}
def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def map = [ name: "battery", unit: "%" ]
if (cmd.batteryLevel == 0xFF) { // Special value for low battery alert
map.value = 1
map.descriptionText = "${device.displayName} has a low battery"
map.isStateChange = true
} else {
map.value = cmd.batteryLevel
log.debug ("Battery: $cmd.batteryLevel")
}
// Store time of last battery update so we don't ask every wakeup, see WakeUpNotification handler
state.lastbatt = new Date().time
createEvent(map)
}
def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x84: 1])
if (encapsulatedCommand) {
state.sec = 1
def result = zwaveEvent(encapsulatedCommand)
result = result.collect {
if (it instanceof physicalgraph.device.HubAction && !it.toString().startsWith("9881")) {
response(cmd.CMD + "00" + it.toString())
} else {
it
}
}
result
}
}
def zwaveEvent(physicalgraph.zwave.commands.centralscenev1.CentralSceneNotification cmd) {
log.debug( "keyAttributes: $cmd.keyAttributes")
log.debug( "sceneNumber: $cmd.sceneNumber")
log.debug( "sequenceNumber: $cmd.sequenceNumber")
if ( cmd.sceneNumber == 1 ) {
Integer button = 1
sendEvent(name: "button", value: "pushed", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
log.debug( "Button $button was pushed" )
}
// log.debug( "payload: $cmd.payload")
}
def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd) {
log.debug( "Value: $cmd.value")
def dimmerValue = cmd.value
if (cmd.value == 0) {
sendEvent(name: "switch", value: "off")
log.debug("turned off")
sendEvent(name: "level", value: dimmerValue)
} else if (cmd.value == 255) {
sendEvent(name: "switch", value: "on")
log.debug("turned on")
} else {
sendEvent(name: "switch", value: "on")
//createEvent(name: "level", value: dimmerValue)
sendEvent(name: "level", value: dimmerValue)
log.debug("sent switch on at value $cmd.value")
}
// log.debug( "payload: $cmd.payload")
}
def zwaveEvent(physicalgraph.zwave.commands.crc16encapv1.Crc16Encap cmd) {
def versions = [0x31: 2, 0x30: 1, 0x84: 1, 0x9C: 1, 0x70: 2]
// def encapsulatedCommand = cmd.encapsulatedCommand(versions)
def version = versions[cmd.commandClass as Integer]
def ccObj = version ? zwave.commandClass(cmd.commandClass, version) : zwave.commandClass(cmd.commandClass)
def encapsulatedCommand = ccObj?.command(cmd.command)?.parse(cmd.data)
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}
def zwaveEvent(physicalgraph.zwave.Command cmd) {
createEvent(descriptionText: "$device.displayName: $cmd", isStateChange: true)
}
def on() {
commands([zwave.basicV1.basicSet(value: 0xFF), zwave.basicV1.basicGet()])
}
def off() {
commands([zwave.basicV1.basicSet(value: 0x00), zwave.basicV1.basicGet()])
}
def refresh() {
command(zwave.basicV1.basicGet())
}
def setLevel(value) {
commands([zwave.basicV1.basicSet(value: value as Integer), zwave.basicV1.basicGet()], 4000)
}
private command(physicalgraph.zwave.Command cmd) {
if (state.sec) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
} else {
cmd.format()
}
}
private commands(commands, delay=200) {
delayBetween(commands.collect{ command(it) }, delay)
}
def configure() {
def commands = [ ]
log.debug "Resetting Sensor Parameters to SmartThings Compatible Defaults"
def cmds = []
cmds << zwave.associationV1.associationSet(groupingIdentifier: 1, nodeId: zwaveHubNodeId).format()
cmds << zwave.associationV1.associationSet(groupingIdentifier: 2, nodeId: zwaveHubNodeId).format()
cmds << zwave.configurationV1.configurationSet(configurationValue: [10], parameterNumber: 10, size: 1).format()
delayBetween(cmds, 500)
}