Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions drivers/SmartThings/zigbee-button/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ zigbeeManufacturer:
manufacturer: LUMI
model: lumi.remote.b286acn03
deviceProfileName: aqara-double-buttons
- id: "LUMI/lumi.remote.b18ac1"
deviceLabel: Aqara Wireless Remote Switch H1 (Single Rocker)
manufacturer: LUMI
model: lumi.remote.b18ac1
deviceProfileName: aqara-single-button-mode
- id: "LUMI/lumi.remote.b28ac1"
deviceLabel: Aqara Wireless Remote Switch H1 (Double Rocker)
manufacturer: LUMI
model: lumi.remote.b28ac1
deviceProfileName: aqara-double-buttons-mode
- id: "HEIMAN/SOS-EM"
deviceLabel: HEIMAN Button
manufacturer: HEIMAN
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: aqara-double-buttons-mode
components:
- id: main
capabilities:
- id: button
version: 1
- id: batteryLevel
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: RemoteController
- id: button1
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: all
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
preferences:
- preferenceId: stse.allowOperationModeChange
explicit: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: aqara-single-button-mode
components:
- id: main
capabilities:
- id: button
version: 1
- id: batteryLevel
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Button
preferences:
- preferenceId: stse.allowOperationModeChange
explicit: true
57 changes: 53 additions & 4 deletions drivers/SmartThings/zigbee-button/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ local data_types = require "st.zigbee.data_types"
local capabilities = require "st.capabilities"
local button_utils = require "button_utils"

local MODE = "devicemode"
local MODE_CHANGE = "stse.allowOperationModeChange"
local SUPPORTED_BUTTON = { { "pushed" }, { "pushed", "held", "double" } }

local PowerConfiguration = clusters.PowerConfiguration
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID_T1 = 0x0009
local PRIVATE_ATTRIBUTE_ID_E1 = 0x0125
local PRIVATE_ATTRIBUTE_ID_ALIVE = 0x00F7
local MFG_CODE = 0x115F

local MULTISTATE_INPUT_CLUSTER_ID = 0x0012
Expand All @@ -34,7 +38,9 @@ local FINGERPRINTS = {
["lumi.remote.b1acn02"] = { mfr = "LUMI", btn_cnt = 1 },
["lumi.remote.acn003"] = { mfr = "LUMI", btn_cnt = 1 },
["lumi.remote.b186acn03"] = { mfr = "LUMI", btn_cnt = 1 },
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 }
["lumi.remote.b286acn03"] = { mfr = "LUMI", btn_cnt = 3 },
["lumi.remote.b18ac1"] = { mfr = "LUMI", btn_cnt = 1 },
["lumi.remote.b28ac1"] = { mfr = "LUMI", btn_cnt = 3 }
}

local configuration = {
Expand Down Expand Up @@ -101,6 +107,36 @@ local function battery_level_handler(driver, device, value, zb_rx)
end
end

local function mode_switching_handler(driver, device, value, zb_rx)
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1
local allow = device.preferences[MODE_CHANGE] or false
if allow then
local mode = device:get_field(MODE) or 1
mode = 3 - mode
device:set_field(MODE, mode, { persist = true })
device:send(cluster_base.write_manufacturer_specific_attribute(device, PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID_E1,
MFG_CODE, data_types.Uint8, mode))
device:emit_event(capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
{ visibility = { displayed = false } }))
device:emit_event(capabilities.button.numberOfButtons({ value = 1 }))
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
capabilities.button.button.pushed({ state_change = false }))
if btn_evt_cnt > 1 then
for i = 1, btn_evt_cnt do
device:emit_component_event(device.profile.components[COMP_LIST[i]],
capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
{ visibility = { displayed = false } }))
device:emit_component_event(device.profile.components[COMP_LIST[i]],
capabilities.button.numberOfButtons({ value = 1 }))
device:emit_component_event(device.profile.components[COMP_LIST[i]],
capabilities.button.button.pushed({ state_change = false }))
button_utils.emit_event_if_latest_state_missing(device, COMP_LIST[i], capabilities.button,
capabilities.button.button.NAME, capabilities.button.button.pushed({ state_change = false }))
end
end
end
end

local is_aqara_products = function(opts, driver, device)
local isAqaraProducts = false
if FINGERPRINTS[device:get_model()] and FINGERPRINTS[device:get_model()].mfr == device:get_manufacturer() then
Expand All @@ -120,8 +156,18 @@ end

local function added_handler(self, device)
local btn_evt_cnt = FINGERPRINTS[device:get_model()].btn_cnt or 1

device:emit_event(capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
local mode = device:get_field(MODE) or 0
local model = device:get_model()

if mode == 0 then
if model == "lumi.remote.b18ac1" or model == "lumi.remote.b28ac1" then
mode = 1
else
mode = 2
end
end
device:set_field(MODE, mode, { persist = true })
device:emit_event(capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
{ visibility = { displayed = false } }))
device:emit_event(capabilities.button.numberOfButtons({ value = 1 }))
button_utils.emit_event_if_latest_state_missing(device, "main", capabilities.button, capabilities.button.button.NAME,
Expand All @@ -133,7 +179,7 @@ local function added_handler(self, device)
if btn_evt_cnt > 1 then
for i = 1, btn_evt_cnt do
device:emit_component_event(device.profile.components[COMP_LIST[i]],
capabilities.button.supportedButtonValues({ "pushed", "held", "double" },
capabilities.button.supportedButtonValues(SUPPORTED_BUTTON[mode],
{ visibility = { displayed = false } }))
device:emit_component_event(device.profile.components[COMP_LIST[i]],
capabilities.button.numberOfButtons({ value = 1 }))
Expand Down Expand Up @@ -177,6 +223,9 @@ local aqara_wireless_switch_handler = {
},
[PowerConfiguration.ID] = {
[PowerConfiguration.attributes.BatteryVoltage.ID] = battery_level_handler
},
[PRIVATE_CLUSTER_ID] = {
[PRIVATE_ATTRIBUTE_ID_ALIVE] = mode_switching_handler
}
}
},
Expand Down
Loading
Loading