-
Notifications
You must be signed in to change notification settings - Fork 2
/
hunter-douglas-powerview-shade.groovy
733 lines (641 loc) · 28.2 KB
/
hunter-douglas-powerview-shade.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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
/**
* Hunter Douglas PowerView Shade
*
* Copyright 2017 Chris Lang
*
* Ported to Hubitat by Brian Ujvary
*
* 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.
*
* Change Log:
* 12/20/2023 v2.6.8 - Version number update only
* 04/03/2023 v2.6.7 - Added Open Position and Closed Position preferences
* 10/09/2022 v2.6.6 - Fixed initialization of the shade capabilities state value
* 10/07/2022 v2.6.5 - Added logic to convert shade type to an equivalent shade capabilities value
* - Added shade capabilities type 10 as defined by the HD Powerview Gen3 API
* - Added logic to reinitialize the "Shade capability information" state on install
* 10/06/2022 v2.6.4 - Added logic to isOpen() and isClosed() to check state of Top-Down shades
* 10/06/2022 v2.6.3 - Reversed min/max values and fixed posKind for Top-Down shades in open() and close()
* - Initialized state.capabilities to -1 if not in shade data from hub
* - Added note to "Shade capability information" about state.capabilities being -1
* - Fixed checks in handleEvent() for missing values
* 09/08/2022 v2.6.2 - Added check for shade firmware version
* 06/24/2022 v2.6.1 - Version number update only
* 06/23/2022 v2.6.0 - Version number update only
* 02/17/2022 v2.5.5 - Reverted logic in isOpen() and isClosed() to how it worked in v2.5.3
* - Modified isClosed() to allow closed state to be <= 1 to allow for imprecise calibration of shades
* 02/16/2022 v2.5.4 - Added tiltClockwise() and tiltCounterClockwise() to allow full close of 180 degree tilt shades
* - Refactored isClosed() and isOpen() to handle open/close state based on shade capabilities
* 02/16/2022 v2.5.3 - Modified isOpen() to allow open state to be >= 99 since Hunter Douglas app uses 0-99
* - Modified tiltOpen() to set tiltPosition to 50 if shade supports 180 degree tilt
* 02/08/2022 v2.5.2 - Moved timedOut signal out of battery level update so it's detected as long as it's
* present in the JSON response.
* 01/31/2022 v2.5.1 - Added attribute to indicate that a forced refresh timed out so it can be used in rules
* 01/25/2022 v2.5.0 - Version number update only
* 01/24/2022 v2.4.0 - Version number update only
* 01/21/2022 v2.3.0 - Version number update only
* 01/20/2022 v2.2.0 - Changed topPosition to 0 in open() and isOpen() for TD/BU shades
* - Modified setLevel() to set topPosition to 0 and bottomPosition to user requested position for TD/BU shades
* - Added startPositionChange() and stopPositionChange() as well as "stop" command and stop()
* - Added presetPosition command and updated presetPosition()
* - Cleaned up debug logging
* 01/19/2022 v2.1.0 - General release with shade tilt capability and better handling of TD/BU shades
* 01/17/2022 v2.0.3 - Refactored code to better handle top-down/bottom windowShade event
* - Initialized setting railForLevelState if it was null
* 01/13/2022 v2.0.2 - Fixed top-down/bottom up shade state settings for level, position and open/close
* - Added preference for top-down/bottom up shade rail selection for level setting
* - Refactored open(), close(), tilt_open(), tilt_close() and setTiltPosition()
* 01/12/2022 v2.0.1 - Fixed issues with tilt capability
* 01/06/2021 v2.0.0 - Added tilt capability based on shade capabilities
* 11/09/2021 v1.9 - Added check for battery voltage greater than max voltage
* 10/30/2021 v1.8 - Added check for the last time the low battery notification was sent
* 10/26/2021 v1.7 - Added call to sendBatteryLowNotification() if batteryStatus is 1 (low)
* 09/24/2021 v1.6 - Fixed error in battery level calculation
* - Added plug-in power supply preference
* 07/28/2021 v1.5 - Added capabilities override preference
* 07/13/2021 v1.4 - Fixed an issue with maxVoltage set to null on driver upgrade
* - Added logsOff() to updated() to automatically disable logging
* 06/30/2021 v1.3 - Fixed Hubitat Dashboard tile colors update when open/closed/partially open
* 04/25/2021 v1.2 - Refactored sendEvent() for battery and shade levels
* 03/28/2021 v1.1 - Added firmware version and shade type to the Data section of Device Details
* - Changed battery percentage calculation based on information from Hunter Douglas engineers
* - Added "position" event for WindowShade capability
* - Modified code to use the "capabilities" value of shade and added logic to handle various shade types properly
* 05/10/2020 v1.0 - Initial release
*
*/
metadata {
definition(name: "Hunter Douglas PowerView Shade", namespace: "hdpowerview", author: "Chris Lang", importUrl: "https://raw.githubusercontent.com/bujvary/hubitat/master/drivers/hunter-douglas-powerview-shade.groovy") {
capability "Initialize"
capability "Actuator"
capability "Battery"
capability "Refresh"
capability "Sensor"
capability "WindowShade"
capability "Switch"
capability "SwitchLevel"
command "calibrate"
command "jog"
command "stop"
command "presetPosition"
command "setBottomPosition", ["number"]
command "setTopPosition", ["number"]
command "setTiltPosition", ["number"]
command "tiltOpen"
command "tiltClose"
command "tiltClockwise"
command "tiltCounterClockwise"
attribute "bottomPosition", "number"
attribute "topPosition", "number"
attribute "tiltPosition", "number"
attribute "refreshTimedOut", "enum", ["true", "false"]
}
preferences {
input name: 'capabilityOverride', type: 'enum', title: '<b>Shade Capability Override</b>', description: '<div><i>Only set this if your shade capabilities value is -1. Use the table above to select the correct shade capability.</i></div><br>', displayDuringSetup: false, required: false, options: [
0: "Bottom Up",
1: "Bottom Up Tilt 90°",
2: "Bottom Up Tilt 180°",
3: "Vertical",
4: "Vertical Tilt 180°",
5: "Tilt Only 180°",
6: "Top Down",
7: "Top Down/Bottom Up",
8: "Duolite Lift",
9: "Duolite Lift and Tilt 90°",
10: "Duolite Lift and Tilt 180°"
]
if (getShadeCapabilities() == 7) {
input name: 'railForLevelState', type: 'enum', title: '<b>Top Down/Bottom Up Rail for Level State</b>', description: '<div><i>Select rail that will determine the value of the level state</i></div><br>', displayDuringSetup: false, defaultValue: '0', required: false, options: [
0: "Bottom Rail",
1: "Top Rail",
]
}
input name: 'preset', type: 'number', title: '<b>Preset Position</b>', description: '<div><i>Set the window shade preset position (defaults to 50)</i></div><br>', displayDuringSetup: false, defaultValue: 50, range: "0..100"
input name: 'pluggedIn', type: 'bool', title: '<b>Plug-in power supply?</b>', description: '<div><i>Automatically sets battery level to 100% if enabled</i></div><br>', displayDuringSetup: false, defaultValue: false
input name: 'maxVoltage', type: 'decimal', title: '<b>Maximum Voltage</b>', description: '<div><i>Maximum voltage of battery wand</i></div><br>', displayDuringSetup: false, defaultValue: '18.5', range: "1..50", required: true
input name: "closedPosition", type: "number", title: '<b>Closed position</b>', description: '<div><i>Set the position for fully closed window shade</i></div><br>', defaultValue: 0, range: "0..100", required: false, displayDuringSetup: false
input name: "openPosition", type: "number", title: '<b>Open position</b>', description: '<div><i>Set the position for fully open window shade</i></div><br>', defaultValue: 100, range: "0..100", required: false, displayDuringSetup: false
input name: 'logEnable', type: 'bool', title: '<b>Enable Logging?</b>', description: '<div><i>Automatically disables after 15 minutes</i></div><br>', displayDuringSetup: false, defaultValue: true
}
}
def installed() {
if (state."Shade capability information from Hunter Douglas" != null)
state.remove("Shade capability information from Hunter Douglas")
if (state.capabilities == -1)
state.remove(state.capabilities)
initialize()
}
def initialize() {
if (logEnable) runIn(900, logsOff)
if (settings?.maxVoltage==null) setting?.maxVoltage=18
if (settings?.closedPosition==null) settings?.closedPosition=0
if (settings?.openPosition==null) settings?.openPosition=100
//state.remove("Shade capability information from Hunter Douglas")
if (!state."Shade capability information from Hunter Douglas") {
state."Shade capability information from Hunter Douglas" = '''
<style type="text/css">
.tg {border-collapse:collapse;border-color:#ccc;border-spacing:0;font-weight:normal;}
.tg td{background-color:#fff;border-color:#ccc;border-style:solid;border-width:1px;color:#333;
font-family:Helvetica,Arial,sans-serif;font-size:14px;overflow:hidden;padding:4px 6px;word-break:normal;}
.tg th{background-color:#f0f0f0;border-color:#ccc;border-style:solid;border-width:1px;color:#333;
font-family:Helvetica,Arial,sans-serif;font-size:14px;overflow:hidden;padding:4px 6px;word-break:normal;}
.tg .tg-1wig{font-weight:bold;text-align:left;vertical-align:top;}
.tg .tg-baqh{text-align:center;vertical-align:top;width:110px;}
.tg .tg-02ax{text-align:left;vertical-align:top;width:145px;}
.tg .tg-01ax{text-align:left;vertical-align:top;}
</style>
<table class="tg">
<thead>
<tr>
<th class="tg-1wig">Capability Value</th>
<th class="tg-1wig">Shade Type</th>
<th class="tg-1wig">Shade Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tg-baqh">0</td>
<td class="tg-02ax">Bottom Up</td>
<td class="tg-0lax">Shades with standard bottom-up operation such as Alustra Woven Textures, Roller, Screen & Banded Shades, Duette/Applause Standard, Design Studio shades, Solera, Vignette Modern Roman Shades Provenance Woven Wood Shades.</td>
</tr>
<tr>
<td class="tg-baqh">1</td>
<td class="tg-02ax">Bottom Up Tilt 90°</td>
<td class="tg-0lax">Shades with Bottom-Up lift and 90° Tilt. Includes Pirouette, Silhouette, Silhouette A Deux Front Shade.</td>
</tr>
<tr>
<td class="tg-baqh">2</td>
<td class="tg-02ax">Bottom Up Tilt 180°</td>
<td class="tg-0lax">Lift and Tilt Horizontal Blind (Not sold in USA at this time).</td>
</tr>
<tr>
<td class="tg-baqh">3</td>
<td class="tg-02ax">Vertical</td>
<td class="tg-0lax">Vertically oriented shades with horizontal traverse operation only. Include Skyline Left Stack, Right Stack, Split Stack; Provenance Vertical Drapery Left Stack, Right Stack, Split Stack; Duette/Applause Vertiglide Left Stack, Right Stack.</td>
</tr>
<tr>
<td class="tg-baqh">4</td>
<td class="tg-02ax">Vertical Tilt 180°</td>
<td class="tg-0lax">Vertically oriented shades with horizontal traverse operation plus 180° Tilt. Includes Luminette Left Stack, Right Stack and Split Stack.</td>
</tr>
<tr>
<td class="tg-baqh">5</td>
<td class="tg-02ax">Tilt Only 180°</td>
<td class="tg-0lax">Products with tilt-only operation such as Parkland, EverWood, Modern Precious Metals and Palm Beach Shutters</td>
</tr>
<tr>
<td class="tg-baqh">6</td>
<td class="tg-0lax">Top Down</td>
<td class="tg-0lax">Top-Down (only) operation includes Duette/Applause Top-Down.</td>
</tr>
<tr>
<td class="tg-baqh">7</td>
<td class="tg-02ax">Top Down/Bottom Up</td>
<td class="tg-0lax">Shades with Top-Down/Bottom-Up (TDBU) operation or stacking Duolite operation including Duette/Applause TDBU, Solera TDBU, Vignette TDBU, Provenance TDBU; Alustrao Woven Textureso Romans TDBU, Duette/Applause Duolite.</td>
</tr>
<tr>
<td class="tg-baqh">8</td>
<td class="tg-02ax">Duolite Lift</td>
<td class="tg-0lax">Shades with lift only Duolite operation eg. Vignette Duolite, Roller/Screen Duolite (not released).</td>
</tr>
<tr>
<td class="tg-baqh">9</td>
<td class="tg-02ax">Duolite Lift and Tilt 90°</td>
<td class="tg-0lax">Duolite lift operation plus 90° tilt operation. Includes: Silhouette Duolite.</td>
</tr>
<tr>
<td class="tg-baqh">10</td>
<td class="tg-02ax">Duolite Lift with Tilt 180°</td>
<td class="tg-0lax">Duolite lift operation plus 180° tilt operation. Includes Silhouette Halo Duolite.</br> • Uses the “primary,” “secondary,” and “tilt” control types</td>
</tr>
</tbody>
</table>
</br>
Note: If the shade capabilities value is -1 then you will need to set the Shade Capability Override value in the Preferences section.'''
}
}
def updated() {
if (logEnable) runIn(900, logsOff)
}
def refresh() {
parent?.pollShade(device)
}
public handleEvent(shadeJson) {
if (logEnable) log.debug "handleEvent: shadeJson = ${shadeJson}"
def now = now()
if(settings?.railForLevelState == null)
settings?.railForLevelState=0
if (shadeJson?.positions != null) {
def positions = shadeJson.positions
if (positions.posKind1) {
updatePosition(positions.position1, positions.posKind1)
}
if (positions.posKind2) {
updatePosition(positions.position2, positions.posKind2)
}
} else {
// If a result doesn't include position, sometimes reissuing the poll will return it.
if (!state?.lastPollRetry || (state?.lastPollRetry - now) > (60 * 10 * 1000)) {
if (logEnable) log.debug "event didn't contain position, retrying poll"
state?.lastPollRetry = now
refresh()
}
}
if (shadeJson?.batteryStrength != null) {
def batteryLevel = 100
def battVoltage = shadeJson.batteryStrength / 10
if (logEnable) log.debug "handleEvent: battVoltage = ${battVoltage}, maxVoltage = ${settings?.maxVoltage}"
if (!settings?.pluggedIn) {
if (battVoltage < settings?.maxVoltage.toFloat()) {
batteryLevel = (int)((battVoltage / settings?.maxVoltage.toFloat()) * 100)
}
}
state.batteryVoltage = battVoltage
descriptionText = "${device.displayName} battery is ${batteryLevel}%"
sendEvent([name: "battery", value: batteryLevel, unit: "%", descriptionText: descriptionText])
}
if (shadeJson?.timedOut != null) {
def timedOut = shadeJson?.timedOut ? "timed out" : "succeeded"
descriptionText = "${device.displayName} refresh ${timedOut}"
sendEvent([name: "refreshTimedOut", value: shadeJson?.timedOut, descriptionText: descriptionText])
}
state.batteryStatus = shadeJson?.batteryStatus; // 0 = No Status Available, 1 = Low, 2 = Medium, 3 = High, 4 = Plugged In
if (state.batteryStatus == 1 && (!state?.lastBatteryLowNotify || (now - state?.lastBatteryLowNotify) > (24 * 60 * 60 * 1000))) {
state?.lastBatteryLowNotify = now
parent.sendBatteryLowNotification(device)
}
if (shadeJson?.capabilities != null) {
state.capabilities = shadeJson.capabilities;
}
else {
if (state.capabilities == null) {
state.capabilities = shadeTypeToCapability(shadeJson.type)
}
}
if (shadeJson?.firmware != null)
device.updateDataValue("firmwareVersion", "${shadeJson.firmware.revision}.${shadeJson.firmware.subRevision}.${shadeJson.firmware.build}")
device.updateDataValue("shadeTypeID", "${shadeJson.type}")
}
def updatePosition(position, posKind) {
def sendLevelEvents = true
def eventName
def level
if (getShadeCapabilities() == 7) {
if (logEnable) log.debug "posKind = ${posKind}, railForLevelState = ${settings?.railForLevelState}"
if (posKind == 1 && settings?.railForLevelState.toInteger() == 0) { // bottom rail
if (logEnable) log.debug "Setting level to bottom rail position"
level = Math.round(position * 100 / 65535)
}
else if (posKind == 2 && settings?.railForLevelState.toInteger() == 1) { // top rail
if (logEnable) log.debug "Setting level to top rail position"
level = Math.round(position * 100 / 65535)
}
else {
level = Math.round(position * 100 / 65535)
sendLevelEvents = false
}
}
else if (posKind == 3) {
max = supportsTilt180() ? 65535 : 32767
level = Math.round(position * 100 / max)
}
else {
level = Math.round(position * 100 / 65535)
}
switch (posKind) {
case 1:
eventName = "bottomPosition"
break
case 2:
eventName = "topPosition"
break
case 3:
eventName = "tiltPosition"
break
default:
throw new Exception("Unknown posKind \"${posKind}\"")
}
if (level != 0 && level < settings?.closedPosition) {
if (logEnable) log.debug "Forcing level to 0"
level = 0
}
if (level != 100 && level > settings?.openPosition) {
if (logEnable) log.debug "Forcing level to 100"
level = 100
}
if (logEnable) log.debug "sending event ${eventName} with value ${level}"
sendEvent(name: eventName, value: level)
if (sendLevelEvents) {
sendEvent(name: "level", value: level)
sendEvent(name: "position", value: level)
}
runIn(1, updateWindowShadeState)
}
def updateWindowShadeState() {
if (logEnable) log.debug "updateWindowShadeState()"
level = device.currentValue('level', true)
if (isOpen(level)) {
sendEvent(name: "windowShade", value: "open", displayed:true)
sendEvent(name: "switch", value: "on")
}
else if (isClosed(level)) {
sendEvent(name: "windowShade", value: "closed", displayed:true)
sendEvent(name: "switch", value: "off")
}
else {
sendEvent(name: "windowShade", value: "partially open", displayed:true)
sendEvent(name: "switch", value: "on")
}
}
// parse events into attributes
def parse(String description) {}
// handle commands
def open() {
if (logEnable) log.debug "open()"
def shadeCapabilities = getShadeCapabilities()
switch (shadeCapabilities) {
case 0: // Bottom Up
case 1: // Bottom Up Tilt 90
case 2: // Bottom Up Tilt 180
case 3: // Vertical
case 4: // Vertical Tilt 180
case 8: // Duolite Lift
case 9: // Duolite Lift and Tilt 90
case 10: // Duolite Lift and Tilt 180
parent.setPosition(device, [bottomPosition: 100])
break
case 5: // Tilt Only 180
log.info "open() shade supports tilt only"
break
case 6: // Top Down
parent.setPosition(device, [bottomPosition: 0])
break
case 7: // Top Down Bottom Up
parent.setPosition(device, [bottomPosition: 100, topPosition: 0])
break
default:
throw new Exception("Unknown shade capability \"${shadeCapabilities}\"")
}
}
def close() {
if (logEnable) log.debug "close()"
def shadeCapabilities = getShadeCapabilities()
switch (shadeCapabilities) {
case 0: // Botton Up
case 1: // Bottom Up Tilt 90
case 2: // Bottom Up Tilt 180
case 3: // Vertical
case 4: // Vertical Tilt 180
case 8: // Duolite Lift
case 9: // Duolite Lift and Tilt 90
case 10: // Duolite Lift and Tilt 180
parent.setPosition(device, [bottomPosition: 0])
break
case 5: // Tilt Only 180
log.info "close() shade supports tilt only"
break
case 6: // Top Down
parent.setPosition(device, [bottomPosition: 100])
break
case 7: // Top Down Bottom Up
parent.setPosition(device, [bottomPosition: 0, topPosition: 0])
break
default:
throw new Exception("Unknown shade capability \"${shadeCapabilities}\"")
}
}
def tiltOpen() {
if (logEnable) log.debug "tiltOpen()"
if (supportsTilt()) {
if(supportsTilt180())
parent.setPosition(device, [tiltPosition: 50])
else
parent.setPosition(device, [tiltPosition: 100])
}
}
def tiltClose() {
if (logEnable) log.debug "tiltClose()"
if (supportsTilt()) {
parent.setPosition(device, [tiltPosition: 0])
}
}
def tiltClockwise() {
if (logEnable) log.debug "tiltClockwise()"
if (supportsTilt()) {
parent.setPosition(device, [tiltPosition: 100])
}
}
def tiltCounterClockwise() {
if (logEnable) log.debug "tiltCounterClockwise()"
tiltClose()
}
def presetPosition() {
setLevel(settings?.preset ?: 50)
}
def calibrate() {
parent.calibrateShade(device)
}
def jog() {
parent.jogShade(device)
}
def stop() {
parent.stopShade(device)
}
def setBottomPosition(bottomPosition) {
bottomPosition = Math.min(Math.max(bottomPosition.intValue(), 0), 100)
parent.setPosition(device, [bottomPosition: bottomPosition])
}
def setTopPosition(topPosition) {
topPosition = Math.min(Math.max(topPosition.intValue(), 0), 100)
parent.setPosition(device, [topPosition: topPosition])
}
def setPosition(position) {
setLevel(position)
}
def setTiltPosition(tiltPosition) {
if (supportsTilt()) {
tiltPosition = Math.min(Math.max(tiltPosition.intValue(), 0), 100)
parent.setPosition(device, [tiltPosition: tiltPosition])
}
}
def setLevel(position, duration = null) {
def positions = []
position = Math.min(Math.max(position.intValue(), 0), 100)
if (getShadeCapabilities() == 7 && device.currentValue('topPosition', true) != 0) {
// The top rail is not closed but the bottom was told to move. In nearly all
// cases, this should mean the top closes.
positions = [topPosition: 0, bottomPosition: position]
} else {
positions = [position: position]
}
parent.setPosition(device, positions)
}
def startPositionChange(direction) {
if (logEnable) log.debug "startPositionChange(): ${direction}"
switch (direction) {
case "close":
close()
break
case "open":
open()
break
default:
throw new Exception("Unsupported startPositionChange direction \"${direction}\"")
break
}
}
def stopPositionChange() {
if (logEnable) log.debug "stopPositionChange()"
stop()
}
def supportsTilt180() {
if (logEnable) log.debug "supportsTilt180()"
def shadeCapabilities = getShadeCapabilities()
def result = false
switch (shadeCapabilities) {
case 1: // Bottom Up Tilt 90
case 9: // Duolite Lift and Tilt 90
result = false
break
case 2: // Bottom Up Tilt 180
case 4: // Vertical Tilt 180
case 5: // Tilt Only 180
case 10: // Duolite Lift and Tilt 180
result = true
break
default:
throw new Exception("Shade does not support tilt capability (shade capability = ${shadeCapabilities})")
break
}
return result
}
def supportsTilt() {
if (logEnable) log.debug "supportsTilt()"
def shadeCapabilities = getShadeCapabilities()
def result = false
switch (shadeCapabilities) {
case 1: // Bottom Up Tilt 90
case 2: // Bottom Up Tilt 180
case 4: // Vertical Tilt 180
case 5: // Tilt Only 180
case 9: // Duolite Lift and Tilt 90
case 10: // Duolite Lift and Tilt 180
result = true
break
default:
throw new Exception("Shade does not support tilt capability (shade capability = ${shadeCapabilities})")
break
}
return result
}
def getShadeCapabilities() {
return (capabilityOverride == null) ? state?.capabilities : capabilityOverride.toInteger()
}
def isClosed(level) {
if (logEnable) log.debug "isClosed()"
def result
def shadeCapabilities = getShadeCapabilities()
if (shadeCapabilities == 6) {
if (logEnable) log.debug "Checking Top-Down shade closed state"
result = (level >= 99) ? true : false
}
else if (shadeCapabilities == 7) {
if (logEnable) log.debug "Checking TB/BU shade closed state"
result = (device.currentValue('bottomPosition', true) == 0 && device.currentValue('topPosition', true) == 0) ? true : false
}
else {
if (logEnable) log.debug "Checking shade closed state"
result = (level <= 1) ? true : false
}
if (logEnable) log.debug "isClosed() = ${result}"
return result
}
def isOpen(level) {
if (logEnable) log.debug "isOpen()"
def result
def shadeCapabilities = getShadeCapabilities()
if (shadeCapabilities == 6) {
if (logEnable) log.debug "Checking Top-Down shade open state"
result = (level <= 1) ? true : false
}
else if (shadeCapabilities == 7) {
if (logEnable) log.debug "Checking TB/BU shade open state"
result = (device.currentValue('bottomPosition', true) == 100 && device.currentValue('topPosition', true) == 0) ? true : false
}
else {
if (logEnable) log.debug "Checking shade open state"
result = (level >= 99) ? true : false
}
if (logEnable) log.debug "isOpen() = ${result}"
return result
}
def shadeTypeToCapability(shadeType) {
if (logEnable) log.debug "shadeTypeToCapability()"
def capability = -1
switch (shadeType) {
case 1:
case 4:
case 5:
case 6:
case 31:
case 42:
case 49:
capability = 0
break
case 18:
case 23:
case 43:
case 44:
capability = 1
break
case 51:
case 62:
capability = 2
break
case 69:
case 70:
case 71:
capability = 3
break
case 54:
case 55:
case 56:
capability = 4
break
case 66:
capability = 5
break
case 7:
capability = 6
break
case 8:
case 9:
case 33:
case 47:
capability = 7
break
case 65:
case 79:
capability = 8
break
case 38:
capability = 9
break
default:
log.error("Unknown shade type ${shadeType})")
break
}
if (logEnable) log.debug "shadeTypeToCapability() = ${capability}"
return capability
}
def logsOff() {
log.warn "Debug logging disabled."
device.updateSetting("logEnable", [value: "false", type: "bool"])
}