@@ -18,6 +18,7 @@ import {
18
18
humidity ,
19
19
iasZoneAlarm ,
20
20
numeric ,
21
+ occupancy ,
21
22
onOff ,
22
23
ota ,
23
24
temperature ,
@@ -27,7 +28,7 @@ import * as tuya from '../lib/tuya';
27
28
import { DefinitionWithExtend , Fz , KeyValue , KeyValueAny , ModernExtend , Tz } from '../lib/types' ;
28
29
import * as utils from '../lib/utils' ;
29
30
30
- const { ewelinkAction} = ewelinkModernExtend ;
31
+ const { ewelinkAction, ewelinkBattery } = ewelinkModernExtend ;
31
32
32
33
const NS = 'zhc:sonoff' ;
33
34
const manufacturerOptions = {
@@ -639,45 +640,35 @@ const definitions: DefinitionWithExtend[] = [
639
640
vendor : 'SONOFF' ,
640
641
whiteLabel : [ { vendor : 'eWeLink' , model : 'RHK06' } , tuya . whitelabel ( 'Tuya' , 'WL-19DWZ' , 'Contact sensor' , [ '_TZ3000_n2egfsli' ] ) ] ,
641
642
description : 'Contact sensor' ,
642
- exposes : [ e . contact ( ) , e . battery_low ( ) , e . battery ( ) , e . battery_voltage ( ) ] ,
643
- fromZigbee : [ fz . ias_contact_alarm_1 , fz . battery ] ,
644
- toZigbee : [ ] ,
645
- configure : async ( device , coordinatorEndpoint ) => {
646
- const endpoint = device . getEndpoint ( 1 ) ;
647
- await reporting . bind ( endpoint , coordinatorEndpoint , [ 'genPowerCfg' ] ) ;
648
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
649
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
650
- } ,
643
+ extend : [ ewelinkBattery ( ) , iasZoneAlarm ( { zoneType : 'contact' , zoneAttributes : [ 'alarm_1' , 'battery_low' ] } ) ] ,
651
644
} ,
652
645
{
653
646
zigbeeModel : [ 'WB01' , 'WB-01' ] ,
654
647
model : 'SNZB-01' ,
655
648
vendor : 'SONOFF' ,
656
649
whiteLabel : [ { vendor : 'eWeLink' , model : 'RHK07' } ] ,
657
650
description : 'Wireless button' ,
658
- exposes : [ e . battery ( ) , e . action ( [ 'single' , 'double' , 'long' ] ) , e . battery_voltage ( ) ] ,
659
- fromZigbee : [ fz . ewelink_action , fz . battery ] ,
651
+ extend : [ ewelinkBattery ( ) ] ,
652
+ exposes : [ e . action ( [ 'single' , 'double' , 'long' ] ) ] ,
653
+ fromZigbee : [ fz . ewelink_action ] ,
660
654
toZigbee : [ ] ,
661
655
configure : async ( device , coordinatorEndpoint ) => {
662
656
const endpoint = device . getEndpoint ( 1 ) ;
663
- await reporting . bind ( endpoint , coordinatorEndpoint , [ 'genOnOff' , 'genPowerCfg' ] ) ;
664
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
665
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
657
+ await reporting . bind ( endpoint , coordinatorEndpoint , [ 'genOnOff' ] ) ;
666
658
} ,
667
659
} ,
668
660
{
669
661
zigbeeModel : [ 'KF01' , 'KF-01' ] ,
670
662
model : 'SNZB-01-KF' ,
671
663
vendor : 'SONOFF' ,
672
664
description : 'Wireless button' ,
673
- exposes : [ e . battery ( ) , e . action ( [ 'off' , 'single' ] ) , e . battery_voltage ( ) ] ,
674
- fromZigbee : [ fz . command_status_change_notification_action , fz . battery ] ,
665
+ extend : [ ewelinkBattery ( ) ] ,
666
+ exposes : [ e . action ( [ 'off' , 'single' ] ) ] ,
667
+ fromZigbee : [ fz . command_status_change_notification_action ] ,
675
668
toZigbee : [ ] ,
676
669
configure : async ( device , coordinatorEndpoint ) => {
677
670
const endpoint = device . getEndpoint ( 1 ) ;
678
- await reporting . bind ( endpoint , coordinatorEndpoint , [ 'ssIasZone' , 'genPowerCfg' ] ) ;
679
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
680
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
671
+ await reporting . bind ( endpoint , coordinatorEndpoint , [ 'ssIasZone' ] ) ;
681
672
} ,
682
673
} ,
683
674
{
@@ -712,6 +703,8 @@ const definitions: DefinitionWithExtend[] = [
712
703
fromZigbee : [ fz . SNZB02_temperature , fz . humidity , fz . battery ] ,
713
704
toZigbee : [ ] ,
714
705
configure : async ( device , coordinatorEndpoint ) => {
706
+ device . powerSource = 'Battery' ;
707
+ device . save ( ) ;
715
708
try {
716
709
const endpoint = device . getEndpoint ( 1 ) ;
717
710
const bindClusters = [ 'msTemperatureMeasurement' , 'msRelativeHumidity' , 'genPowerCfg' ] ;
@@ -731,7 +724,7 @@ const definitions: DefinitionWithExtend[] = [
731
724
model : 'SNZB-02D' ,
732
725
vendor : 'SONOFF' ,
733
726
description : 'Temperature and humidity sensor with screen' ,
734
- extend : [ battery ( { percentage : true } ) , temperature ( ) , humidity ( ) , bindCluster ( { cluster : 'genPollCtrl' , clusterType : 'input' } ) ] ,
727
+ extend : [ battery ( ) , temperature ( ) , humidity ( ) , bindCluster ( { cluster : 'genPollCtrl' , clusterType : 'input' } ) ] ,
735
728
} ,
736
729
{
737
730
fingerprint : [
@@ -754,18 +747,7 @@ const definitions: DefinitionWithExtend[] = [
754
747
vendor : 'SONOFF' ,
755
748
whiteLabel : [ { vendor : 'eWeLink' , model : 'RHK09' } ] ,
756
749
description : 'Motion sensor' ,
757
- fromZigbee : [ fz . ias_occupancy_alarm_1 , fz . battery ] ,
758
- toZigbee : [ ] ,
759
- configure : async ( device , coordinatorEndpoint ) => {
760
- const endpoint = device . getEndpoint ( 1 ) ;
761
- const bindClusters = [ 'genPowerCfg' ] ;
762
- await reporting . bind ( endpoint , coordinatorEndpoint , bindClusters ) ;
763
- // 3600/7200 prevents disconnect
764
- // https://github.com/Koenkk/zigbee2mqtt/issues/13600#issuecomment-1283827935
765
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
766
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
767
- } ,
768
- exposes : [ e . occupancy ( ) , e . battery_low ( ) , e . battery ( ) , e . battery_voltage ( ) ] ,
750
+ extend : [ ewelinkBattery ( ) , iasZoneAlarm ( { zoneType : 'occupancy' , zoneAttributes : [ 'alarm_1' , 'battery_low' ] } ) ] ,
769
751
} ,
770
752
{
771
753
zigbeeModel : [ 'S26R2ZB' ] ,
@@ -839,9 +821,8 @@ const definitions: DefinitionWithExtend[] = [
839
821
model : 'SNZB-04P' ,
840
822
vendor : 'SONOFF' ,
841
823
description : 'Contact sensor' ,
842
- exposes : [ e . contact ( ) , e . battery_low ( ) , e . battery ( ) , e . battery_voltage ( ) ] ,
843
- fromZigbee : [ fz . ias_contact_alarm_1 , fz . battery ] ,
844
824
extend : [
825
+ iasZoneAlarm ( { zoneType : 'contact' , zoneAttributes : [ 'alarm_1' , 'battery_low' ] } ) ,
845
826
binary ( {
846
827
name : 'tamper' ,
847
828
cluster : 0xfc11 ,
@@ -853,22 +834,16 @@ const definitions: DefinitionWithExtend[] = [
853
834
access : 'STATE_GET' ,
854
835
} ) ,
855
836
ota ( ) ,
837
+ ewelinkBattery ( ) ,
856
838
] ,
857
- configure : async ( device , coordinatorEndpoint ) => {
858
- const endpoint = device . getEndpoint ( 1 ) ;
859
- await reporting . bind ( endpoint , coordinatorEndpoint , [ 'genPowerCfg' ] ) ;
860
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
861
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
862
- } ,
863
839
} ,
864
840
{
865
841
zigbeeModel : [ 'SNZB-03P' ] ,
866
842
model : 'SNZB-03P' ,
867
843
vendor : 'SONOFF' ,
868
844
description : 'Zigbee PIR sensor' ,
869
- fromZigbee : [ fz . occupancy , fz . battery ] ,
870
- exposes : [ e . occupancy ( ) , e . battery ( ) ] ,
871
845
extend : [
846
+ occupancy ( ) ,
872
847
numeric ( {
873
848
name : 'motion_timeout' ,
874
849
cluster : 0x0406 ,
@@ -887,13 +862,8 @@ const definitions: DefinitionWithExtend[] = [
887
862
access : 'STATE' ,
888
863
} ) ,
889
864
ota ( ) ,
865
+ ewelinkBattery ( ) ,
890
866
] ,
891
- configure : async ( device , coordinatorEndpoint ) => {
892
- const endpoint = device . getEndpoint ( 1 ) ;
893
- await reporting . bind ( endpoint , coordinatorEndpoint , [ 'genPowerCfg' ] ) ;
894
- await reporting . batteryVoltage ( endpoint , { min : 3600 , max : 7200 } ) ;
895
- await reporting . batteryPercentageRemaining ( endpoint , { min : 3600 , max : 7200 } ) ;
896
- } ,
897
867
} ,
898
868
{
899
869
zigbeeModel : [ 'SNZB-05P' ] ,
@@ -907,9 +877,8 @@ const definitions: DefinitionWithExtend[] = [
907
877
model : 'SNZB-06P' ,
908
878
vendor : 'SONOFF' ,
909
879
description : 'Zigbee occupancy sensor' ,
910
- fromZigbee : [ fz . occupancy ] ,
911
- exposes : [ e . occupancy ( ) ] ,
912
880
extend : [
881
+ occupancy ( ) ,
913
882
numeric ( {
914
883
name : 'occupancy_timeout' ,
915
884
cluster : 0x0406 ,
0 commit comments