-
Notifications
You must be signed in to change notification settings - Fork 529
Aqara Wireless Knob Switch H1 #2844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
haedo-doo
wants to merge
3
commits into
SmartThingsCommunity:main
Choose a base branch
from
haedo-doo:AqaraWirelessKnobSwitchH1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
drivers/SmartThings/zigbee-button/profiles/aqara-knob-switch.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: aqara-knob-switch | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: button | ||
| version: 1 | ||
| - id: knob | ||
| version: 1 | ||
| - id: batteryLevel | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: Button | ||
| preferences: | ||
| - preferenceId: stse.knobSensitivity | ||
| explicit: true |
13 changes: 13 additions & 0 deletions
13
drivers/SmartThings/zigbee-button/src/aqara-knob/can_handle.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local is_aqara_products = function(opts, driver, device, ...) | ||
| local FINGERPRINTS = { mfr = "LUMI", model = "lumi.remote.rkba01" } | ||
|
|
||
| if device:get_manufacturer() == FINGERPRINTS.mfr and device:get_model() == FINGERPRINTS.model then | ||
| return true, require("aqara-knob") | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| return is_aqara_products |
140 changes: 140 additions & 0 deletions
140
drivers/SmartThings/zigbee-button/src/aqara-knob/init.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local battery_defaults = require "st.zigbee.defaults.battery_defaults" | ||
| local clusters = require "st.zigbee.zcl.clusters" | ||
| local cluster_base = require "st.zigbee.cluster_base" | ||
| local data_types = require "st.zigbee.data_types" | ||
| local capabilities = require "st.capabilities" | ||
| local utils = require "st.utils" | ||
| local button_utils = require "button_utils" | ||
|
|
||
| local PowerConfiguration = clusters.PowerConfiguration | ||
| local PRIVATE_CLUSTER_ID = 0xFCC0 | ||
| local PRIVATE_ATTRIBUTE_ID = 0x0009 | ||
| local MFG_CODE = 0x115F | ||
| local MULTISTATE_INPUT_CLUSTER_ID = 0x0012 | ||
| local PRESENT_ATTRIBUTE_ID = 0x0055 | ||
| local ROTATION_MONITOR_ID = 0x0232 | ||
|
|
||
| local AQARA_KNOB = { | ||
| ["lumi.remote.rkba01"] = { mfr = "LUMI", type = "CR2032", quantity = 2 }, -- Aqara Wireless Knob Switch H1 | ||
| } | ||
|
|
||
|
|
||
| local function device_init(driver, device) | ||
| local configuration = { | ||
| { | ||
| cluster = PowerConfiguration.ID, | ||
| attribute = PowerConfiguration.attributes.BatteryVoltage.ID, | ||
| minimum_interval = 30, | ||
| maximum_interval = 3600, | ||
| data_type = PowerConfiguration.attributes.BatteryVoltage.base_type, | ||
| reportable_change = 1 | ||
| } | ||
| } | ||
|
|
||
| battery_defaults.build_linear_voltage_init(2.6, 3.0)(driver, device) | ||
| for _, attribute in ipairs(configuration) do | ||
| device:add_configured_attribute(attribute) | ||
| end | ||
| end | ||
|
|
||
| local function device_added(self, device) | ||
| local model = device:get_model() | ||
| local type = AQARA_KNOB[model].type or "CR2032" | ||
| local quantity = AQARA_KNOB[model].quantity or 1 | ||
|
|
||
| device:emit_event(capabilities.button.supportedButtonValues({ "pushed", "held", "double" }, { 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})) | ||
| device:emit_event(capabilities.batteryLevel.battery.normal()) | ||
| device:emit_event(capabilities.batteryLevel.type(type)) | ||
| device:emit_event(capabilities.batteryLevel.quantity(quantity)) | ||
| device:emit_event(capabilities.knob.rotateAmount({value = 0, unit = "%"})) | ||
| device:emit_event(capabilities.knob.heldRotateAmount({value = 0, unit = "%"})) | ||
| end | ||
|
|
||
| local function do_configure(driver, device) | ||
| device:configure() | ||
| device:send(cluster_base.write_manufacturer_specific_attribute(device, | ||
| PRIVATE_CLUSTER_ID, PRIVATE_ATTRIBUTE_ID, MFG_CODE, data_types.Uint8, 1)) | ||
| device:emit_event(capabilities.knob.supportedAttributes({"rotateAmount", "heldRotateAmount"}, {state_change = true})) | ||
| end | ||
|
|
||
| local function button_monitor_handler(driver, device, value, zb_rx) | ||
| local val = value.value | ||
|
|
||
| if val == 1 then -- push | ||
| device:emit_event(capabilities.button.button.pushed({ state_change = true })) | ||
| elseif val == 2 then -- dobule push | ||
| device:emit_event(capabilities.button.button.double({ state_change = true })) | ||
| elseif val == 0 then -- down_hold | ||
| device:emit_event(capabilities.button.button.held({ state_change = true })) | ||
| end | ||
| end | ||
|
|
||
| local function rotation_monitor_per_handler(driver, device, value, zb_rx) | ||
| local SENSITIVITY_KEY = "stse.knobSensitivity" | ||
| local SENSITIVITY_FACTORS = {0.5, 1.0, 2.0} | ||
|
|
||
| local end_point = zb_rx.address_header.src_endpoint.value | ||
| local raw_val = utils.round(value.value) | ||
| if raw_val > 0x7FFF then | ||
| raw_val = raw_val - 0x10000 | ||
| end | ||
| local sensitivity = tonumber(device.preferences[SENSITIVITY_KEY]) | ||
| local factor = SENSITIVITY_FACTORS[sensitivity] or 1.0 | ||
| local intermediate_val = raw_val * factor | ||
| local sign = (intermediate_val > 0 and 1) or (intermediate_val < 0 and -1) or 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very lua-y. Nice! |
||
| local val = math.floor(math.abs(intermediate_val) + 0.5) * sign | ||
| val = math.max(-100, math.min(100, val)) | ||
|
|
||
| if val == 0 then | ||
| return | ||
| elseif end_point == 0x47 then -- normal | ||
| device:emit_event(capabilities.knob.rotateAmount({value = val, unit = "%"}, {state_change = true})) | ||
| elseif end_point == 0x48 then -- press | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indentation should be fixed |
||
| device:emit_event(capabilities.knob.heldRotateAmount({value = val, unit = "%"}, {state_change = true})) | ||
| end | ||
| end | ||
|
|
||
| local function battery_level_handler(driver, device, value, zb_rx) | ||
| local voltage = value.value | ||
| local batteryLevel = "normal" | ||
|
|
||
| if voltage <= 25 then | ||
| batteryLevel = "critical" | ||
| elseif voltage < 28 then | ||
| batteryLevel = "warning" | ||
| end | ||
|
|
||
| device:emit_event(capabilities.batteryLevel.battery(batteryLevel)) | ||
| end | ||
|
|
||
| local aqara_knob_switch_handler = { | ||
| NAME = "Aqara Wireless Knob Switch Handler", | ||
| lifecycle_handlers = { | ||
| init = device_init, | ||
| added = device_added, | ||
| doConfigure = do_configure | ||
| }, | ||
| zigbee_handlers = { | ||
| attr = { | ||
| [MULTISTATE_INPUT_CLUSTER_ID] = { | ||
| [PRESENT_ATTRIBUTE_ID] = button_monitor_handler | ||
| }, | ||
| [PRIVATE_CLUSTER_ID] = { | ||
| [ROTATION_MONITOR_ID] = rotation_monitor_per_handler | ||
| }, | ||
| [PowerConfiguration.ID] = { | ||
| [PowerConfiguration.attributes.BatteryVoltage.ID] = battery_level_handler | ||
| }, | ||
| } | ||
| }, | ||
|
|
||
| can_handle = require("aqara-knob.can_handle"), | ||
| } | ||
|
|
||
| return aqara_knob_switch_handler | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a comment here about what this attribute write is doing would be nice to understand why it is needed.