forked from InovelliUSA/Hubitat
/
inovelli-bulb-multi-white-lzw41.groovy
423 lines (376 loc) · 15.6 KB
/
inovelli-bulb-multi-white-lzw41.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
/**
* Copyright 2019 Inovelli / Eric Maycock
*
* 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.
*
* Inovelli Bulb Multi-White LZW41
*
* Author: Eric Maycock
* Date: 2019-9-9
* updated by bcopeland 1/7/2020
* Added color pre-staging option
* Added power restored memory configuration
* Added debug logging configuration
* Fixed color setting
* Fixed color temperature setting
* Fixed reporting
* Removed SmartThings related code
* Added importURL
* Added color name
* updated by bcopeland 1/9/2020
* added firmware version reporting
* updated by bcopeland 1/21/2020
* fixes for reported bugs
* correct comand class versions to match what the hardware supports
* add z-wave color component ids manually as it didnt seem to match in correct command class version from he
* updated by bcopeland 2/6/2020
* added ChangeLevel capability and relevant commands
* updated by bcopeland 2/15/2020
* dramatically improved speed of CT operations and reduced packet count - Make sure to hit configure after updating.
* improved speed of on/off events also reducing packets
* improved speed of setLevel events also reducing packets
* updated by bcopeland 3/11/2020
* improved speed reduced packets on CT set operations
* added color fade time preference for smoother CT transitions
* updated by bcopeland 3/15/2020
* fix for issue with reporting when using more than 1 device with the same driver
* update by bcopeland 4/9/2020
* major re-write for new coding standards / cleanup
* stabilization of color temp reporting
* re-organization of device data for standardization / addition of serialnumber, hardware ver, protocol ver, firmware
* re-work of associations
* updated by npk22 4/9/2020
* added dimming speed parameter
* added dimming speed to on / off
* updated by bcopeland 4/11/2020
* fixed type definitions
* fixed fingerprint
* updated by bcopeland 4/12/2020
* added duplicate event filtering (optional as it has a slight possibility of causing issues with voice assistants)
* changed dimming speed default to 1 to match previous default functionality
* updated by InovelliUSA 4/15/2020
* corrected incorrect options for parameter 2
* updated by bcopeland 4/16/2020
* updated ambiguous language
*/
import groovy.transform.Field
metadata {
definition (name: "Inovelli Bulb Multi-White LZW41", namespace: "InovelliUSA", author: "InovelliUSA", importUrl: "https://raw.githubusercontent.com/InovelliUSA/Hubitat/master/Drivers/inovelli-bulb-multi-white-lzw41.src/inovelli-bulb-multi-white-lzw41.groovy") {
capability "SwitchLevel"
capability "ColorTemperature"
capability "Switch"
capability "Refresh"
capability "Actuator"
capability "Sensor"
capability "Configuration"
capability "ChangeLevel"
attribute "colorName", "string"
fingerprint mfr: "031E", prod: "0006", model: "0001", deviceJoinName: "Inovelli Bulb Multi-White" //US
}
preferences {
configParams.each { input it.value.input }
input name: "colorStaging", type: "bool", description: "", title: "Enable color pre-staging", defaultValue: false
input name: "colorTransition", type: "number", description: "", title: "Color fade time:", defaultValue: 0
input name: "dimmingSpeed", type: "number", description: "", title: "Dimming speed:", defaultValue: 1
input name: "eventFilter", type: "bool", title: "Filter out duplicate events", defaultValue: false
input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}
}
@Field static Map configParams = [
2: [input: [name: "configParam2", type: "enum", title: "Power fail load state restore", description: "", defaultValue: 0, options: [0:"Bulb turns ON",1:"Bulb remembers last state"]], parameterSize: 1]
]
@Field static Map CMD_CLASS_VERS=[0x33:2,0x26:2,0x86:2,0x70:1]
@Field static int COLOR_TEMP_MIN=2700
@Field static int COLOR_TEMP_MAX=6500
@Field static int WARM_WHITE_CONFIG=0x51
@Field static int COLD_WHITE_CONFIG=0x52
@Field static String WARM_WHITE="warmWhite"
@Field static String COLD_WHITE="coldWhite"
@Field static Map ZWAVE_COLOR_COMPONENT_ID=[warmWhite: 0, coldWhite: 1, red: 2, green: 3, blue: 4]
@Field static List<String> WHITE_NAMES=["warmWhite", "coldWhite"]
private getCOLOR_TEMP_DIFF() { COLOR_TEMP_MAX - COLOR_TEMP_MIN }
void logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("logEnable",[value:"false",type:"bool"])
}
void configure() {
if (!state.initialized) initializeVars()
runIn(5,pollDeviceData)
}
void initializeVars() {
// first run only
state.colorReceived=[red: null, green: null, blue: null, warmWhite: null, coldWhite: null]
state.initialized=true
runIn(5, refresh)
}
void updated() {
log.info "updated..."
log.warn "debug logging is: ${logEnable == true}"
unschedule()
if (logEnable) runIn(1800,logsOff)
runConfigs()
}
void runConfigs() {
List<hubitat.zwave.Command> cmds=[]
configParams.each { param, data ->
if (settings[data.input.name]) {
cmds.addAll(configCmd(param, data.parameterSize, settings[data.input.name]))
}
}
sendToDevice(cmds)
}
List<hubitat.zwave.Command> configCmd(parameterNumber, size, scaledConfigurationValue) {
List<hubitat.zwave.Command> cmds = []
cmds.add(zwave.configurationV1.configurationSet(parameterNumber: parameterNumber.toInteger(), size: size.toInteger(), scaledConfigurationValue: scaledConfigurationValue.toInteger()))
cmds.add(zwave.configurationV1.configurationGet(parameterNumber: parameterNumber.toInteger()))
return cmds
}
void zwaveEvent(hubitat.zwave.commands.configurationv1.ConfigurationReport cmd) {
if(configParams[cmd.parameterNumber.toInteger()]) {
Map configParam=configParams[cmd.parameterNumber.toInteger()]
int scaledValue
cmd.configurationValue.reverse().eachWithIndex { v, index -> scaledValue=scaledValue | v << (8*index) }
device.updateSetting(configParam.input.name, [value: "${scaledValue}", type: configParam.input.type])
}
}
void pollDeviceData() {
List<hubitat.zwave.Command> cmds = []
cmds.add(zwave.versionV2.versionGet())
cmds.add(zwave.manufacturerSpecificV2.deviceSpecificGet(deviceIdType: 1))
cmds.add(zwave.configurationV1.configurationGet(parameterNumber: 2))
cmds.addAll(configCmd(51,2,1387))
cmds.addAll(configCmd(52,2,6500))
cmds.addAll(processAssociations())
sendToDevice(cmds)
}
void refresh() {
List<hubitat.zwave.Command> cmds=[]
cmds.add(zwave.switchMultilevelV2.switchMultilevelGet())
cmds.add(zwave.basicV1.basicGet())
cmds.addAll(queryAllColors())
sendToDevice(cmds)
}
private void refreshColor() {
sendToDevice(queryAllColors())
}
void installed() {
if (logEnable) log.debug "installed()..."
sendEvent(name: "level", value: 100, unit: "%")
sendEvent(name: "colorTemperature", value: 2700)
initializeVars()
}
private List<hubitat.zwave.Command> queryAllColors() {
List<hubitat.zwave.Command> cmds=[]
WHITE_NAMES.each { cmds.add(zwave.switchColorV2.switchColorGet(colorComponent: it, colorComponentId: ZWAVE_COLOR_COMPONENT_ID[it])) }
return cmds
}
void eventProcess(Map evt) {
if (device.currentValue(evt.name).toString() != evt.value.toString() || !eventFilter) {
evt.isStateChange=true
sendEvent(evt)
}
}
void startLevelChange(direction) {
boolean upDownVal = direction == "down" ? true : false
if (logEnable) log.debug "got startLevelChange(${direction})"
sendToDevice(zwave.switchMultilevelV2.switchMultilevelStartLevelChange(ignoreStartLevel: true, startLevel: device.currentValue("level"), upDown: upDownVal))
}
void stopLevelChange() {
sendToDevice(zwave.switchMultilevelV2.switchMultilevelStopLevelChange())
}
void zwaveEvent(hubitat.zwave.commands.basicv1.BasicReport cmd) {
if (logEnable) log.debug cmd
dimmerEvents(cmd)
}
void zwaveEvent(hubitat.zwave.commands.switchmultilevelv2.SwitchMultilevelReport cmd) {
if (logEnable) log.debug cmd
dimmerEvents(cmd)
}
void zwaveEvent(hubitat.zwave.commands.switchcolorv2.SwitchColorReport cmd) {
if (logEnable) log.debug "got SwitchColorReport: $cmd"
if (!state.colorReceived) initializeVars()
state.colorReceived[cmd.colorComponent] = cmd.value
if (WHITE_NAMES.every { state.colorReceived[it] != null}) {
int warmWhite = state.colorReceived[WARM_WHITE]
int coldWhite = state.colorReceived[COLD_WHITE]
if (logEnable) log.debug "warmWhite: $warmWhite, coldWhite: $coldWhite"
if (warmWhite == 0 && coldWhite == 0) {
eventProcess(name: "colorTemperature", value: COLOR_TEMP_MIN)
} else {
int colorTemp = COLOR_TEMP_MIN + (COLOR_TEMP_DIFF / 2)
if (warmWhite != coldWhite) {
colorTemp = (COLOR_TEMP_MAX - (COLOR_TEMP_DIFF * warmWhite) / 255) as Integer
}
eventProcess(name: "colorTemperature", value: colorTemp)
setGenericTempName(colorTemp)
}
}
}
private void dimmerEvents(hubitat.zwave.Command cmd) {
def value = (cmd.value ? "on" : "off")
eventProcess(name: "switch", value: value, descriptionText: "$device.displayName was turned $value")
if (cmd.value) {
eventProcess(name: "level", value: cmd.value == 99 ? 100 : cmd.value , unit: "%")
}
}
void on() {
//Check if dimming speed exists and set the duration
int duration=0
if (dimmingSpeed) duration=dimmingSpeed.toInteger()
sendToDevice(zwave.switchMultilevelV2.switchMultilevelSet(value: 0xFF, dimmingDuration: duration))
}
void off() {
//Check if dimming speed exists and set the durration
def duration=0
if (dimmingSpeed) duration=dimmingSpeed.toInteger()
sendToDevice(zwave.switchMultilevelV2.switchMultilevelSet(value: 0x00, dimmingDuration: duration))
}
void setLevel(level) {
//Check if dimming speed exists and set the duration
int duration=1
if (dimmingSpeed) duration=dimmingSpeed.toInteger()
setLevel(level, duration)
}
void setLevel(level, duration) {
if (logEnable) log.debug "setLevel($level, $duration)"
if(level > 99) level = 99
sendToDevice(zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: duration))
}
void setColorTemperature(temp) {
if (logEnable) log.debug "setColorTemperature($temp)"
int dimmingDuration=0
if (colorTransition) dimmingDuration=colorTransition
List<hubitat.zwave.Command> cmds = []
if (temp < COLOR_TEMP_MIN) temp = COLOR_TEMP_MIN
if (temp > COLOR_TEMP_MAX) temp = COLOR_TEMP_MAX
int warmValue = ((COLOR_TEMP_MAX - temp) / COLOR_TEMP_DIFF * 255) as Integer
int coldValue = 255 - warmValue
cmds.add(zwave.switchColorV2.switchColorSet(warmWhite: warmValue, coldWhite: coldValue, dimmingDuration: dimmingDuration))
if ((device.currentValue("switch") != "on") && (!colorStaging)) {
if (logEnable) log.debug "Bulb is off. Turning on"
cmds.add(zwave.basicV1.basicSet(value: 0xFF))
}
sendToDevice(cmds)
runIn(dimmingDuration, "refreshColor")
}
private void setGenericTempName(temp){
if (!temp) return
String genericName
int value = temp.toInteger()
if (value <= 2000) genericName = "Sodium"
else if (value <= 2100) genericName = "Starlight"
else if (value < 2400) genericName = "Sunrise"
else if (value < 2800) genericName = "Incandescent"
else if (value < 3300) genericName = "Soft White"
else if (value < 3500) genericName = "Warm White"
else if (value < 4150) genericName = "Moonlight"
else if (value <= 5000) genericName = "Horizon"
else if (value < 5500) genericName = "Daylight"
else if (value < 6000) genericName = "Electronic"
else if (value <= 6500) genericName = "Skylight"
else if (value < 20000) genericName = "Polar"
String descriptionText = "${device.getDisplayName()} color is ${genericName}"
eventProcess(name: "colorName", value: genericName ,descriptionText: descriptionText)
}
void zwaveEvent(hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
hubitat.zwave.Command encapsulatedCommand = cmd.encapsulatedCommand(CMD_CLASS_VERS)
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}
void parse(String description) {
if (logEnable) log.debug "parse:${description}"
hubitat.zwave.Command cmd = zwave.parse(description, CMD_CLASS_VERS)
if (cmd) {
zwaveEvent(cmd)
}
}
void zwaveEvent(hubitat.zwave.commands.supervisionv1.SupervisionGet cmd) {
if (logEnable) log.debug "Supervision get: ${cmd}"
hubitat.zwave.Command encapsulatedCommand = cmd.encapsulatedCommand(CMD_CLASS_VERS)
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
sendToDevice(new hubitat.zwave.commands.supervisionv1.SupervisionReport(sessionID: cmd.sessionID, reserved: 0, moreStatusUpdates: false, status: 0xFF, duration: 0))
}
void zwaveEvent(hubitat.zwave.commands.manufacturerspecificv2.DeviceSpecificReport cmd) {
if (logEnable) log.debug "Device Specific Report: ${cmd}"
switch (cmd.deviceIdType) {
case 1:
// serial number
def serialNumber=""
if (cmd.deviceIdDataFormat==1) {
cmd.deviceIdData.each { serialNumber += hubitat.helper.HexUtils.integerToHexString(it & 0xff,1).padLeft(2, '0')}
} else {
cmd.deviceIdData.each { serialNumber += (char) it }
}
device.updateDataValue("serialNumber", serialNumber)
break
}
}
void zwaveEvent(hubitat.zwave.commands.versionv2.VersionReport cmd) {
if (logEnable) log.debug "version3 report: ${cmd}"
device.updateDataValue("firmwareVersion", "${cmd.firmware0Version}.${cmd.firmware0SubVersion}")
device.updateDataValue("protocolVersion", "${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}")
device.updateDataValue("hardwareVersion", "${cmd.hardwareVersion}")
}
void sendToDevice(List<hubitat.zwave.Command> cmds) {
sendHubCommand(new hubitat.device.HubMultiAction(commands(cmds), hubitat.device.Protocol.ZWAVE))
}
void sendToDevice(hubitat.zwave.Command cmd) {
sendHubCommand(new hubitat.device.HubAction(secureCommand(cmd), hubitat.device.Protocol.ZWAVE))
}
void sendToDevice(String cmd) {
sendHubCommand(new hubitat.device.HubAction(secureCommand(cmd), hubitat.device.Protocol.ZWAVE))
}
List<String> commands(List<hubitat.zwave.Command> cmds, Long delay=200) {
return delayBetween(cmds.collect{ secureCommand(it) }, delay)
}
String secureCommand(hubitat.zwave.Command cmd) {
secureCommand(cmd.format())
}
String secureCommand(String cmd) {
String encap=""
if (getDataValue("zwaveSecurePairingComplete") != "true") {
return cmd
} else {
encap = "988100"
}
return "${encap}${cmd}"
}
void zwaveEvent(hubitat.zwave.Command cmd) {
if (logEnable) log.debug "skip:${cmd}"
}
List<hubitat.zwave.Command> setDefaultAssociation() {
List<hubitat.zwave.Command> cmds=[]
cmds.add(zwave.associationV2.associationSet(groupingIdentifier: 1, nodeId: zwaveHubNodeId))
cmds.add(zwave.associationV2.associationGet(groupingIdentifier: 1))
return cmds
}
List<hubitat.zwave.Command> processAssociations(){
List<hubitat.zwave.Command> cmds = []
cmds.addAll(setDefaultAssociation())
return cmds
}
void zwaveEvent(hubitat.zwave.commands.associationv2.AssociationReport cmd) {
if (logEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
List<String> temp = []
if (cmd.nodeId != []) {
cmd.nodeId.each {
temp.add(it.toString().format( '%02x', it.toInteger() ).toUpperCase())
}
}
updateDataValue("zwaveAssociationG${cmd.groupingIdentifier}", "$temp")
}
void zwaveEvent(hubitat.zwave.commands.associationv2.AssociationGroupingsReport cmd) {
if (logEnable) log.debug "${device.label?device.label:device.name}: ${cmd}"
log.info "${device.label?device.label:device.name}: Supported association groups: ${cmd.supportedGroupings}"
state.associationGroups = cmd.supportedGroupings
}