-
Notifications
You must be signed in to change notification settings - Fork 533
Expand file tree
/
Copy pathinit.lua
More file actions
executable file
·71 lines (60 loc) · 2.34 KB
/
init.lua
File metadata and controls
executable file
·71 lines (60 loc) · 2.34 KB
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
-- Copyright 2026 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local clusters = require "st.zigbee.zcl.clusters"
local configurationMap = require "configurations"
local capabilities = require "st.capabilities"
local IASZone = clusters.IASZone
local function generate_event_from_zone_status(driver, device, zone_status, zb_rx)
device:emit_event(zone_status:is_alarm1_set() and capabilities.contactSensor.contact.open() or capabilities.contactSensor.contact.closed())
if device:supports_capability_by_id(capabilities.tamperAlert.ID) then
device:emit_event(zone_status:is_tamper_set() and capabilities.tamperAlert.tamper.detected() or capabilities.tamperAlert.tamper.clear())
end
end
local function ias_zone_status_attr_handler(driver, device, attr_val, zb_rx)
generate_event_from_zone_status(driver, device, attr_val, zb_rx)
end
local function ias_zone_status_change_handler(driver, device, zb_rx)
generate_event_from_zone_status(driver, device, zb_rx.body.zcl_body.zone_status, zb_rx)
end
local function device_init(driver, device)
device:remove_configured_attribute(IASZone.ID, IASZone.attributes.ZoneStatus.ID)
device:remove_monitored_attribute(IASZone.ID, IASZone.attributes.ZoneStatus.ID)
local configuration = configurationMap.get_device_configuration(device)
if configuration ~= nil then
for _, attribute in ipairs(configuration) do
device:add_configured_attribute(attribute)
end
end
end
local function added_handler(driver, device)
device:emit_event(capabilities.battery.battery(100))
device:emit_event(capabilities.contactSensor.contact.closed())
if device:supports_capability_by_id(capabilities.tamperAlert.ID) then
device:emit_event(capabilities.tamperAlert.tamper.clear())
end
end
local function do_configure(driver, device)
device:configure()
end
local MultiIR_sensor = {
NAME = "MultiIR Contact Tamper",
lifecycle_handlers = {
init = device_init,
added = added_handler,
doConfigure = do_configure
},
zigbee_handlers = {
cluster = {
[IASZone.ID] = {
[IASZone.client.commands.ZoneStatusChangeNotification.ID] = ias_zone_status_change_handler,
}
},
attr = {
[IASZone.ID] = {
[IASZone.attributes.ZoneStatus.ID] = ias_zone_status_attr_handler,
}
}
},
can_handle = require("MultiIR.can_handle"),
}
return MultiIR_sensor