@@ -79,7 +79,7 @@ tiles(scale: 2){
79
79
80
80
}
81
81
preferences {
82
- input description : " Once you change values on this page, the corner of the \" configuration\" icon will change orange until all configuration parameters are updated." , title : " Settings" , displayDuringSetup : false , type : " paragraph" , element : " paragraph"
82
+ input description : " Once you change values on this page, the corner of the \" configuration\" icon will change orange until all configuration parameters are updated." , title : " Settings" , type : " paragraph" , element : " paragraph"
83
83
generate_preferences(configuration_model())
84
84
}
85
85
}
@@ -177,15 +177,15 @@ def refresh() {
177
177
cmds << zwave. switchBinaryV1. switchBinaryGet()
178
178
cmds << zwave. meterV2. meterGet(scale : 0 )
179
179
cmds << zwave. meterV2. meterGet(scale : 2 )
180
- secureSequence (cmds, 1000 )
180
+ commands (cmds, 1000 )
181
181
}
182
182
183
183
def reset () {
184
184
def cmds = []
185
185
cmds << zwave. meterV2. meterReset()
186
186
cmds << zwave. meterV2. meterGet(scale : 0 )
187
187
cmds << zwave. meterV2. meterGet(scale : 2 )
188
- secureSequence (cmds, 1000 )
188
+ commands (cmds, 1000 )
189
189
}
190
190
191
191
def ping () {
@@ -209,7 +209,7 @@ def configure() {
209
209
210
210
cmds = update_needed_settings()
211
211
212
- if (cmds != []) secureSequence (cmds)
212
+ if (cmds != []) commands (cmds)
213
213
}
214
214
215
215
def zwaveEvent (hubitat.zwave.commands.centralscenev1.CentralSceneNotification cmd ) {
@@ -224,41 +224,53 @@ def zwaveEvent(hubitat.zwave.commands.centralscenev1.CentralSceneNotification cm
224
224
225
225
def buttonEvent (button , value ) {
226
226
logging(" buttonEvent() Button:$button , Value:$value " )
227
- createEvent(name : " button" , value : value, data : [buttonNumber : button], descriptionText : " $device . displayName button $button was $value " , isStateChange : true )
227
+ sendEvent(name : value, value : button, isStateChange :true )
228
+ }
229
+
230
+ def installed () {
231
+ def cmds = initialize()
232
+ if (cmds != []) commands(cmds)
228
233
}
229
234
230
235
/**
231
236
* Triggered when Done button is pushed on Preference Pane
232
237
*/
233
238
def updated ()
234
239
{
235
- state. enableDebugging = settings. enableDebugging
236
240
logging(" updated() is being called" )
241
+ def cmds = initialize()
242
+ sendEvent(name :" needUpdate" , value : device. currentValue(" needUpdate" ), displayed :false , isStateChange : true )
243
+ if (cmds != []) commands(cmds)
244
+ }
245
+
246
+ def initialize () {
247
+ log. debug " initialize()"
248
+ state. enableDebugging = settings. enableDebugging
237
249
sendEvent(name : " checkInterval" , value : 2 * 30 * 60 + 2 * 60 , displayed : false , data : [protocol : " zwave" , hubHardwareId : device. hub. hardwareID])
238
- def cmds = update_needed_settings()
239
-
240
- sendEvent(name :" needUpdate" , value : device. currentValue(" needUpdate" ), displayed :false , isStateChange : true )
241
-
242
- if (cmds != []) response(secureSequence(cmds))
250
+ return update_needed_settings()
243
251
}
244
252
245
253
def on () {
246
- secureSequence ([
254
+ commands ([
247
255
zwave. basicV1. basicSet(value : 0xFF )
248
256
])
249
257
}
250
258
def off () {
251
- secureSequence ([
259
+ commands ([
252
260
zwave. basicV1. basicSet(value : 0x00 )
253
261
])
254
262
}
255
263
256
- private secure (hubitat.zwave.Command cmd ) {
257
- zwave. securityV1. securityMessageEncapsulation(). encapsulate(cmd). format()
264
+ private command (hubitat.zwave.Command cmd ) {
265
+ if (state. sec) {
266
+ zwave. securityV1. securityMessageEncapsulation(). encapsulate(cmd). format()
267
+ } else {
268
+ cmd. format()
269
+ }
258
270
}
259
271
260
- private secureSequence (commands , delay = 1500 ) {
261
- delayBetween(commands. collect{ secure (it) }, delay)
272
+ private commands (commands , delay = 1000 ) {
273
+ delayBetween(commands. collect{ command (it) }, delay)
262
274
}
263
275
264
276
private encap (cmd , endpoint ) {
@@ -270,8 +282,11 @@ private encap(cmd, endpoint) {
270
282
}
271
283
272
284
def zwaveEvent (hubitat.zwave.commands.securityv1.SecurityMessageEncapsulation cmd ) {
285
+ // log.debug cmd
286
+ // def encapsulatedCommand = cmd.encapsulatedCommand([0x20: 1, 0x32: 3, 0x25: 1, 0x98: 1, 0x70: 2, 0x85: 2, 0x9B: 1, 0x90: 1, 0x73: 1, 0x30: 1, 0x28: 1, 0x2B: 1, , 0x5B: 1]) // can specify command class versions here like in zwave.parse
273
287
def encapsulatedCommand = cmd. encapsulatedCommand([0x20 : 1 , 0x32 : 3 , 0x25 : 1 , 0x98 : 1 , 0x70 : 2 , 0x85 : 2 , 0x9B : 1 , 0x90 : 1 , 0x73 : 1 , 0x30 : 1 , 0x28 : 1 , 0x2B : 1 ]) // can specify command class versions here like in zwave.parse
274
288
if (encapsulatedCommand) {
289
+ state. sec = 1
275
290
return zwaveEvent(encapsulatedCommand)
276
291
} else {
277
292
log. warn " Unable to extract encapsulated cmd from $cmd "
@@ -291,30 +306,26 @@ def generate_preferences(configuration_model)
291
306
input " ${ it.@index} " , " number" ,
292
307
title :" ${ it.@label} \n " + " ${ it.Help} " ,
293
308
range : " ${ it.@min} ..${ it.@max} " ,
294
- defaultValue : " ${ it.@value} " ,
295
- displayDuringSetup : " ${ it.@displayDuringSetup} "
309
+ defaultValue : " ${ it.@value} "
296
310
break
297
311
case " list" :
298
312
def items = []
299
313
it.Item . each { items << [" ${ it.@value} " :" ${ it.@label} " ] }
300
314
input " ${ it.@index} " , " enum" ,
301
315
title :" ${ it.@label} \n " + " ${ it.Help} " ,
302
316
defaultValue : " ${ it.@value} " ,
303
- displayDuringSetup : " ${ it.@displayDuringSetup} " ,
304
317
options : items
305
318
break
306
319
case " decimal" :
307
320
input " ${ it.@index} " , " decimal" ,
308
321
title :" ${ it.@label} \n " + " ${ it.Help} " ,
309
322
range : " ${ it.@min} ..${ it.@max} " ,
310
- defaultValue : " ${ it.@value} " ,
311
- displayDuringSetup : " ${ it.@displayDuringSetup} "
323
+ defaultValue : " ${ it.@value} "
312
324
break
313
325
case " boolean" :
314
326
input " ${ it.@index} " , " bool" ,
315
327
title : it. @label != " " ? " ${ it.@label} \n " + " ${ it.Help} " : " " + " ${ it.Help} " ,
316
- defaultValue : " ${ it.@value} " ,
317
- displayDuringSetup : " ${ it.@displayDuringSetup} "
328
+ defaultValue : " ${ it.@value} "
318
329
break
319
330
case " paragraph" :
320
331
input title : " ${ it.@label} " ,
@@ -393,16 +404,16 @@ def convertParam(number, value) {
393
404
def parValue
394
405
switch (number){
395
406
case 28 :
396
- parValue = (value == " true" ? 1 : 0 )
397
- parValue + = (settings. " fc_2" == " true" ? 2 : 0 )
398
- parValue + = (settings. " fc_3" == " true" ? 4 : 0 )
399
- parValue + = (settings. " fc_4" == " true" ? 8 : 0 )
407
+ parValue = (value == true ? 1 : 0 )
408
+ parValue + = (settings. " fc_2" == true ? 2 : 0 )
409
+ parValue + = (settings. " fc_3" == true ? 4 : 0 )
410
+ parValue + = (settings. " fc_4" == true ? 8 : 0 )
400
411
break
401
412
case 29 :
402
- parValue = (value == " true" ? 1 : 0 )
403
- parValue + = (settings. " sc_2" == " true" ? 2 : 0 )
404
- parValue + = (settings. " sc_3" == " true" ? 4 : 0 )
405
- parValue + = (settings. " sc_4" == " true" ? 8 : 0 )
413
+ parValue = (value == true ? 1 : 0 )
414
+ parValue + = (settings. " sc_2" == true ? 2 : 0 )
415
+ parValue + = (settings. " sc_3" == true ? 4 : 0 )
416
+ parValue + = (settings. " sc_4" == true ? 8 : 0 )
406
417
break
407
418
default :
408
419
parValue = value
@@ -462,27 +473,13 @@ def integer2Cmd(value, size) {
462
473
}
463
474
}
464
475
465
- private command (hubitat.zwave.Command cmd ) {
466
-
467
- if (state. sec && cmd. toString() != " WakeUpIntervalGet()" ) {
468
- zwave. securityV1. securityMessageEncapsulation(). encapsulate(cmd). format()
469
- } else {
470
- cmd. format()
471
- }
472
- }
473
-
474
- private commands (commands , delay = 1000 ) {
475
- delayBetween(commands. collect{ command(it) }, delay)
476
- }
477
-
478
476
def zwaveEvent (hubitat.zwave.commands.crc16encapv1.Crc16Encap cmd ) {
479
- def versions = [0x31 : 5 , 0x30 : 1 , 0x9C : 1 , 0x70 : 2 , 0x85 : 2 ]
480
- def version = versions[cmd. commandClass as Integer ]
481
- def ccObj = version ? zwave. commandClass(cmd. commandClass, version) : zwave. commandClass(cmd. commandClass)
482
- def encapsulatedCommand = ccObj?. command(cmd. command)?. parse(cmd. data)
483
- if (encapsulatedCommand) {
484
- zwaveEvent(encapsulatedCommand)
485
- }
477
+ def encapsulatedCommand = zwave. getCommand(cmd. commandClass, cmd. command, cmd. data, 1 )
478
+ if (encapsulatedCommand) {
479
+ zwaveEvent(encapsulatedCommand)
480
+ } else {
481
+ log. warn " Unable to extract CRC16 command from ${ cmd} "
482
+ }
486
483
}
487
484
488
485
def configuration_model ()
@@ -704,4 +701,4 @@ Momentary Mode
704
701
</Value>
705
702
</configuration>
706
703
'''
707
- }
704
+ }
0 commit comments