@@ -19,6 +19,7 @@ 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
@@ -28,6 +29,7 @@ local ZIGBEE_GENERIC_SENSOR_PROFILE = "generic-sensor"
28
29
local ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE = " generic-contact-sensor"
29
30
local ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE = " generic-motion-sensor"
30
31
local ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE = " generic-waterleak-sensor"
32
+ local ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE = " generic-motion-illuminance"
31
33
32
34
local ZONETYPE = " ZoneType"
33
35
local IASZone = clusters .IASZone
@@ -42,6 +44,7 @@ local do_configure = function(self, device)
42
44
device :configure ()
43
45
device :send (device_management .build_bind_request (device , IASZone .ID , self .environment_info .hub_zigbee_eui ))
44
46
device :send (IASZone .attributes .ZoneStatus :configure_reporting (device , 30 , 300 , 1 ))
47
+ device :send (PowerConfiguration .attributes .BatteryPercentageRemaining :read (device ))
45
48
end
46
49
47
50
local function info_changed (driver , device , event , args )
@@ -55,12 +58,16 @@ local function update_profile(device, zone_type)
55
58
local profile = ZIGBEE_GENERIC_SENSOR_PROFILE
56
59
if zone_type == CONTACT_SWITCH then
57
60
profile = ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE
58
- elseif zone_type == MOTION_SENSOR then
59
- profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE
60
61
elseif zone_type == WATER_SENSOR then
61
62
profile = ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE
63
+ elseif zone_type == MOTION_SENSOR then
64
+ profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE
65
+ for _ , ep in ipairs (device .zigbee_endpoints ) do
66
+ if device :supports_server_cluster (clusters .IlluminanceMeasurement .ID , ep .id ) then
67
+ profile = ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE
68
+ end
69
+ end
62
70
end
63
-
64
71
device :try_update_metadata ({profile = profile })
65
72
end
66
73
@@ -70,44 +77,6 @@ local ias_zone_type_attr_handler = function (driver, device, attr_val)
70
77
update_profile (device , attr_val .value )
71
78
end
72
79
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
80
local zigbee_generic_sensor_template = {
112
81
supported_capabilities = {
113
82
capabilities .battery ,
@@ -117,13 +86,7 @@ local zigbee_generic_sensor_template = {
117
86
zigbee_handlers = {
118
87
attr = {
119
88
[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
89
+ [IASZone .attributes .ZoneType .ID ] = ias_zone_type_attr_handler
127
90
}
128
91
}
129
92
},
@@ -132,6 +95,12 @@ local zigbee_generic_sensor_template = {
132
95
doConfigure = do_configure ,
133
96
infoChanged = info_changed
134
97
},
98
+ sub_drivers = {
99
+ require (" contact" ),
100
+ require (" motion" ),
101
+ require (" waterleak" ),
102
+ require (" motion-illuminance" )
103
+ },
135
104
ias_zone_configuration_method = constants .IAS_ZONE_CONFIGURE_TYPE .AUTO_ENROLL_RESPONSE
136
105
}
137
106
0 commit comments