Skip to content

WWSTCERT-9467 Add Sonoff SNZB-01M Smart Scene Button into zigbee-button.#2510

Open
Oniums wants to merge 8 commits intoSmartThingsCommunity:mainfrom
Oniums:main
Open

WWSTCERT-9467 Add Sonoff SNZB-01M Smart Scene Button into zigbee-button.#2510
Oniums wants to merge 8 commits intoSmartThingsCommunity:mainfrom
Oniums:main

Conversation

@Oniums
Copy link

@Oniums Oniums commented Oct 30, 2025

Check all that apply

Type of Change

  • WWST Certification Request
    • If this is your first time contributing code:
      • I have reviewed the README.md file
      • I have reviewed the CODE_OF_CONDUCT.md file
      • I have signed the CLA
    • I plan on entering a WWST Certification Request or have entered a request through the WWST Certification console at developer.smartthings.com
  • Bug fix
  • New feature
  • Refactor

Checklist

  • I have performed a self-review of my code
  • I have commented my code in hard-to-understand areas
  • I have verified my changes by testing with a device or have communicated a plan for testing
  • I am adding new behavior, such as adding a sub-driver, and have added and run new unit tests to cover the new behavior

Description of Change

This PR adds support for the Sonoff SNZB-01M Smart Scene Button to the existing zigbee-button driver.

Changes made:

  1. Added device fingerprint in fingerprints.yml to recognize the SONOFF SNZB-01M device
  2. Created device profile sonoff-buttons-battery.yml with 4 button components and battery capability
  3. Implemented custom handler in src/zigbee-multi-button/sonoff/init.lua to handle SONOFF-specific Zigbee communication
  4. Added device support to the multi-button matching matrix with support for 4 button actions: pushed, double, held, pushed_3x
  5. Created test file test_sonoff_button.lua for verification purposes

Summary of Completed Tests

Device Testing:

  • Device pairing: Successfully paired SONOFF SNZB-01M with SmartThings Hub
  • Button actions: Verified all 4 button types work correctly:
    • Single press (pushed)
    • Double press (double)
    • Long press (held)
    • Triple press (pushed_3x)
  • Battery reporting: Confirmed battery percentage is correctly displayed in SmartThings app
  • Endpoint mapping: Verified button events are properly mapped to correct button components (button1-button4)

Code Testing:

  • Fingerprint recognition: Device correctly identified during pairing process
  • Profile loading: Device profile loaded successfully with all 4 button components
  • Event handling: Custom SONOFF handler processes Zigbee messages correctly
  • Integration: No conflicts with existing button drivers

Compatibility:

  • SmartThings Hub compatibility: Tested on SmartThings Hub v3
  • Driver integration: Successfully integrates with existing zigbee-button driver framework
  • No regression: Existing button devices continue to function normally

@@ -0,0 +1,87 @@
-- Copyright 2024 SmartThings

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update date

@@ -0,0 +1,26 @@
-- Test file for SONOFF SNZB-01M integration

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add copyright info.

end
end

return test No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add some proper unit tests utiliizing expect_send and expect_receive. More details can be found here

@github-actions
Copy link

Duplicate profile check: Passed - no duplicate profiles detected.

@github-actions
Copy link

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

Test Results

   72 files    493 suites   0s ⏱️
2 695 tests 2 690 ✅ 0 💤 0 ❌ 5 🔥
4 557 runs  4 552 ✅ 0 💤 0 ❌ 5 🔥

For more details on these errors, see this check.

Results for commit 61d1077.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Dec 13, 2025

File Coverage
All files 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/heiman/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/zunzunbee/init.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/iris/init.lua 89%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/vimar/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/robb/init.lua 99%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/shinasystems/init.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/sonoff/init.lua 70%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/frient/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/adurosmart/init.lua 97%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/aqara/init.lua 94%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/pushButton/init.lua 76%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/init.lua 83%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/supported_values.lua 99%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/SLED/init.lua 95%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/wallhero/init.lua 87%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/button_utils.lua 92%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/init.lua 96%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/lazy_load_subdriver.lua 57%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ikea/TRADFRI_remote_control/init.lua 98%
/home/runner/work/SmartThingsEdgeDrivers/SmartThingsEdgeDrivers/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/somfy/somfy_situo_4/init.lua 98%

Minimum allowed coverage is 90%

Generated by 🐒 cobertura-action against 61d1077

@@ -0,0 +1,261 @@
-- Copyright 2022 SmartThings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date

