Skip to content

Commit b53f7bb

Browse files
authored
WWSTCERT-8471/8468 [Aqara] Wireless Remote Switch T1(Single/Double) (#2458)
* add Aqara Wireless Remote Switch T1(Single/Double) * change the categories of the main component from 'Button' to 'RemoteController' in the 'aqara-double-buttons' profile * Added the firmwareUpdate capability to aqara-single-button.yml and renamed the file to one-button-batteryLevel.yml. * Changing the device profile of Aqara Button Devices * dd the firmwareUpdate capability to the aqara-double-buttons device profile.
1 parent 73c36a8 commit b53f7bb

File tree

5 files changed

+257
-119
lines changed

5 files changed

+257
-119
lines changed

drivers/SmartThings/zigbee-button/fingerprints.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,22 @@ zigbeeManufacturer:
88
deviceLabel: Aqara Wireless Mini Switch T1
99
manufacturer: LUMI
1010
model: lumi.remote.b1acn02
11-
deviceProfileName: one-button-battery
11+
deviceProfileName: one-button-batteryLevel
1212
- id: "LUMI/lumi.remote.acn003"
1313
deviceLabel: Aqara Wireless Remote Switch E1 (Single Rocker)
1414
manufacturer: LUMI
1515
model: lumi.remote.acn003
16-
deviceProfileName: one-button-battery
16+
deviceProfileName: one-button-batteryLevel
17+
- id: "LUMI/lumi.remote.b186acn03"
18+
deviceLabel: Aqara Wireless Remote Switch T1 (Single Rocker)
19+
manufacturer: LUMI
20+
model: lumi.remote.b186acn03
21+
deviceProfileName: one-button-batteryLevel
22+
- id: "LUMI/lumi.remote.b286acn03"
23+
deviceLabel: Aqara Wireless Remote Switch T1 (Double Rocker)
24+
manufacturer: LUMI
25+
model: lumi.remote.b286acn03
26+
deviceProfileName: aqara-double-buttons
1727
- id: "HEIMAN/SOS-EM"
1828
deviceLabel: HEIMAN Button
1929
manufacturer: HEIMAN
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: aqara-double-buttons
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: button
6+
version: 1
7+
- id: batteryLevel
8+
version: 1
9+
- id: firmwareUpdate
10+
version: 1
11+
- id: refresh
12+
version: 1
13+
categories:
14+
- name: RemoteController
15+
- id: button1
16+
capabilities:
17+
- id: button
18+
version: 1
19+
categories:
20+
- name: RemoteController
21+
- id: button2
22+
capabilities:
23+
- id: button
24+
version: 1
25+
categories:
26+
- name: RemoteController
27+
- id: all
28+
capabilities:
29+
- id: button
30+
version: 1
31+
categories:
32+
- name: RemoteController
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: one-button-batteryLevel
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: button
6+
version: 1
7+
- id: batteryLevel
8+
version: 1
9+
- id: firmwareUpdate
10+
version: 1
11+
- id: refresh
12+
version: 1
13+
categories:
14+
- name: Button

drivers/SmartThings/zigbee-button/src/aqara/init.lua

Lines changed: 101 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,74 +29,113 @@ local MFG_CODE = 0x115F
2929
local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
3030
local PRESENT_ATTRIBUTE_ID = 0x0055
3131

32+
local COMP_LIST = { "button1", "button2", "all" }
3233
local FINGERPRINTS = {
33-
{ mfr = "LUMI", model = "lumi.remote.b1acn02" },
34-
{ mfr = "LUMI", model = "lumi.remote.acn003" }
34+
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1 },
35+
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1 },
36+
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1 },
37+
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 }
3538
}
3639

3740
local configuration = {
38-
{
39-
cluster = MULTISTATE_INPUT_CLUSTER_ID,
40-
attribute = PRESENT_ATTRIBUTE_ID,
41-
minimum_interval = 3,
42-
maximum_interval = 7200,
43-
data_type = data_types.Uint16,
44-
reportable_change = 1
45-
},
46-
{
47-
cluster = PowerConfiguration.ID,
48-
attribute = PowerConfiguration.attributes.BatteryVoltage.ID,
49-
minimum_interval = 30,
50-
maximum_interval = 3600,
51-
data_type = PowerConfiguration.attributes.BatteryVoltage.base_type,
52-
reportable_change = 1
53-
}
41+
{
42+
cluster = MULTISTATE_INPUT_CLUSTER_ID,
43+
attribute = PRESENT_ATTRIBUTE_ID,
44+
minimum_interval = 3,
45+
maximum_interval = 7200,
46+
data_type = data_types.Uint16,
47+
reportable_change = 1
48+
},
49+
{
50+
cluster = PowerConfiguration.ID,
51+
attribute = PowerConfiguration.attributes.BatteryVoltage.ID,
52+
minimum_interval = 30,
53+
maximum_interval = 3600,
54+
data_type = PowerConfiguration.attributes.BatteryVoltage.base_type,
55+
reportable_change = 1
56+
}
5457
}
5558

5659
local function present_value_attr_handler(driver, device, value, zb_rx)
57-
if value.value == 1 then
58-
device:emit_event(capabilities.button.button.pushed({state_change = true}))
59-
elseif value.value == 2 then
60-
device:emit_event(capabilities.button.button.double({state_change = true}))
61-
elseif value.value == 0 then
62-
device:emit_event(capabilities.button.button.held({state_change = true}))
63-
end
60+
local end_point = zb_rx.address_header.src_endpoint.value
61+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
62+
local evt = capabilities.button.button.held({ state_change = true })
63+
if value.value == 1 then
64+
evt = capabilities.button.button.pushed({ state_change = true })
65+
elseif value.value == 2 then
66+
evt = capabilities.button.button.double({ state_change = true })
67+
end
68+
device:emit_event(evt)
69+
if btn_evt_cnt > 1 then
70+
device:emit_component_event(device.profile.components[COMP_LIST[end_point]], evt)
71+
end
72+
end
73+
local function battery_level_handler(driver, device, value, zb_rx)
74+
local voltage = value.value
75+
local batteryLevel = "normal"
76+
if voltage <= 25 then
77+
batteryLevel = "critical"
78+
elseif voltage < 28 then
79+
batteryLevel = "warning"
80+
end
81+
device:emit_event(capabilities.batteryLevel.battery(batteryLevel))
6482
end
6583

6684
local is_aqara_products = function(opts, driver, device)
67-
for _, fingerprint in ipairs(FINGERPRINTS) do
68-
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
69-
return true
70-
end
71-
end
72-
return false
85+
local isAqaraProducts = false
86+
if FINGERPRINTS[device:get_model()] and FINGERPRINTS[device:get_model()].mfr == device:get_manufacturer() then
87+
isAqaraProducts = true
88+
end
89+
return isAqaraProducts
7390
end
7491

7592
local function device_init(driver, device)
76-
battery_defaults.build_linear_voltage_init(2.6, 3.0)(driver, device)
77-
if configuration ~= nil then
78-
for _, attribute in ipairs(configuration) do
79-
device:add_configured_attribute(attribute)
80-
end
93+
battery_defaults.build_linear_voltage_init(2.6, 3.0)(driver, device)
94+
if configuration ~= nil then
95+
for _, attribute in ipairs(configuration) do
96+
device:add_configured_attribute(attribute)
8197
end
98+
end
8299
end
83100

84101
local function added_handler(self, device)
85-
device:emit_event(capabilities.button.supportedButtonValues({"pushed","held","double"}, {visibility = { displayed = false }}))
86-
device:emit_event(capabilities.button.numberOfButtons({value = 1}))
87-
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME, capabilities.button.button.pushed({state_change = false}))
88-
device:emit_event(capabilities.battery.battery(100))
102+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
103+
104+
device:emit_event(capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
105+
{ visibility = { displayed = false } }))
106+
device:emit_event(capabilities.button.numberOfButtons({ value = 1 }))
107+
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
108+
capabilities.button.button.pushed({ state_change = false }))
109+
device:emit_event(capabilities.batteryLevel.battery.normal())
110+
device:emit_event(capabilities.batteryLevel.type("CR2032"))
111+
device:emit_event(capabilities.batteryLevel.quantity(1))
112+
113+
if btn_evt_cnt > 1 then
114+
for i = 1, btn_evt_cnt do
115+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
116+
capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
117+
{ visibility = { displayed = false } }))
118+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
119+
capabilities.button.numberOfButtons({ value = 1 }))
120+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
121+
capabilities.button.button.pushed({ state_change = false }))
122+
button_utils.emit_event_if_latest_state_missing(device, COMP_LIST[i], capabilities.button,
123+
capabilities.button.button.NAME, capabilities.button.button.pushed({ state_change = false }))
124+
end
125+
end
89126
end
90127

91128
local function do_configure(driver, device)
129+
local ATTR_ID = PRIVATE_ATTRIBUTE_ID_T1
130+
local cmd_value = 1
131+
92132
device:configure()
93-
if device:get_model() == "lumi.remote.b1acn02" then
94-
device:send(cluster_base.write_manufacturer_specific_attribute(device,
95-
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_T1, MFG_CODE, data_types.Uint8, 1))
96-
elseif device:get_model() == "lumi.remote.acn003" then
97-
device:send(cluster_base.write_manufacturer_specific_attribute(device,
98-
PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1, MFG_CODE, data_types.Uint8, 2))
133+
if device:get_model() == "lumi.remote.acn003" then
134+
ATTR_ID = PRIVATE_ATTRIBUTE_ID_E1
135+
cmd_value = 2
99136
end
137+
device:send(cluster_base.write_manufacturer_specific_attribute(device,
138+
PRIVATE_CLUSTER_ID, ATTR_ID, MFG_CODE, data_types.Uint8, cmd_value))
100139
-- when the wireless switch T1 accesses the network, the gateway sends
101140
-- private attribute 0009 to make the device no longer distinguish
102141
-- between the standard gateway and the aqara gateway.
@@ -105,20 +144,23 @@ local function do_configure(driver, device)
105144
end
106145

107146
local aqara_wireless_switch_handler = {
108-
NAME = "Aqara Wireless Switch Handler",
109-
lifecycle_handlers = {
110-
init = device_init,
111-
added = added_handler,
112-
doConfigure = do_configure
113-
},
114-
zigbee_handlers = {
115-
attr = {
116-
[MULTISTATE_INPUT_CLUSTER_ID] = {
117-
[PRESENT_ATTRIBUTE_ID] = present_value_attr_handler
118-
}
147+
NAME = "Aqara Wireless Switch Handler",
148+
lifecycle_handlers = {
149+
init = device_init,
150+
added = added_handler,
151+
doConfigure = do_configure
152+
},
153+
zigbee_handlers = {
154+
attr = {
155+
[MULTISTATE_INPUT_CLUSTER_ID] = {
156+
[PRESENT_ATTRIBUTE_ID] = present_value_attr_handler
157+
},
158+
[PowerConfiguration.ID] = {
159+
[PowerConfiguration.attributes.BatteryVoltage.ID] = battery_level_handler
119160
}
120-
},
121-
can_handle = is_aqara_products
161+
}
162+
},
163+
can_handle = is_aqara_products
122164
}
123165

124166
return aqara_wireless_switch_handler

0 commit comments

Comments
 (0)