@@ -19,15 +19,19 @@ local capabilities = require "st.capabilities"
19
19
local constants = require " st.zigbee.constants"
20
20
local IasZoneType = require " st.zigbee.generated.types.IasZoneType"
21
21
local device_management = require " st.zigbee.device_management"
22
+ local PowerConfiguration = clusters .PowerConfiguration
22
23
23
24
local CONTACT_SWITCH = IasZoneType .CONTACT_SWITCH
24
25
local MOTION_SENSOR = IasZoneType .MOTION_SENSOR
25
26
local WATER_SENSOR = IasZoneType .WATER_SENSOR
27
+ local REMOTE_CONTROL = IasZoneType .REMOTE_CONTROL
26
28
27
29
local ZIGBEE_GENERIC_SENSOR_PROFILE = " generic-sensor"
28
30
local ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE = " generic-contact-sensor"
29
31
local ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE = " generic-motion-sensor"
30
32
local ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE = " generic-waterleak-sensor"
33
+ local ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE = " generic-motion-illuminance"
34
+ local ZIGBEE_GENERIC_REMOTE_CONTROL_PROFILE = " generic-remote-control"
31
35
32
36
local ZONETYPE = " ZoneType"
33
37
local IASZone = clusters .IASZone
@@ -42,6 +46,7 @@ local do_configure = function(self, device)
42
46
device :configure ()
43
47
device :send (device_management .build_bind_request (device , IASZone .ID , self .environment_info .hub_zigbee_eui ))
44
48
device :send (IASZone .attributes .ZoneStatus :configure_reporting (device , 30 , 300 , 1 ))
49
+ device :send (PowerConfiguration .attributes .BatteryPercentageRemaining :read (device ))
45
50
end
46
51
47
52
local function info_changed (driver , device , event , args )
@@ -55,12 +60,18 @@ local function update_profile(device, zone_type)
55
60
local profile = ZIGBEE_GENERIC_SENSOR_PROFILE
56
61
if zone_type == CONTACT_SWITCH then
57
62
profile = ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE
58
- elseif zone_type == MOTION_SENSOR then
59
- profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE
63
+ elseif zone_type == REMOTE_CONTROL then
64
+ profile = ZIGBEE_GENERIC_REMOTE_CONTROL_PROFILE
60
65
elseif zone_type == WATER_SENSOR then
61
66
profile = ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE
67
+ elseif zone_type == MOTION_SENSOR then
68
+ profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE
69
+ for _ , ep in ipairs (device .zigbee_endpoints ) do
70
+ if device :supports_server_cluster (clusters .IlluminanceMeasurement .ID , ep .id ) then
71
+ profile = ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE
72
+ end
73
+ end
62
74
end
63
-
64
75
device :try_update_metadata ({profile = profile })
65
76
end
66
77
@@ -70,44 +81,6 @@ local ias_zone_type_attr_handler = function (driver, device, attr_val)
70
81
update_profile (device , attr_val .value )
71
82
end
72
83
73
- -- since we don't have button devices using IASZone, the driver here is remaining to be updated
74
- local generate_event_from_zone_status = function (driver , device , zone_status , zb_rx )
75
- local type = device :get_field (ZONETYPE )
76
- local event
77
- if type == CONTACT_SWITCH then
78
- if zone_status :is_alarm1_set () or zone_status :is_alarm2_set () then
79
- event = capabilities .contactSensor .contact .open ()
80
- else
81
- event = capabilities .contactSensor .contact .closed ()
82
- end
83
- elseif type == MOTION_SENSOR then
84
- if zone_status :is_alarm1_set () or zone_status :is_alarm2_set () then
85
- event = capabilities .motionSensor .motion .active ()
86
- else
87
- event = capabilities .motionSensor .motion .inactive ()
88
- end
89
- elseif type == WATER_SENSOR then
90
- if zone_status :is_alarm1_set () then
91
- event = capabilities .waterSensor .water .wet ()
92
- else
93
- event = capabilities .waterSensor .water .dry ()
94
- end
95
- end
96
- if event ~= nil then
97
- device :emit_event_for_endpoint (
98
- zb_rx .address_header .src_endpoint .value ,
99
- event )
100
- end
101
- end
102
-
103
- local ias_zone_status_attr_handler = function (driver , device , zone_status , zb_rx )
104
- generate_event_from_zone_status (driver , device , zone_status , zb_rx )
105
- end
106
-
107
- local ias_zone_status_change_handler = function (driver , device , zb_rx )
108
- generate_event_from_zone_status (driver , device , zb_rx .body .zcl_body .zone_status , zb_rx )
109
- end
110
-
111
84
local zigbee_generic_sensor_template = {
112
85
supported_capabilities = {
113
86
capabilities .battery ,
@@ -117,13 +90,7 @@ local zigbee_generic_sensor_template = {
117
90
zigbee_handlers = {
118
91
attr = {
119
92
[IASZone .ID ] = {
120
- [IASZone .attributes .ZoneType .ID ] = ias_zone_type_attr_handler ,
121
- [IASZone .attributes .ZoneStatus .ID ] = ias_zone_status_attr_handler
122
- }
123
- },
124
- cluster = {
125
- [IASZone .ID ] = {
126
- [IASZone .client .commands .ZoneStatusChangeNotification .ID ] = ias_zone_status_change_handler
93
+ [IASZone .attributes .ZoneType .ID ] = ias_zone_type_attr_handler
127
94
}
128
95
}
129
96
},
@@ -132,6 +99,14 @@ local zigbee_generic_sensor_template = {
132
99
doConfigure = do_configure ,
133
100
infoChanged = info_changed
134
101
},
102
+ sub_drivers = {
103
+ require (" contact" ),
104
+ require (" motion" ),
105
+ require (" waterleak" ),
106
+ require (" motion-illuminance" ),
107
+ require (" meian" ),
108
+ require (" ezviz" )
109
+ },
135
110
ias_zone_configuration_method = constants .IAS_ZONE_CONFIGURE_TYPE .AUTO_ENROLL_RESPONSE
136
111
}
137
112
0 commit comments