local function battery_attr_handler(driver, device, value, zb_rx)
local percent = math.floor((value.value or 0) / 2)
device:emit_event(capabilities.battery.battery(percent))
log.info(string.format("Battery percentage remaining: %d%%", percent))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log line

local endpoint = zb_rx.address_header.src_endpoint.value
local button_name = "button" .. tostring(endpoint)
local event_func = EVENT_MAP[attr_val]
log.info(string.format("SONOFF attr: endpoint=%s, value=%s, button=%s", endpoint, attr_val, button_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this log line

@greens
Copy link
Contributor

greens commented Feb 5, 2026

Checking drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua 8 warnings

    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:67:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:143:122: (W612) line contains trailing whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:145:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:161:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:180:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:199:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:218:1: (W611) line contains only whitespace
    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:253:1: (W611) line contains only whitespace

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid duplication here, I'd recommend you use the existing profile four-buttons-without-main-button

Comment on lines +34 to +37
local function battery_attr_handler(driver, device, value, zb_rx)
local percent = math.floor((value.value or 0) / 2)
device:emit_event(capabilities.battery.battery(percent))
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be handled by the defaults

Comment on lines +133 to +139
},
SONOFF_BUTTON_4 = {
MATCHING_MATRIX = {
{ mfr = "SONOFF", model = "SNZB-01M" }
},
SUPPORTED_BUTTON_VALUES = { "pushed", "double", "held", "pushed_3x" },
NUMBER_OF_BUTTONS = 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you overwrote added in your handler (because you did not include the button capability on your main component, this info is never used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I checked the existing profiles: four-buttons-without-main-button has no battery capability, while four-buttons-battery includes button on main, which doesn’t match the SNZB-01M capability layout. Would you prefer that I: use four-buttons-without-main-button and accept no battery on main, or use the profile I added earlier.

Copy link
Contributor

@greens greens Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why you've added the new profile, but I'll advise you on why our multi-button profiles include the button capability on the main component: without it (and duplicating any other buttons' events to main, the remote on the device list will not change to indicate button presses. You'll only see them within the device details page.

I didn't notice four-buttons-without-main-button didn't have battery. I definitely think you should maintain that.

So you can go with your new profile if you like, but this comment was merely pointing out that, because these values are only used in the zigbee-multi-button added handler, your additions to this file are not used.

@greens
Copy link
Contributor

greens commented Feb 10, 2026

Checking drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua 1 warning

    drivers/SmartThings/zigbee-button/src/test/test_sonoff_button.lua:143:122: (W612) line contains trailing whitespace

@CLAassistant
Copy link

CLAassistant commented Feb 25, 2026

CLA assistant check
All committers have signed the CLA.

Comment on lines +42 to +45
log.warn("Unknown button component: " .. button_name)
end
else
log.warn("Unknown event value: " .. tostring(attr_val))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these log statements

@greens
Copy link
Contributor

greens commented Feb 27, 2026

driver needs to be rebased

@Oniums
Copy link
Author

Oniums commented Mar 6, 2026

Is the rebase based on this PR? If I submit a new PR, will it cause any issues if it doesn’t match the PR used for the Samsung certification application?

@greens
Copy link
Contributor

greens commented Mar 9, 2026

@Oniums you should be able to set your fork's upstream to our main repo, update the main branch there, then rebase your changes on your local branch onto main:

In your fork's directory:

git remote add upstream git@github.com:SmartThingsCommunity/SmartThingsEdgeDrivers.git
git checkout upstream/main
git pull
git checkout main
git rebase upstream/main

Then you should be able to resolve the conflicts and git push --force up your changes.

Oniums added 2 commits March 10, 2026 09:12
- Remove custom battery attribute handler and added lifecycle in Sonoff subdriver
- Align Sonoff tests with default added behavior and keep battery report coverage
end
)

return test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests are not being run.

Your test should end with test.run_registered_tests().

If you had run your tests, you would see that they fail, because you have not actually added your sub-driver to the base driver. You need to use this file: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/sub_drivers.lua a and also change how your can_handle function is written and broken out. Here's an example: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-button/src/zigbee-multi-button/ecosmart/can_handle.lua

Your directory structure should look like all the other sub-drivers'

@greens greens changed the title Add Sonoff SNZB-01M Smart Scene Button into zigbee-button. WWSTCERT-9467 Add Sonoff SNZB-01M Smart Scene Button into zigbee-button. Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants