-
Notifications
You must be signed in to change notification settings - Fork 4
/
Tuya-Wall-Thermostat.groovy
2452 lines (2321 loc) · 126 KB
/
Tuya-Wall-Thermostat.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
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* groovylint-disable DuplicateListLiteral, LineLength, MethodCount, NestedBlockDepth, PublicMethodsBeforeNonPublicMethods, SpaceAfterClosingBrace, UnnecessaryGetter, UnusedPrivateMethod */
/**
* Tuya Wall Thermostat driver for Hubitat Elevation
*
* https://community.hubitat.com/t/release-tuya-wall-mount-thermostat-water-electric-floor-heating-zigbee-driver/87050
*
* 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.
*
* Credits: Jaewon Park, iquix and many others
*
* ver. 1.0.0 2022-01-09 kkossev - Inital version
* ver. 1.0.1 2022-01-09 kkossev - modelGroupPreference working OK
* ver. 1.0.2 2022-01-09 kkossev - MOES group heatingSetpoint and setpointReceiveCheck() bug fixes
* ver. 1.0.3 2022-01-10 kkossev - resending heatingSetpoint max 3 retries; heatSetpoint rounding up/down; incorrect temperature reading check; min and max values for heatingSetpoint
* ver. 1.0.4 2022-01-11 kkossev - reads temp. calibration for AVATTO, patch: temperatures > 50 are divided by 10!; AVATO parameters decoding; added BEOK model
* ver. 1.0.5 2022-01-15 kkossev - 2E+1 bug fixed; added rxCounter, txCounter, duplicateCounter; ChildLock control; if boost (emergency) mode was on, then auto() heat() off() commands cancel it;
* BRT-100 thermostatOperatingState changes on valve report; AVATTO/MOES switching from off mode to auto/heat modes fix; command 'controlMode' is now removed.
* ver. 1.0.6 2022-01-16 kkossev - debug/trace commands fixes
* ver. 1.0.7 2022-03-21 kkossev - added childLock attribute and events; checkDriverVersion(); removed 'Switch' capability and events; enabled 'auto' mode for all thermostat types.
* ver. 1.0.8 2022-04-03 kkossev - added tempCalibration; hysteresis; minTemp and maxTemp for AVATTO and BRT-100; added Battery capability for BRT-100
* ver. 1.2.1 2022-04-05 kkossev - BRT-100 basic cluster warning supressed; tempCalibration, maxTemp, minTemp fixes; added Battery capability; 'Changed from device Web UI' desctiption in off() and heat() events.
* ver. 1.2.2 2022-09-04 kkossev - AVATTO additional DP logging; removed Calibration command (now is as Preference parameter); replaced Initialize capability w/ custom command; degrees symbol in temp. unit;
* Refresh command wakes up the display'; Google Home compatibility
* ver. 1.2.3 2022-09-05 kkossev - added FactoryReset command (experimental, change Boolean debug = true); added AVATTO programMode preference;
* ver. 1.2.4 2022-09-28 kkossev - _TZE200_2ekuz3dz fingerprint corrected
* ver. 1.2.5 2022-10-08 kkossev - BEOK: added sound on/off, tempCalibration, hysteresis, tempCeiling, setBrightness, 0.5 degrees heatingSetpoint (BEOK only); bug fixes for BEOK: Child lock, thermostatMode, operatingState
* ver. 1.2.6 2022-10-16 kkossev - BEOK: time sync workaround; BEOK: temperature scientific representation bug fix; parameters number/decimal fixes; brightness and maxTemp bug fixes; heatingTemp is always rounded to 0.5; cool() does not switch the thermostat off anymore
* ver. 1.2.7 2022-11-05 kkossev - BEOK: added frostProtection; BRT-100: tempCalibration bug fix; reversed heat and auto modes for MOES dp=3; hysteresis is hidden for BRT-100; maxTemp lower limit set to 15; dp3 is ignored from MOES/BSEED if in off mode
* supressed dp=9 BRT-100 unknown function warning;
* ver. 1.2.8 2022-11-27 kkossev - added 'brightness' attribute; removed MODEL3; dp=3 refactored; presence function bug fix; added resetStats command; refactored stats; faster sending of Zigbee commands; time is synced every hour for BEOK;
* modeReceiveCheck() and setpointReceiveCheck() refactored;
* ver. 1.2.9 2022-12-05 kkossev - bugfix: 'supportedThermostatFanModes' and 'supportedThermostatModes' proper JSON formatting; homeKitCompatibility option
* ver. 1.2.10 2023-01-08 kkossev - bugfix: AVATTO thermostat can not be switched off from HE dashboard;
* ver. 1.2.11 2023-01-14 kkossev - bugfix: BEOK setBrightness retry
* ver. 1.3.0 2023-06-03 kkossev - added sensorSelection; replaced Presence w/ Health Status; added ping() and rtt; added '--- Select ---' default value for the sensorSelection command; added sensorSelection as attribute
* ver. 1.3.1 2023-10-29 kkossev - added 'HY369' group (TS0601 _TZE200_ckud7u2l); add state.deviceProfile
* ver. 1.3.2 2023-11-16 kkossev - added TS0601 _TZE200_bvrlmajk Avatto TRV07 ; added Immax Neo Lite TRV 07732L TS0601 _TZE200_rufdtfyv as HY367;
* ver. 1.3.3 2023-11-16 vnistor - added modes, valve, childLock, windowOpen, windowOpenDetection, thermostatOperatingState to TS0601 _TZE200_bvrlmajk Avatto TRV07
* ver. 1.3.4 2023-11-16 kkossev - merged versions 1.3.2 and 1.3.3;
* ver. 1.3.5 2023-11-23 vnistor - added childLock status, valve status, battery warning, thermostatMode, setHeatingSetpoint, Valve capability, Preferences: tempCalibration, minTemp, maxTemp to HY367;
* ver. 1.3.6 2023-11-24 kkossev - The newly added events are declared as custom attributes;
* ver. 1.3.7 2023-12-05 kkossev - setting the hysteresis bug fix for AVATTO.
* ver. 1.3.8 2023-12-08 kkossev - thermostatOperatingState bug fix for BRT-100.
* ver. 1.4.0 2024-02-28 kkossev - Groovy lint
* ver. 1.4.1 2024-10-26 kkossev - commented out the fingerprints for _TZE200_b6wax7g0 _TZE200_ckud7u2l _TZE200_bvrlmajk _TZE200_rufdtfyv - they are now supported in the new 'Tuya Zigbee TRVs and Thermostats' driver
*
* TODO: update the community thread top post
*/
def version() { '1.4.1' }
def timeStamp() { '2024/10/26 11:45 AM' }
import groovy.json.*
import groovy.transform.Field
import hubitat.zigbee.zcl.DataType
import hubitat.device.HubAction
import hubitat.device.Protocol
import java.text.DecimalFormat
import groovy.time.TimeCategory
import groovy.transform.CompileStatic
import java.util.concurrent.ConcurrentHashMap
@Field static final Boolean _DEBUG = false
metadata {
definition (name: 'Tuya Wall Thermostat', namespace: 'kkossev', author: 'Krassimir Kossev', importUrl: 'https://raw.githubusercontent.com/kkossev/Hubitat-Tuya-Wall-Thermostat/development/Tuya-Wall-Thermostat.groovy', singleThreaded: true ) {
capability 'Actuator'
capability 'Refresh'
capability 'Sensor'
capability 'Temperature Measurement'
capability 'Thermostat'
capability 'ThermostatHeatingSetpoint'
capability 'ThermostatCoolingSetpoint'
capability 'ThermostatOperatingState'
capability 'ThermostatSetpoint'
capability 'ThermostatMode'
capability 'Battery'
capability 'HealthCheck'
attribute 'childLock', 'enum', ['off', 'on']
attribute 'windowOpenDetection', 'enum', ['off', 'on']
attribute 'brightness', 'enum', ['off', 'low', 'medium', 'high']
attribute 'healthStatus', 'enum', ['offline', 'online', 'unknown']
attribute 'sensorSelection', 'enum', sensorOptions.values() as List<String>
attribute 'rtt', 'number'
attribute 'valve', 'number'
attribute 'windowOpen', 'enum', ['false', 'true']
attribute 'minHeatingSetpoint', 'number'
attribute 'maxHeatingSetpoint', 'number'
attribute 'holidayModeSetpoint', 'number'
if (_DEBUG == true) {
command 'zTest', [
[name:'dpCommand', type: 'STRING', description: 'Tuya DP Command', constraints: ['STRING']],
[name:'dpValue', type: 'STRING', description: 'Tuya DP value', constraints: ['STRING']],
[name:'dpType', type: 'ENUM', constraints: ['DP_TYPE_VALUE', 'DP_TYPE_BOOL', 'DP_TYPE_ENUM'], description: 'DP data type']
]
command 'test'
}
command 'initialize', [[name: 'Initialize the thermostat after switching drivers. \n\r ***** Will load device default values! *****' ]]
command 'childLock', [[name: 'ChildLock', type: 'ENUM', constraints: ['off', 'on'], description: 'Select Child Lock mode'] ]
command 'windowOpenDetection', [[name: 'windowOpenDetection', type: 'ENUM', constraints: ['off', 'on'], description: 'Select Window Open Detection mode'] ]
command 'setBrightness', [[name: 'setBrightness', type: 'ENUM', constraints: ['off', 'low', 'medium', 'high'], description: 'Set LCD brightness for BEOK thermostats'] ]
command 'sensorSelection', [[name: 'sensorSelection', type: 'ENUM', constraints: ['99':'--- Select ---'] + sensorOptions, description: 'Select the temperature sensor'] ]
command 'factoryReset', [[name:'factoryReset', type: 'STRING', description: "Type 'YES'", constraints: ['STRING']]]
command 'resetStats', [[name: 'Reset Statistics' ]]
// (AVATTO)
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_ye5jkfsb', deviceJoinName: 'AVATTO Wall Thermostat' // ME81AH
// (Moes)
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_aoclfnxz', deviceJoinName: 'Moes Wall Thermostat' // BHT-002
// (unknown)
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_unknown', deviceJoinName: '_TZE200_ Thermostat' // unknown
// (BEOK)
fingerprint profileId:'0104', endpointId:'01', inClusters:'0004,0005,EF00,0000', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_2ekuz3dz', deviceJoinName: 'Beok Wall Thermostat' // X5H-GB-B
/* The TRVs below are now supported in the new 'Tuya Zigbee TRVs and Thermostats' driver. Starting from version
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_b6wax7g0', deviceJoinName: 'BRT-100 TRV' // BRT-100
//fingerprint profileId:"0104", endpointId:"01", inClusters:"0000,0004,0005,EF00", outClusters:"0019,000A", model:"TS0601", manufacturer:"_TZE200_chyvmhay", deviceJoinName: "Lidl Silvercrest" // Lidl Silvercrest (dev tests only, never tested really)
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_ckud7u2l', deviceJoinName: 'Moes HY369 TRV' // added 10/29/2023
fingerprint profileId:'0104', endpointId:'01', inClusters:'0004,0005,EF00,0000', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_bvrlmajk', deviceJoinName: 'AVATTO TRV07' // added 11/14/2023 // https://community.hubitat.com/t/release-tuya-wall-mount-thermostat-water-electric-floor-heating-zigbee-driver/87050/215?u=kkossev
fingerprint profileId:'0104', endpointId:'01', inClusters:'0000,0004,0005,EF00', outClusters:'0019,000A', model:'TS0601', manufacturer:'_TZE200_rufdtfyv', deviceJoinName: 'Immax Neo Lite TRV 07732L' // HY367 added 11/16/2023
*/
}
preferences {
if (logEnable == true || logEnable == false) {
input (name: 'logEnable', type: 'bool', title: '<b>Debug logging</b>', description: '<i>Debug information, useful for troubleshooting. Recommended value is <b>false</b></i>', defaultValue: false)
input (name: 'txtEnable', type: 'bool', title: '<b>Description text logging</b>', description: '<i>Display measured values in HE log page. Recommended value is <b>true</b></i>', defaultValue: true)
input (name: 'forceManual', type: 'bool', title: '<b>Force Manual Mode</b>', description: '<i>If the thermostat changes into schedule mode, then it automatically reverts back to manual mode</i>', defaultValue: false)
input (name: 'resendFailed', type: 'bool', title: '<b>Resend failed commands</b>', description: '<i>If the thermostat does not change the Setpoint or Mode as expected, then commands will be resent automatically</i>', defaultValue: false)
input (name: 'minTemp', type: 'number', title: '<b>Minimum Temperature</b>', description: '<i>The Minimum temperature setpoint that can be sent to the device</i>', defaultValue: 5, range: '0..60')
input (name: 'maxTemp', type: 'number', title: '<b>Maximum Temperature</b>', description: '<i>The Maximum temperature setpoint that can be sent to the device</i>', defaultValue: 35, range: '15..95')
input (name: 'modelGroupPreference', title: "Select a model group. Recommended value is <b>'Auto detect'</b>", /*description: "<i>Thermostat type</i>",*/ type: 'enum', options:['Auto detect':'Auto detect', 'AVATTO':'AVATTO', 'MOES':'MOES', 'BEOK':'BEOK', 'BRT-100':'BRT-100', 'HY367':'HY367', 'HY369':'HY369', 'TRV07':'TRV07'], defaultValue: 'Auto detect', required: false)
input (name: 'tempCalibration', type: 'decimal', title: '<b>Temperature Calibration</b>', description: '<i>Adjust measured temperature range: -9..9 C</i>', defaultValue: 0.0, range: '-9.0..9.0')
if ((getModelGroup() in ['AVATTO', 'BEOK'])) {
input (name: 'hysteresis', type: 'decimal', title: '<b>Hysteresis</b>', description: '<i>Adjust switching differential range: 0.5 .. 5.0 C</i>', defaultValue: 1.0, range: '0.5..5.0') // not available for BRT-100 !
}
if (isBEOK()) {
input (name: 'tempCeiling', type: 'number', title: '<b>Temperature Ceiling</b>', description: '<i>temperature limit parameter (unknown functionality) ></i>', defaultValue: 35, range: '35..95') // step is 5 deg. for BEOK'; default 35?
input (name: 'brightness', type: 'enum', title: '<b>LCD brightness</b>', description:'<i>LCD brightness control</i>', defaultValue: '3', options: brightnessOptions)
}
if (getModelGroup() in ['AVATTO']) {
input (name: 'programMode', type: 'enum', title: '<b>Program Mode</b> (thermostat internal schedule)', description: "<i>Recommended selection is '<b>off</b>'</i>", defaultValue: 0, options: [0:'off', 1:'Mon-Fri', 2:'Mon-Sat', 3: 'Mon-Sun'])
}
if (isBEOK()) {
input (name: 'frostProtection', type: 'bool', title: '<b>Disable/Enable frost protection</b>', description: '<i>Disable/Enable frost protection</i>', defaultValue: true)
input (name: 'sound', type: 'bool', title: '<b>Disable/Enable sound</b>', description: '<i>Disable/Enable sound</i>', defaultValue: true)
}
input (name: 'homeKitCompatibility', type: 'bool', title: '<b>HomeKit Compatibility</b>', description: 'Enable/disable HomeKit Compatibility', defaultValue: false)
}
}
}
@Field static final Map<String, String> Models = [
'_TZE200_ye5jkfsb' : 'AVATTO', // Tuya AVATTO ME81AH
'_TZE200_aoclfnxz' : 'MOES', // Tuya Moes BHT series Thermostat BTH-002 (also BSEED)
'_TZE200_2ekuz3dz' : 'BEOK', // Beok thermostat
'_TZE200_b6wax7g0' : 'BRT-100', // TRV BRT-100; MOES, ZONNSMART
'_TYST11_ckud7u2l' : 'HY369', // Moes HY369 // https://github.com/jacekk015/zha_quirks/blob/main/ts0601_trv_moes.py#L38
'_TZE200_ckud7u2l' : 'HY369', // KKmoon Tuya; temp /10.0
// vendor: Hysen model: HY369-ZB /
// https://www.aliexpress.com/item/4000742201198.html
// https://github.com/zigbeefordomoticz/wiki/blob/38206248debb348e40e3718d07b4e0ec5baa454c/en-eng/Technical/Tuya-0xEF00.md?plain=1#L102
'_TZE200_ywdxldoj' : 'HY369', //
'_TZE200_cwnjrr72' : 'HY369', //
'_TZE200_pvvbommb' : 'HY369', //
'_TZE200_2atgpdho' : 'HY369', // added 10/30/2023
'_TZE200_rufdtfyv' : 'HY367', // added 11/16/2023 https://community.hubitat.com/t/release-tuya-wall-mount-thermostat-water-electric-floor-heating-zigbee-driver/87050/232?u=kkossev
'_TZE200_bvrlmajk' : 'TRV07', // added 11/14/2023 // https://github.com/OzGav/zigbee-herdsman-converters/blob/d2e4e8ed359163ea8553fcae1cf2fa945b0f4c62/devices/tuya.js#L2194
'_TZE200_zion52ef' : 'TEST3', // TRV MOES => fn = "0001 > off: dp = "0204" data = "02" // off; heat: dp = "0204" data = "01" // on; auto: n/a !; setHeatingSetpoint(preciseDegrees): fn = "00" SP = preciseDegrees *10; dp = "1002"
'_TZE200_c88teujp' : 'TEST3', // TRV "SEA-TR", "Saswell", model "SEA801" (to be tested)
'_TZE200_xxxxxxxx' : 'UNKNOWN',
'' : 'UNKNOWN' //
]
def isBEOK() { return device.getDataValue('manufacturer') in ['_TZE200_2ekuz3dz'] }
def isMOES() { return device.getDataValue('manufacturer') in ['_TZE200_aoclfnxz'] }
def isBSEED() { return isMOES() }
def isTRV07() { return device.getDataValue('manufacturer') in ['_TZE200_bvrlmajk'] }
def isHY367() { return device.getDataValue('manufacturer') in ['_TZE200_rufdtfyv'] }
@Field static final Map brightnessOptions = [
'0' : 'off',
'1' : 'low',
'2' : 'medium',
'3' : 'high'
]
@Field static final Map faultOptions = [
'0' : 'none',
'1' : 'e1',
'2' : 'e2',
'3' : 'e3'
]
@Field static final Map sensorOptions = [ // BEOK - only in and out; AVATTO + both
'0' : 'in',
'1' : 'out',
'2' : 'both'
]
@Field static final Map programModeOptions = [
'0' : 'off',
'1' : 'Mon-Fri',
'2' : 'Mon-Sat',
'3' : 'Mon-Sun'
]
@Field static final Integer presenceCountTreshold = 3
@Field static final Integer defaultPollingInterval = 3600
@Field static final Integer MAX_PING_MILISECONDS = 10000 // rtt more than 10 seconds will be ignored
@Field static final Integer COMMAND_TIMEOUT = 10 // timeout time in seconds
@Field static final Integer MaxRetries = 5
@Field static final Integer NOT_SET = -1
private getCLUSTER_TUYA() { 0xEF00 }
private getSETDATA() { 0x00 }
private getSETTIME() { 0x24 }
// Tuya Commands
private getTUYA_REQUEST() { 0x00 }
private getTUYA_REPORTING() { 0x01 }
private getTUYA_QUERY() { 0x02 }
private getTUYA_STATUS_SEARCH() { 0x06 }
private getTUYA_TIME_SYNCHRONISATION() { 0x24 }
// tuya DP type
private getDP_TYPE_RAW() { '01' } // [ bytes ]
private getDP_TYPE_BOOL() { '01' } // [ 0/1 ]
private getDP_TYPE_VALUE() { '02' } // [ 4 byte value ]
private getDP_TYPE_STRING() { '03' } // [ N byte string ]
private getDP_TYPE_ENUM() { '04' } // [ 0-255 ]
private getDP_TYPE_BITMAP() { '05' } // [ 1,2,4 bytes ] as bits
// Parse incoming device messages to generate events
def parse(String description) {
checkDriverVersion()
unschedule('deviceCommandTimeout')
incRxCtr()
setHealthStatusOnline() // was setPresent()
//if (settings?.logEnable) log.debug "${device.displayName} parse() descMap = ${zigbee.parseDescriptionAsMap(description)}"
if (description?.startsWith('catchall:') || description?.startsWith('read attr -')) {
Map descMap = zigbee.parseDescriptionAsMap(description)
if (descMap?.clusterInt == zigbee.BASIC_CLUSTER && descMap.attrInt == 0x01) {
logDebug "Tuya check-in message (attribute ${descMap.attrId} reported: ${descMap.value})"
def now = new Date().getTime()
Map lastTxMap = stringToJsonMap( state.lastTx )
def timeRunning = now.toInteger() - (lastTxMap.pingTime ?: '0').toInteger()
if (timeRunning < MAX_PING_MILISECONDS) {
sendRttEvent()
}
}
else if (descMap?.clusterInt == CLUSTER_TUYA && descMap?.command == '24') { //getSETTIME
logDebug "time synchronization request from device, descMap = ${descMap}"
syncTuyaDateTime()
}
else if (descMap?.clusterInt == CLUSTER_TUYA && descMap?.command == '0B') { // ZCL Command Default Response
String clusterCmd = descMap?.data[0]
def status = descMap?.data[1]
if (settings?.logEnable) { log.debug "${device.displayName} device has received Tuya cluster ZCL command 0x${clusterCmd} response 0x${status} data = ${descMap?.data}" }
setLastRx( NOT_SET, NOT_SET) // -1
if (status != '00') {
if (settings?.logEnable) { log.warn "${device.displayName} ATTENTION! manufacturer = ${device.getDataValue('manufacturer')} group = ${getModelGroup()} unsupported Tuya cluster ZCL command 0x${clusterCmd} response 0x${status} data = ${descMap?.data} !!!" }
}
}
else if ((descMap?.clusterInt == CLUSTER_TUYA) && (descMap?.command == '01' || descMap?.command == '02')) {
def transid = zigbee.convertHexToInt(descMap?.data[1]) // "transid" is just a "counter", a response will have the same transid as the command
def dp = zigbee.convertHexToInt(descMap?.data[2]) // "dp" field describes the action/message of a command frame
def dp_id = zigbee.convertHexToInt(descMap?.data[3]) // "dp_identifier" is device dependant
def fncmd = getTuyaAttributeValue(descMap?.data) //
if (isDuplicated( dp, fncmd )) {
if (settings?.logEnable) { log.debug "(duplicate) transid=${transid} dp_id=${dp_id} <b>dp=${dp}</b> fncmd=${fncmd} command=${descMap?.command} data = ${descMap?.data}" }
//if ( state.duplicateCounter != null ) state.duplicateCounter = state.duplicateCounter +1
incDupeCtr()
return
}
else {
if (settings?.logEnable) { log.debug "${device.displayName} dp_id=${dp_id} <b>dp=${dp}</b> fncmd=${fncmd}" }
setLastRx( dp, fncmd)
}
// the switch cases below default to dp_id = "01"
switch (dp) {
case 0x01 : // (01) switch state : On / Off
switch (getModelGroup()) {
case 'AVATTO' : // all wall thermostats: AVATTO switch (boolean) // ; BEOK x5hState; MOES/BEOK
case 'MOES' :
case 'BEOK' :
def switchState = (fncmd == 0) ? 'off' : state.lastThermostatMode
sendEvent(name: 'thermostatMode', value: switchState)
if (switchState == 'off') {
logInfo 'switchState reported is: OFF'
sendEvent(name: 'thermostatOperatingState', value: 'idle')
}
else {
if (settings?.logEnable) { log.info "${device.displayName } switchState reported is: ON, restoring last lastThermostatMode ${state.lastThermostatMode} (dp=${dp}, fncmd=${fncmd})"}
sendEvent(name: 'thermostatOperatingState', value: state.lastThermostatOperatingState)
}
if (switchState == getLastMode()) {
logDebug "last sent mode ${getLastMode()} is confirmed from the device (dp=${dp}, fncmd=${fncmd})"
}
else {
logWarn "last sent mode ${getLastMode()} DIFFERS from the mode received from the device ${switchState} (dp=${dp}, fncmd=${fncmd})"
}
break
case 'BRT-100' : // 0x0401 # Mode (Received value 0:Manual / 1:Holiday / 2:Temporary Manual Mode / 3:Prog)
case 'TRV07' : //
logDebug "${device.displayName} mode is ${fncmd} (<b>dp=${dp}</b> fncmd=${fncmd})"
def thermostatModes = ['auto', 'heat', 'off', 'on'] // the themostatMode attribute value must be "heat" instead of "heating"
def thermostatMode = thermostatModes[fncmd]
sendEvent(name: 'thermostatMode', value: thermostatMode)
break
case 'TEST3' :
processBRT100Presets( dp, fncmd )
break
case 'HY367' : // dp1 not used
case 'HY369' : // dp1 not used
default :
if (settings?.logEnable) { log.warn "${device.displayName } Thermostat model group ${getModelGroup()} is not processed! (dp=${dp}, fncmd=${fncmd})"}
break
}
break
case 0x02 : // thermostatMode (AVATTO,BEOK, LIDL)
switch (getModelGroup()) {
case 'AVATTO' : // AVATTO : mode (enum) 'manual', 'program';
case 'BEOK' : // BEOK: x5hMode
logDebug "AVATTO/BEOK current thermostatMode was ${device.currentState('thermostatMode').value}"
/* was commented out 1/27/2022 - breaks switching off from HE dashboard! */
if (device.currentState('thermostatMode').value == 'off') {
logWarn 'ignoring 0x02 command in off mode'
sendEvent(name: 'thermostatOperatingState', value: 'idle')
break // ignore 0x02 command if thermostat was switched off !!
}
else { // previous thermosatMode was heat or auto
/**/
logDebug "previous thermosatMode was ${device.currentState('thermostatMode').value}..."
def thermostatMode = fncmd == 0 ? 'heat' : 'auto' // inverted!
if (thermostatMode == 'auto') {
if (settings?.forceManual == true) {
logDebug "'Force Manual Mode' preference option is enabled, switching back to heat mode!"
setManualMode()
}
}
if (settings?.logEnable) { log.info "${device.displayName} Thermostat mode reported is: <b>${thermostatMode}</b> (dp=${dp}, fncmd=${fncmd})" }
else if (settings?.txtEnable) { log.info "${device.displayName} Thermostat mode reported is: <b>${thermostatMode}</b>" }
sendEvent(name: 'thermostatMode', value: thermostatMode)
state.lastThermostatMode = thermostatMode
}
break
case 'MOES' : // MOES thermostatMode: 0-manual; 1:auto; 2:auto w/ temporary changed setpoint
def mode
if (fncmd != 0) {
mode = 'auto' // scheduled
if (settings?.forceManual == true) {
if (settings?.txtEnable) { log.warn "${device.displayName} 'Force Manual Mode' preference option is enabled, switching back to heat mode!" }
setManualMode()
}
}
else {
mode = 'heat' // manual
}
logDebug "BEOK/MOES (dp=2) thermostatMode = ${mode}"
if (settings?.logEnable) { log.info "${device.displayName } BEOK/MOES (dp=2) thermostatMode reported is: $mode (dp=${dp}, fncmd=${fncmd})"}
else if (settings?.txtEnable) { log.info "${device.displayName } BEOK/MOES (dp=2) thermostatMode reported is: ${mode}"}
sendEvent(name: 'thermostatMode', value: mode)
state.lastThermostatMode = mode
break // no more processing for BEOK!
case 'BRT-100' : // BRT-100 Thermostat heatsetpoint # 0x0202 #
case 'HY367' : // process incoming setPoint change
processTuyaHeatSetpointReport (fncmd)
break
case 'HY369' :
case 'TRV07' : // TODO - check TRV07 "Target temperature" !!!!!!!!!!!
case 'TEST3' :
processTuyaHeatSetpointReport( fncmd ) // target temp, in degrees (int!)
break
default :
if (settings?.logEnable) { log.warn "${device.displayName } Thermostat model group ${getModelGroup()} is not processed! (dp=${dp}, fncmd=${fncmd})"}
break
}
break
case 0x03 : // BEOK x5hWorkingStatus (thermostatOperatingState) !
logDebug "processing command dp=${dp} fncmd=${fncmd} (lastThermostatMode=${state.lastThermostatMode})" // TODO: See which models this is actually there for, and move it to said model only
switch (getModelGroup()) {
case 'AVATTO' :
case 'BEOK' :
def thermostatOperatingState = (fncmd == 1) ? 'heating' : 'idle'
sendThermostatOperatingStateEvent(thermostatOperatingState) // "thermostatOperatingState"
if (settings?.logEnable) { log.info "${device.displayName } Thermostat working status (thermostatOperatingState) reported is: ${thermostatOperatingState} (dp=${dp}, fncmd=${fncmd})"}
else if (settings?.txtEnable) { log.info "${device.displayName } Thermostat working status (thermostatOperatingState) reported is: ${thermostatOperatingState}"}
break
case 'MOES' :
if (settings?.logEnable) { log.warn "${device.displayName } IGNORING dp=${dp}, fncmd=${fncmd} command for BSEED/MOES while in <b>${device.currentValue('thermostatMode', true)}</b> thermostatMode!"}
break // shouldn't come here ... TODO!
case 'BRT-100' :
case 'TEST3' : // Thermostat current temperature
case 'TRV07' : // added 11/14/2023
case 'HY367' : // Thermostat Current temperature
logDebug "processTuyaTemperatureReport descMap?.size() = ${descMap?.data.size()} dp_id=${dp_id} <b>dp=${dp}</b> :"
processTuyaTemperatureReport( fncmd )
break
case 'HY369' :
// TODO !!
// # [0] away [1] scheduled [2] manual [3] comfort [4] eco [5] boost [6] complex
logDebug "HY369 mode (dp=${dp}, fncmd=${fncmd}) <b>not processed</b>!"
break
default :
if (settings?.logEnable) { log.warn "${device.displayName } Thermostat model group ${getModelGroup()} is not processed! (dp=${dp}, fncmd=${fncmd})"}
break
}
break
case 0x04 :
switch (getModelGroup()) {
case 'BRT-100' : // BRT-100 Boost DP_IDENTIFIER_THERMOSTAT_BOOST DP_IDENTIFIER_THERMOSTAT_BOOST 0x04 // Boost for Moes
processTuyaBoostModeReport( fncmd )
break
case 'HY367' : // Thermostat Mode
def thermostatModes = ['holiday', 'auto', 'heat', 'comfort', 'eco', 'emergency heat', 'temp_auto', 'valve'] // using "heat" and "emergency heat" for consistency, 01 is defined as manual in documentation 05 is defined as Boost in documentation
def thermostatMode = thermostatModes[fncmd]
logDebug "${device.displayName} mode is <b>${thermostatMode}</b> (<b>dp=${dp}</b> fncmd=${fncmd})"
sendEvent(name: 'thermostatMode', value: thermostatMode)
break
default :
if (settings?.logEnable) { log.warn "${device.displayName } Thermostat model group ${getModelGroup()} is not processed! (dp=${dp}, fncmd=${fncmd})"}
break
}
// TODO 'HY369' | 0x04 | | Mode 0x01 Auto ,0x02 Off | |
break
case 0x05 : // BRT-100 ?
if (settings?.txtEnable) log.info "${device.displayName} configuration is done. Result: 0x${fncmd}"
break
case 0x06 : // thermostatOperatingState
switch (getModelGroup()) {
case 'TRV07' :
if (settings?.txtEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==1 ? 'heating' : 'idle'}"}
else if (settings?.logEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==1 ? 'heating' : 'idle'} (dp=${dp}, fncmd=${fncmd})"}
sendThermostatOperatingStateEvent(fncmd == 1 ? 'heating' : 'idle')
break
default :
if (settings?.txtEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==0 ? 'heating' : 'idle'}"}
else if (settings?.logEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==0 ? 'heating' : 'idle'} (dp=${dp}, fncmd=${fncmd})"}
sendThermostatOperatingStateEvent(fncmd == 0 ? 'heating' : 'idle')
break
}
break
case 0x07 : // others Childlock status DP_IDENTIFIER_THERMOSTAT_CHILDLOCK_1 0x07 // 0x0407 > starting moving // sound for X5H thermostat
if (isBEOK()) {
logInfo "sound is: ${fncmd==0?'off':'on'}"
device.updateSetting( 'sound', [value : (fncmd == 0 ? false : true), type : 'bool'] )
}
else if (getModelGroup() in ['HY367', 'HY369']) { // Child Lock status
logInfo "HY367/HY369 Child Lock (dp=${dp}) is: ${fncmd}" // [0] unlocked [1] locked
sendEvent(name: 'childLock', value: (fncmd == 0) ? 'off' : 'on' )
break
}
else if (getModelGroup() in ['TRV07']) { // Open Window function
logInfo "TRV07 Window Open status dp=${dp} fncmd=${fncmd}" //
sendEvent(name: 'windowOpen', value: fncmd == 0 ? 'false' : 'true')
}
else {
if (settings?.txtEnable) log.info "${device.displayName} valve starts moving: 0x${fncmd}" // BRT-100 00-> opening; 01-> closed!
if (fncmd == 00) {
sendThermostatOperatingStateEvent('heating')
}
else { // fncmd == 01
sendThermostatOperatingStateEvent('idle')
}
}
break
case 0x08 : // DP_IDENTIFIER_WINDOW_OPEN2 0x08 // BRT-100 TRV07
logInfo "Window Open Detection MODE (dp=${dp}) is: ${fncmd==0 ? 'off' : 'on'}" //0:function disabled / 1:function enabled
sendEvent(name: 'windowOpenDetection', value: fncmd == 0 ? 'off' : 'on')
break
case 0x09 : // BRT-100 unknown function
logInfo "BRT-100 unknown function (dp=${dp}) is: ${fncmd}"
break
case 0x0A : // (10) BEOK - x5hFrostProtection
logInfo "frost protection is: ${fncmd==0?'off':'on'} (0x${fncmd})"
device.updateSetting( 'frostProtection', [value:(fncmd == 0) ? false : true, type:'bool'] )
break;
case 0x0C : // (12)
logInfo "TRV07 Child lock dp=${dp} fncmd=${fncmd}" // TRV07
sendEvent(name: 'childLock', value: (fncmd == 0) ? 'off' : 'on' )
break
case 0x0D : // (13)
if (getModelGroup() in ['TRV07']) {
if (fncmd <= 200) {
logInfo "TRV07 battery dp=${dp} fncmd=${fncmd}" // ? fncmd=3281408 ?
def battery = fncmd > 100 ? 100 : fncmd
if (settings?.txtEnable) log.info "${device.displayName} battery is: ${fncmd} % (dp=${dp})"
getBatteryPercentageResult(battery * 2)
}
else {
logInfo "TRV07 bad value for a battery report dp=${dp} fncmd=${fncmd}" // ? fncmd=3281408 ?
}
}
else if (getModelGroup() in ['HY367']) {
logInfo "TRV07 Fault alarm dp=${dp} fncmd=${fncmd}"
}
else { // BRT-100 Childlock status DP_IDENTIFIER_THERMOSTAT_CHILDLOCK_4 0x0D MOES, LIDL, TRV07
logInfo "Child Lock (dp=${dp}) is: ${fncmd}" // 0:function disabled / 1:function enabled
sendEvent(name: 'childLock', value: (fncmd == 0) ? 'off' : 'on' )
}
break
case 0x0E : // (14) BRT-100 Battery # 0x020e # battery percentage (updated every 4 hours )
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Fault alarm dp=${dp} fncmd=${fncmd}" // TODO !!! ? fncmd=3281408 or 0 ?
}
else {
def battery = fncmd > 100 ? 100 : fncmd
if (settings?.txtEnable) log.info "${device.displayName} battery is: ${fncmd} % (dp=${dp})"
getBatteryPercentageResult(fncmd * 2)
}
break
case 0x0F : // (15)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Minimum limit temperature is: ${fncmd/10} (raw ${fncmd})" / 5.0 TODO - update preference
}
else {
logInfo "unknown dp=${dp} fncmd=${fncmd}"
}
case 0x10 : // (16): Heating setpoint AVATTO; x5hSetTemp BEOK; // TODO isTRV07() - maybe heatingSetpoint ???
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Maximum limit temperature is: ${fncmd/10} (raw ${fncmd})" / 30.0 TODO - update preference
}
else {
processTuyaHeatSetpointReport( fncmd )
}
break
case 0x11 : // (17) AVATTO, TRV07
if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Heating schedule dp=${dp} fncmd=${fncmd}" // ? fncmd=3281408 ?
}
else {
logInfo "AVATTO Set temperature F is: ${fncmd}"
}
break
case 0x12 : // (18) Max Temp Limit MOES, LIDL
// TODO 'HY369' - windowdetection
if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} Set temperature upper limit F is: ${fncmd}"
}
else if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Tuesday dp=${dp} fncmd=${fncmd}" // ? fncmd=3281408 ?
}
else { // KK TODO - also Window open status (false:true) for TRVs ? DP_IDENTIFIER_WINDOW_OPEN
if (settings?.txtEnable) log.info "${device.displayName} Max Temp Limit is: ${fncmd}"
}
break
case 0x13 : // (19) Max Temp LIMIT AVATTO MOES, LIDL
if (getModelGroup() in ['AVATTO']) {
device.updateSetting('maxTemp', [value: fncmd as int , type:'number'])
if (settings?.txtEnable) log.info "${device.displayName} AVATTO Max Temp Limit is: ${fncmd} C (dp=${dp}, fncmd=${fncmd})"
}
else if (isBEOK()) {
device.updateSetting('maxTemp', [value: fncmd as int , type:'number'])
if (settings?.txtEnable) log.info "${device.displayName} BEOK Max Temp Limit is: ${fncmd} C (dp=${dp}, fncmd=${fncmd})"
}
else if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Wednesday dp=${dp} fncmd=${fncmd}"
}
else {
// TODO - MOES !!
logInfo "${getModelGroup()} Max Temp Limit is: ${fncmd} C (dp=${dp}, fncmd=${fncmd})"
}
break
case 0x14 : // (20) Dead Zone Temp (hysteresis) MOES, LIDL
if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} lower limit F is: ${fncmd}"
// TODO - clarify!
}
else if (getModelGroup() == 'HY369') {
logInfo "HY369 valvestate (VALVE_DETECT_ATTR) is: ${fncmd}" // [0] do not report [1] report
}
else if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Thursday dp=${dp} fncmd=${fncmd}"
}
else { // KK TODO - also Valve state report : on=1 / off=0 ? DP_IDENTIFIER_THERMOSTAT_VALVE 0x14 // Valve
if (settings?.txtEnable) log.info "${device.displayName} Dead Zone Temp (hysteresis) is: ${fncmd}"
// TODO - clarify!
}
break
case 0x15 : // (21) 'HY369' battery
if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Friday dp=${dp} fncmd=${fncmd}"
}
else {
def battery = fncmd > 100 ? 100 : fncmd
if (settings?.txtEnable) log.info "${device.displayName} battery is: ${fncmd} % (dp=${dp})"
getBatteryPercentageResult(fncmd * 2)
}
break
case 0x16 : // (22)
if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Saturday dp=${dp} fncmd=${fncmd}"
}
else {
logInfo "unknown dp=${dp} fncmd=${fncmd}"
}
break
case 0x17 : // (23) temperature scale for AVATTO
if (getModelGroup() in ['TRV07']) {
logDebug "TRV07 Week program Sunday dp=${dp} fncmd=${fncmd}"
}
else {
if (settings?.txtEnable) log.info "${device.displayName} temperature scale is: ${fncmd==0?'C':'F'} (${fncmd})"
}
break
case 0x18 : // (24) : Current (local) temperature; x5hCurrentTemp BEOK TRV07
logDebug "processTuyaTemperatureReport dp_id=${dp_id} <b>dp=${dp}</b> :"
processTuyaTemperatureReport( fncmd )
break
case 0x1A : // (26) AVATTO setpoint lower limit
if (getModelGroup() in ['AVATTO']) {
device.updateSetting('minTemp', [value: fncmd , type:'number'])
}
if (settings?.txtEnable) log.info "${device.displayName} Min temperature limit is: ${fncmd} C (dp=${dp}, fncmd=${fncmd})"
break
case 0x1B : // (27) temperature calibration/correction (offset in degrees) for AVATTO, Moes and Saswell; x5hTempCorrection BEOK TRV07?
processTuyaCalibration( dp, fncmd )
break
case 0x1D : // (29) AVATTO
if (settings?.txtEnable) log.info "${device.displayName} current temperature F is: ${fncmd}"
break
case 0x1E : // (30) x5hWeeklyProcedure BEOK
if (settings?.txtEnable) log.info "${device.displayName} weekly procedure is: ${fncmd}"
break
case 0x1F : // (31) x5hWorkingDaySetting BEOK TRV07?
if (settings?.txtEnable) log.info "${device.displayName} working day setting is: ${fncmd}"
break
case 0x23 : // (35) LIDL BatteryVoltage
if (settings?.txtEnable) log.info "${device.displayName} BatteryVoltage is: ${fncmd}"
break
case 0x24 : // (36) : current (running) operating state (valve) AVATTO (enum) 'open','close' also MOES
if (settings?.txtEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==0 ? 'heating' : 'idle'}"}
else if (settings?.logEnable) { log.info "${device.displayName } thermostatOperatingState is: ${fncmd==0 ? 'heating' : 'idle'} (dp=${dp}, fncmd=${fncmd})"}
sendThermostatOperatingStateEvent(fncmd == 0 ? 'heating' : 'idle')
break
case 0x27 : // (39) AVATTO - RESET; x5hFactoryReset BEOK
if (fncmd == 0) {
if (settings?.txtEnable) log.info "${device.displayName} thermostat reset state is (${fncmd})"
}
else {
log.warn "${device.displayName} thermostat reset state is (${fncmd}) !!!"
}
break
case 0x1E : // (30) DP_IDENTIFIER_THERMOSTAT_CHILDLOCK_3 0x1E // For Moes device
case 0x28 : // (40) Child Lock DP_IDENTIFIER_THERMOSTAT_CHILDLOCK_2 0x28 ( AVATTO (boolean) ); x5hChildLock BEOK (TODO - check if boolean or enum for BEOK?)
if (settings?.txtEnable) log.info "${device.displayName} Child Lock is: ${fncmd} (dp=${dp})"
sendEvent(name: 'childLock', value: (fncmd == 0) ? 'off' : 'on' )
break
case 0x2B : // (43) AVATTO Sensor 0-In 1-Out 2-Both; x5hSensorSelection BEOK
logInfo "Sensor is: ${sensorOptions[fncmd.toString()]} (${fncmd})"
// TODO - make it a preference parameter !
sendEvent(name: 'sensorSelection', value: sensorOptions[fncmd.toString()])
break
case 0x2C : // (44) // temperature calibration (offset in degree) //DP_IDENTIFIER_THERMOSTAT_CALIBRATION_2 0x2C // Calibration offset used by others
processTuyaCalibration( dp, fncmd ) // including 'HY367' and 'HY369'- temperature calibration (decidegree)
break
case 0x2D : // (45) LIDL and AVATTO ErrorStatus (bitmap) e1, e2, e3 // er1: Built-in sensor disconnected or fault with it; Er1: Built-in sensor disconnected or fault with it.; x5hFaultAlarm BEOK
if (settings?.txtEnable) log.info "${device.displayName} fault alarm error code is: ${fncmd}"
break
// case 0x62 : // (98) DP_IDENTIFIER_REPORTING_TIME 0x62 (Sensors)
case 0x65 : // (101) AVATTO PID ; also LIDL ComfortTemp; x5hTempDiff BEOK
if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} Thermostat PID regulation point is: ${fncmd}" // Model#1 only !!
}
else if (isBEOK() || isTRV07()) { // TODO - check TRV07 - Room sensor calibration !!!!!!!!!!!
double floatDif = (fncmd as double) / 10.0
device.updateSetting('hysteresis', [value:floatDif, type:'decimal'])
if (settings?.txtEnable) log.info "${device.displayName} (0x65) temperature difference (hysteresis) is: ${floatDif} C (${fncmd})"
}
else {
if (settings?.logEnable) log.info "${device.displayName} Thermostat SCHEDULE_1 (0x65) data received (not processed)... ${fncmd}"
}
break
case 0x66 : // (102) min temperature limit; also LIDL EcoTemp; x5hProtectionTempLimit BEOK (default 35)
if (isBEOK()) { // aka 'temperature ceiling'; aka protection temperature limit
if (settings?.txtEnable) log.info "${device.displayName} BEOK 'temperature ceiling' is: ${fncmd} C (dp=${dp}, fncmd=${fncmd})"
device.updateSetting('tempCeiling', [value: fncmd as int , type:'number']) // whole number
}
else if (getModelGroup() in ['HY367','HY369']) { // Minimum allowed heating setpoint
logInfo "HY367/HY369 Min temperature limit (dp=${dp}) is: ${fncmd} (raw=${fncmd})"
device.updateSetting('minTemp', [value: (fncmd) as int , type:'number'])
sendEvent(name: 'minHeatingSetpoint', value: fncmd)
}
else {
if (settings?.txtEnable) log.info "${device.displayName} Min temperature limit (UNPROCESSED) is: ${fncmd}"
// TODO - set minTemp for AVATTO and MOES ???
}
break
case 0x67 : // (103) max temperature limit; also LIDL AwaySetting; x5hOutputReverse BEOK
if (getModelGroup() in ['BRT-100']) { // #0x0267 # Boost heating countdown in second (Received value [0, 0, 1, 44] for 300)
if (settings?.txtEnable) log.info "${device.displayName} Boost heating countdown: ${fncmd} seconds"
}
else if (getModelGroup() in ['AVATTO']) { // Antifreeze mode ?
if (settings?.txtEnable) log.info "${device.displayName} Antifreeze mode is ${fncmd==0?'off':'on'} (${fncmd})"
}
else if (isBEOK()) {
if (settings?.txtEnable) log.info "${device.displayName} output reverse is ${fncmd==0?'off':'on'} (${fncmd})"
}
else if (getModelGroup() in ['HY367','HY369']) { // Maximum allowed heating setpoint
logInfo "HY367/HY369 Max temperature limit (dp=${dp}) is: ${fncmd} (raw=${fncmd})"
device.updateSetting('maxTemp', [value: (fncmd) as int , type:'number'])
sendEvent(name: 'maxHeatingSetpoint', value: fncmd)
}
else {
if (settings?.txtEnable) log.info "${device.displayName} unknown parameter is: ${fncmd} (dp=${dp}, fncmd=${fncmd}, data=${descMap?.data})"
}
// KK TODO - could be setpoint for some devices ?
// DP_IDENTIFIER_THERMOSTAT_HEATSETPOINT_2 0x67 // Heatsetpoint for Moe ?
break
case 0x68 : // (104) DP_IDENTIFIER_THERMOSTAT_VALVE_2 0x68 // Valve; also LIDL TempCalibration!; x5hBackplaneBrightness BEOK
if (getModelGroup() in ['AVATTO']) {
def value = safeToInt(fncmd)
if (settings?.txtEnable) log.info "${device.displayName} AVATTO Program Mode (104) received is: ${programModeOptions[fncmd.toString()]} (${fncmd})" // AVATTO programm mode 0:0ff 1:Mon-Fri 2:Mon-Sat 3:Mon-Sun
device.updateSetting( 'programMode', [value:value.toString(), type:'enum'] )
}
else if (isBEOK()) {
if (settings?.txtEnable) log.info "${device.displayName} backplane brightness is ${brightnessOptions[fncmd.toString()]} (${fncmd})"
device.updateSetting( 'brightness', [value: fncmd.toString(), type:'enum'] )
Map lastRxMap = stringToJsonMap( state.lastRx )
lastRxMap.setBrightness = brightnessOptions[fncmd.toString()]
state.lastRx = mapToJsonString( lastRxMap)
sendEvent(name: 'brightness', value: brightnessOptions[fncmd.toString()])
}
else if (getModelGroup in ['HY367','HY369']) {
logInfo "HY367/HY369 MOES_WINDOW_DETECT_ATTR (dp=${dp}) is: ${fncmd}" // [0,35,5] on/off, temperature, operating time (min)
}
else {
if (settings?.txtEnable) log.info "${device.displayName} Valve position is: ${fncmd}% (dp=${dp}, fncmd=${fncmd})"
// # 0x0268 # TODO - send event! (works OK with BRT-100 (values of 25 / 50 / 75 / 100)
}
break
case 0x69 : // (105) BRT-100 temp calibration // could be also Heatsetpoint for TRV_MOE mode auto ? also LIDL
if (getModelGroup() in ['BRT-100']) {
processTuyaCalibration( dp, fncmd )
}
else if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} AVATTO unknown parameter (105) is: ${fncmd}" // TODO: check AVATTO usage
}
else if (getModelGroup in ['HY367','HY369']) {
logInfo "HY367/HY369 BOOST mode operating time (dp=${dp}) is: ${fncmd} seconds"
}
else {
log.warn "${device.displayName} (DP=0x69) ?TRV_MOES auto mode Heatsetpoint? value is: ${fncmd}"
}
break
case 0x6A : // (106) DP_IDENTIFIER_THERMOSTAT_MODE_1 0x6A // mode used with DP_TYPE_ENUM Energy saving mode (Received value 0:off / 1:on)
if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} Dead Zone temp (hysteresis) is: ${fncmd}C (dp=${dp}, fncmd=${fncmd})"
device.updateSetting('hysteresis', [value:fncmd, type:'decimal'])
}
else if (getModelGroup in ['HY367','HY369']) {
logInfo "HY367/HY369 MOES_FORCE_VALVE_ATTR (dp=${dp}) is: ${fncmd}" // [0] normal [1] open [2] close
}
else {
if (settings?.txtEnable) log.info "${device.displayName} Energy saving mode? (dp=${dp}) is: ${fncmd} data = ${descMap?.data})" // 0:function disabled / 1:function enabled
}
break
case 0x6B : // (107) DP_IDENTIFIER_TEMPERATURE 0x6B (Sensors) // BRT-100 !
if (getModelGroup() in ['AVATTO']) {
if (settings?.txtEnable) log.info "${device.displayName} AVATTO unknown parameter (105) is: ${fncmd}" // TODO: check AVATTO usage
}
else if (getModelGroup in ['HY367','HY369']) {
logInfo "HY367/HY369 comfort mode temperaure (dp=${dp}) is: ${fncmd/10.0} (raw:${fncmd})" / (decidegree)
}
else {
if (settings?.txtEnable) log.info "${device.displayName} (DP=0x6B) Energy saving mode temperature value is: ${fncmd}" // for BRT-100 # 0x026b # Energy saving mode temperature ( Received value [0, 0, 0, 15] )
}
break
case 0x6C : // (108)
if (getModelGroup() in ['BRT-100']) {
if (settings?.txtEnable) log.info "${device.displayName} (DP=0x6C) Max target temp is: ${fncmd}" // BRT-100 ( Received value [0, 0, 0, 35] )
device.updateSetting('maxTemp', [value: fncmd , type:'number'])
}
else if (getModelGroup() in ['AVATTO']) {
logInfo "AVATTO unknown parameter (108) is: ${fncmd}" // fncmd=0 TODO: check AVATTO usage
}
else if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Valve (108) is open: ${fncmd/10}%"
sendEvent(name: 'valve', value: fncmd / 10)
}
else if (getModelGroup in ['HY367','HY369']) {
logInfo "HY367/HY369 eco mode temperature (dp=${dp}) is: ${fncmd/10.0} (raw:${fncmd})" / (decidegree)
}
else {
logInfo "(dp=108) unknown parameter value is: ${fncmd}" // DP_IDENTIFIER_HUMIDITY 0x6C (Sensors)
}
// KK Tuya cmd: dp=108 value=404095046 descMap.data = [00, 08, 6C, 00, 00, 18, 06, 00, 28, 08, 00, 1C, 0B, 1E, 32, 0C, 1E, 32, 11, 00, 18, 16, 00, 46, 08, 00, 50, 17, 00, 3C]
break
case 0x6D : // (109)
if (getModelGroup() in ['BRT-100']) { // 0x026d # Min target temp (Received value [0, 0, 0, 5])
if (settings?.txtEnable) log.info "${device.displayName} (DP=0x6D) Min target temp is: ${fncmd}"
device.updateSetting('minTemp', [value: fncmd , type:'number'])
}
else if (getModelGroup() in ['AVATTO']) {
logInfo "AVATTO unknown parameter (109) is: ${fncmd}" // TODO: check AVATTO usage
}
else if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 model (109) is: ${fncmd}"
}
else if (getModelGroup() in ['HY367', 'HY369']) { // Valve % open report
logInfo "HY367/HY369 valve opening percentage (dp=${dp}) is: ${fncmd} %"
sendEvent(name: 'valve', value: fncmd, unit: '%')
}
else { // TODO 'HY369'- valveposition TODO - event! // Valve position in % (also // DP_IDENTIFIER_THERMOSTAT_SCHEDULE_4 0x6D // Not finished)
if (settings?.txtEnable) log.info "${device.displayName} (DP=0x6D) valve position is: ${fncmd} (dp=${dp}, fncmd=${fncmd})"
}
// KK TODO if (valve > 3) => On !
break
case 0x6E : // (110) Low battery DP_IDENTIFIER_BATTERY 0x6E // including 'HY369' lowbattery
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Motor thrust (110) is: ${fncmd}"
}
else if (getModelGroup() in ['HY367']) { // Low Battery warning
def battery = fncmd < 1 ? 100 : fncmd // battery is 100% if no warning
if (battery == 100) { // log battery as charged if the fncmd is 0
if (settings?.txtEnable) log.info "${device.displayName} battery is: <b>charged</b> (dp=${dp}, fncmd=${fncmd})"
} else { // log the warning that battery is low
logWarn "${device.displayName} battery is: <b>LOW</b> (dp=${dp}, fncmd=${fncmd})"
}
getBatteryPercentageResult(battery * 2)
}
else {
logInfo "(Low) Battery warning (DP= 0x6E) is: ${fncmd}" // or battery status? 'HY367','HY369',
// TODO - send battery event 111
}
break
case 0x6F : // (111)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Display brightness (111) is: ${fncmd}" // TODO: map to the preference
}
else if (getModelGroup in ['HY367']) {
logInfo "HY367 AutoMode Type (dp=${dp}) is: ${fncmd}"
}
else {
logInfo "HY369 Week format (dp=${dp}) is: ${fncmd}" // [0] 5 days [1] 6 days, [2] 7 days
}
break
case 0x70 : // (112)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Software version (112) is: ${fncmd}" // fncmd=1001 TODO: map to tuyaVersion
}
else if (getModelGroup in ['HY369']) {
logInfo "HY369 thermostat schedule workdays (dp=${dp}) is: ${fncmd}" // DP_IDENTIFIER_THERMOSTAT_SCHEDULE_2 0x70 // work days (6)
}
else if (getModelGroup in ['HY367']) {
logInfo "HY367 Workday Set (dp=${dp}) is: ${fncmd}"
}
else {
if (settings?.txtEnable) log.info "${device.displayName} reporting status state : ${descMap?.data}"
}
break
case 0x71 : // (113)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Screen orientation (113) is: ${fncmd}"
}
else if (getModelGroup in ['HY369']) {
logInfo "HY369 thermostat schedule weekend (dp=${dp}) is: ${fncmd}" // DP_IDENTIFIER_THERMOSTAT_SCHEDULE_3 0x71 // holiday = Not working day (6)
}
else if (getModelGroup in ['HY367']) {
logInfo "HY367 Restday Set (dp=${dp}) is: ${fncmd}"
}
else {
if (settings?.txtEnable) log.info "${device.displayName} reporting status state : ${descMap?.data}"
}
break
case 0x72 : // (114)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 System mode (114) is: ${fncmd}" // TODO: check TRV07 usage as 'Sstem mode'
}
else if (getModelGroup() in ['HY367']) { // HY367 Holiday Mode Setpoint Temperature
logInfo "HY367/HY369 away mode (holiday) temperature (dp=${dp}) is: ${fncmd} (raw=${fncmd})"
device.updateSetting('holidayModeSetpoint', [value: (fncmd) as int , type:'number'])
sendEvent(name: 'holidayModeSetpoint', value: fncmd, unit: "°C")
}
break
case 0x73 : // (115)
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Switch deviation (energy-saving mode only) (115) is: ${fncmd}"
}
else if (getModelGroup in ['HY367']) {
logInfo "HY367 Window Open status (dp=${dp}) is: ${fncmd==0 ? 'false' : 'true'} (${fncmd})"
sendEvent(name: 'windowOpen', value: fncmd == 0 ? 'false' : 'true')
}
else {
logInfo "unknown parameter (115) is: ${fncmd}"
}
break
case 0x74 : // (116) // LIDL OpenwindowTemp
if (getModelGroup() in ['TRV07']) {
logInfo "TRV07 Motor Data (116) is: ${fncmd}"
}
else {
logInfo "HY367/HY369 auto lock/ keylock (dp=${dp}) is: ${fncmd}" // [0] auto [1] manual
}
break
case 0x75 : // (117)
if (getModelGroup in ['HY367']) {
logInfo "HY367 Holiday Days (dp=${dp}) is: ${fncmd}"
}
else {
logInfo "HY369 away mode duration (dp=${dp}) is: ${fncmd} days"
}
break
case 0x76 : // (118)
if (getModelGroup() in ['HY367']) { // Not quite sure what this does, as it does not appear to change when valve opens (handled by dp 109)
logInfo "HY367 Valve openning (dp=${dp}) is: ${fncmd}"
}
else {
logInfo "unknown parameter (dp=${dp}) is: ${fncmd}"
}
break
default :
if (settings?.logEnable) log.warn "${device.displayName} NOT PROCESSED Tuya cmd: dp=${dp} value=${fncmd} descMap.data = ${descMap?.data}"
break
} // (dp) switch
}
else if (descMap?.cluster == '0000') {
if (settings?.logEnable) log.debug "${device.displayName} basic cluster report : descMap = ${descMap}"
}
else {
if (settings?.logEnable) log.warn 'not parsed : ' + descMap
}
} // if catchAll || readAttr
}
def syncTuyaDateTime() {
// The data format for time synchronization, including standard timestamps and local timestamps. Standard timestamp (4 bytes) local timestamp (4 bytes) Time synchronization data format: The standard timestamp is the total number of seconds from 00:00:00 on January 01, 1970 GMT to the present.
// For example, local timestamp = standard timestamp + number of seconds between standard time and local time (including time zone and daylight saving time). // Y2K = 946684800
def offset = 0
def offsetHours = 0
Calendar cal = Calendar.getInstance(); //it return same time as new Date()
def hour = cal.get(Calendar.HOUR_OF_DAY)
try {
offset = location.getTimeZone().getOffset(new Date().getTime())
offsetHours = (offset / 3600000) as int
logDebug "timezone offset of current location is ${offset} (${offsetHours} hours), current hour is ${hour} h"
} catch(e) {
log.error "${device.displayName} cannot resolve current location. please set location in Hubitat location setting. Setting timezone offset to zero"
}
//
def cmds
if (isBEOK()) {
// do NOT synchronize the clock between 00:00 and 09:00 local time !!
if (hour >= 8) {
cmds = zigbee.command(CLUSTER_TUYA, SETTIME, '0008' + zigbee.convertToHexString((int)((now() - 3600000L * (8 - offsetHours)) / 1000),8) + zigbee.convertToHexString((int)((now() + 3600000L * 8) / 1000), 8)) // works OK between 8 and 24 h
}
else {
logDebug "skipped time synchronization (current hour is ${hour} h)"
return
}
}
else {
cmds = zigbee.command(CLUSTER_TUYA, SETTIME, '0008' + zigbee.convertToHexString((int)(now() / 1000),8) + zigbee.convertToHexString((int)((now() + offset) / 1000), 8))
}
logDebug "sending time data : ${cmds}"
cmds.each { sendHubCommand(new hubitat.device.HubAction(it, hubitat.device.Protocol.ZIGBEE)) }
incTxCtr()
setLastRx( NOT_SET, NOT_SET) // -1
}
def processTuyaHeatSetpointReport( fncmd )
{
double setpointValue
def model = getModelGroup()
if (getModelGroup() in ['AVATTO', 'MOES', 'BRT-100' ]) {
setpointValue = fncmd as int
}
else if (getModelGroup() in ['BEOK', 'HY367', 'HY369', 'TRV07','TEST3']) { // added HYS369 10/29/2023 - current room temp (decidegree)
setpointValue = fncmd / 10.0
}
else {
setpointValue = fncmd
}
setpointValue = setpointValue.round(1)
if (settings?.txtEnable) log.info "${device.displayName} heatingSetpoint is: ${setpointValue}" + "\u00B0" + 'C'
sendEvent(name: 'heatingSetpoint', value: setpointValue, unit: "\u00B0" + 'C')
sendEvent(name: 'thermostatSetpoint', value: setpointValue, unit: "\u00B0" + 'C') // Google Home compatibility
//
Map lastRxMap = stringToJsonMap( state.lastRx )
lastRxMap.setPoint = setpointValue
state.lastRx = mapToJsonString( lastRxMap) // state.lastRx
}
def processTuyaTemperatureReport( fncmd )
{
double currentTemperatureValue
def model = getModelGroup()