Skip to content

Commit 4da14bb

Browse files
committed
add Aqara Wireless Remote Switch H1(Single/Double)
1 parent b53f7bb commit 4da14bb

File tree

5 files changed

+216
-49
lines changed

5 files changed

+216
-49
lines changed

drivers/SmartThings/zigbee-button/fingerprints.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ zigbeeManufacturer:
2424
manufacturer: LUMI
2525
model: lumi.remote.b286acn03
2626
deviceProfileName: aqara-double-buttons
27+
- id: "LUMI/lumi.remote.b18ac1"
28+
deviceLabel: Aqara Wireless Remote Switch H1 (Single Rocker)
29+
manufacturer: LUMI
30+
model: lumi.remote.b18ac1
31+
deviceProfileName: aqara-single-button-mode
32+
- id: "LUMI/lumi.remote.b28ac1"
33+
deviceLabel: Aqara Wireless Remote Switch H1 (Double Rocker)
34+
manufacturer: LUMI
35+
model: lumi.remote.b28ac1
36+
deviceProfileName: aqara-double-buttons-mode
2737
- id: "HEIMAN/SOS-EM"
2838
deviceLabel: HEIMAN Button
2939
manufacturer: HEIMAN
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: aqara-double-buttons-mode
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
33+
preferences:
34+
- preferenceId: stse.allowOperationModeChange
35+
explicit: true
36+
# - name: "modeSwitch"
37+
# title: "Mode switching"
38+
# description: "Setting for Mode Change Feature Activation"
39+
# required: true
40+
# preferenceType: boolean
41+
# definition:
42+
# default: false
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: aqara-single-button-mode
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
15+
preferences:
16+
- preferenceId: stse.allowOperationModeChange
17+
explicit: true
18+
# - name: "modeSwitch"
19+
# title: "Mode switching"
20+
# description: "Setting for Mode Change Feature Activation"
21+
# required: true
22+
# preferenceType: boolean
23+
# definition:
24+
# default: false

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

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ local data_types = require "st.zigbee.data_types"
1919
local capabilities = require "st.capabilities"
2020
local button_utils = require "button_utils"
2121

22+
local MODE = "devicemode"
23+
local MODE_CHANGE = "stse.allowOperationModeChange"
24+
local SUPPORTED_BUTTON = { { "pushed" }, { "pushed", "held", "double" } }
2225

2326
local PowerConfiguration = clusters.PowerConfiguration
2427
local PRIVATE_CLUSTER_ID = 0xFCC0
2528
local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
2629
local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125
30+
local PRIVATE_ATTRIBUTE_ID_ALIVE = 0x00F7
2731
local MFG_CODE = 0x115F
2832

2933
local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
@@ -34,7 +38,9 @@ local FINGERPRINTS = {
3438
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1 },
3539
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1 },
3640
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1 },
37-
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 }
41+
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 },
42+
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1 },
43+
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3 }
3844
}
3945

4046
local configuration = {
@@ -81,6 +87,36 @@ local function battery_level_handler(driver, device, value, zb_rx)
8187
device:emit_event(capabilities.batteryLevel.battery(batteryLevel))
8288
end
8389

90+
local function mode_switching_handler(driver, device, value, zb_rx)
91+
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
92+
local allow = device.preferences[MODE_CHANGE] or false
93+
if allow then
94+
local mode = device:get_field(MODE) or 1
95+
mode = 3 - mode
96+
device:set_field(MODE, mode, { persist = true })
97+
device:send(cluster_base.write_manufacturer_specific_attribute(device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1,
98+
MFG_CODE, data_types.Uint8, mode))
99+
device:emit_event(capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
100+
{ visibility = { displayed = false } }))
101+
device:emit_event(capabilities.button.numberOfButtons({ value = 1 }))
102+
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
103+
capabilities.button.button.pushed({ state_change = false }))
104+
if btn_evt_cnt > 1 then
105+
for i = 1, btn_evt_cnt do
106+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
107+
capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
108+
{ visibility = { displayed = false } }))
109+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
110+
capabilities.button.numberOfButtons({ value = 1 }))
111+
device:emit_component_event(device.profile.components[COMP_LIST[i]],
112+
capabilities.button.button.pushed({ state_change = false }))
113+
button_utils.emit_event_if_latest_state_missing(device, COMP_LIST[i], capabilities.button,
114+
capabilities.button.button.NAME, capabilities.button.button.pushed({ state_change = false }))
115+
end
116+
end
117+
end
118+
end
119+
84120
local is_aqara_products = function(opts, driver, device)
85121
local isAqaraProducts = false
86122
if FINGERPRINTS[device:get_model()] and FINGERPRINTS[device:get_model()].mfr == device:get_manufacturer() then
@@ -100,8 +136,18 @@ end
100136

101137
local function added_handler(self, device)
102138
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
103-
104-
device:emit_event(capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
139+
local mode = device:get_field(MODE) or 0
140+
local model = device:get_model()
141+
142+
if mode == 0 then
143+
if model == "lumi.remote.b18ac1" or model == "lumi.remote.b28ac1" then
144+
mode = 1
145+
else
146+
mode = 2
147+
end
148+
end
149+
device:set_field(MODE, mode, { persist = true })
150+
device:emit_event(capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
105151
{ visibility = { displayed = false } }))
106152
device:emit_event(capabilities.button.numberOfButtons({ value = 1 }))
107153
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
@@ -113,7 +159,7 @@ local function added_handler(self, device)
113159
if btn_evt_cnt > 1 then
114160
for i = 1, btn_evt_cnt do
115161
device:emit_component_event(device.profile.components[COMP_LIST[i]],
116-
capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
162+
capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
117163
{ visibility = { displayed = false } }))
118164
device:emit_component_event(device.profile.components[COMP_LIST[i]],
119165
capabilities.button.numberOfButtons({ value = 1 }))
@@ -157,6 +203,9 @@ local aqara_wireless_switch_handler = {
157203
},
158204
[PowerConfiguration.ID] = {
159205
[PowerConfiguration.attributes.BatteryVoltage.ID] = battery_level_handler
206+
},
207+
[PRIVATE_CLUSTER_ID] = {
208+
[PRIVATE_ATTRIBUTE_ID_ALIVE] = mode_switching_handler
160209
}
161210
}
162211
},

0 commit comments

Comments
 (0)