Repository navigation
[WWSTCERT-13462, WWSTCERT-13465] Sonoff SWV2C valve support #3171
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
yezi289
wants to merge
7
commits into
SmartThingsCommunity:main
Choose a base branch
from
yezi289:swv2c
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
7 commits
Select commit
Hold shift + click to select a range
3b3aab5
feat:sonoff swv2c valve
yezi289 f74c63f
Zigbee Value:
yezi289 3c864f7
Address SWV2C review feedback
yezi289 a4565e0
Configure SWV2C reporting and fix integration tests
yezi289 e5e09ae
Remove duplicate Zigbee valve health check setting
yezi289 6a14233
Merge upstream main into SWV2C PR
yezi289 92b8fbe
Merge branch 'main' into swv2c
KKlimczukS 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
21 changes: 21 additions & 0 deletions
21
drivers/SmartThings/zigbee-valve/profiles/valve-battery-2.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,21 @@ | ||
| name: valve-battery-2 | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: valve | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: powerSource | ||
| version: 1 | ||
| config: | ||
| values: | ||
| - key: "powerSource.value" | ||
| enabledValues: | ||
| - battery | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: WaterValve |
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,10 @@ | ||
| name: valve | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: valve | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| categories: | ||
| - name: WaterValve |
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
18 changes: 18 additions & 0 deletions
18
drivers/SmartThings/zigbee-valve/src/sonoff/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,18 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local FINGERPRINTS = { | ||
| { mfr = "SONOFF", model = "SWV-ZF2U" }, | ||
| { mfr = "SONOFF", model = "SWV-ZF2" } | ||
| } | ||
|
|
||
| local function sonoff_can_handle(opts, driver, device, ...) | ||
| for _, fingerprint in ipairs(FINGERPRINTS) do | ||
| if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then | ||
| return true, require "sonoff" | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| return sonoff_can_handle |
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,131 @@ | ||
| -- Copyright 2026 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local capabilities = require "st.capabilities" | ||
| local log = require "log" | ||
| local zcl_clusters = require "st.zigbee.zcl.clusters" | ||
| local Basic = zcl_clusters.Basic | ||
| local OnOff = zcl_clusters.OnOff | ||
| local PowerConfiguration = zcl_clusters.PowerConfiguration | ||
| local st_device = require "st.device" | ||
| local utils = require "st.utils" | ||
|
|
||
| local CONFIGURATION = { | ||
| { | ||
| cluster = PowerConfiguration.ID, | ||
| attribute = PowerConfiguration.attributes.BatteryPercentageRemaining.ID, | ||
| minimum_interval = 30, | ||
| maximum_interval = 21600, | ||
| data_type = PowerConfiguration.attributes.BatteryPercentageRemaining.base_type, | ||
| reportable_change = 1 | ||
| }, | ||
| { | ||
| cluster = OnOff.ID, | ||
| attribute = OnOff.attributes.OnOff.ID, | ||
| minimum_interval = 0, | ||
| maximum_interval = 600, | ||
| data_type = OnOff.attributes.OnOff.base_type | ||
| } | ||
| } | ||
|
|
||
| local function find_child(parent, ep_id) | ||
| return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id)) | ||
| end | ||
|
|
||
| --- OnOff Property Reporting → Valve Capability Point Event | ||
| local function onoff_attr_handler(driver, device, value, zb_rx) | ||
| local ep = zb_rx.address_header.src_endpoint.value | ||
| local target = device | ||
| if ep == 0x02 then | ||
| local child = find_child(device, 2) | ||
| if child then target = child end | ||
| end | ||
| log.info(string.format("[SWV] OnOff report ep=%s value=%s", tostring(ep), tostring(value.value))) | ||
| if value.value == true or value.value == 1 then | ||
| target:emit_event(capabilities.valve.valve.open()) | ||
| else | ||
| target:emit_event(capabilities.valve.valve.closed()) | ||
| end | ||
| end | ||
|
|
||
| --- Battery Percentage Attribute Handler | ||
| local function battery_percentage_handler(driver, device, value) | ||
| device:emit_event(capabilities.battery.battery(utils.round(value.value / 2))) | ||
| end | ||
|
|
||
| --- Lifecycle initialization handler | ||
| local function device_init(driver, device) | ||
| if device.network_type == st_device.NETWORK_TYPE_ZIGBEE then | ||
| device:set_find_child(find_child) | ||
| for _, attribute in ipairs(CONFIGURATION) do | ||
| device:add_configured_attribute(attribute) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| --- doConfigure | ||
| local function do_configure(driver, device) | ||
| if device.network_type == st_device.NETWORK_TYPE_ZIGBEE then | ||
| device:refresh() | ||
| device:configure() | ||
| end | ||
| end | ||
|
|
||
| --- added | ||
| local function device_added(driver, device) | ||
| if device.network_type == st_device.NETWORK_TYPE_ZIGBEE then | ||
| if find_child(device, 2) == nil then | ||
| driver:try_create_device({ | ||
| type = "EDGE_CHILD", | ||
| label = string.format("%s 2", device.label), | ||
| profile = "valve", | ||
| parent_device_id = device.id, | ||
| parent_assigned_child_key = string.format("%02X", 2), | ||
| vendor_provided_label = string.format("%s 2", device.label), | ||
| }) | ||
| end | ||
| end | ||
| device:refresh() | ||
| end | ||
|
|
||
| --- driverSwitched | ||
| local function driver_switched(driver, device) | ||
| device_added(driver, device) | ||
| end | ||
|
|
||
| --- Identity cluster handler:button pressed on the device, sync valve states | ||
| local function identify_handler(driver, device, zb_rx) | ||
| log.info("[SWV] Identify received, syncing valve states") | ||
| device.thread:call_with_delay(2, function() | ||
| device:send(OnOff.attributes.OnOff:read(device)) | ||
| device:send(OnOff.attributes.OnOff:read(device):to_endpoint(0x02)) | ||
| end) | ||
| end | ||
|
|
||
| local sonoff_valve_handler = { | ||
| NAME = "SONOFF Water Valve Handler", | ||
| lifecycle_handlers = { | ||
| init = device_init, | ||
| added = device_added, | ||
| doConfigure = do_configure, | ||
| driverSwitched = driver_switched, | ||
| }, | ||
| zigbee_handlers = { | ||
| attr = { | ||
| [OnOff.ID] = { | ||
| [OnOff.attributes.OnOff.ID] = onoff_attr_handler | ||
| }, | ||
| [PowerConfiguration.ID] = { | ||
| [PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = battery_percentage_handler | ||
| } | ||
| }, | ||
| cluster = { | ||
| [Basic.ID] = { | ||
| [Basic.server.commands.ResetToFactoryDefaults.ID] = identify_handler | ||
| } | ||
| } | ||
| }, | ||
| can_handle = require "sonoff.can_handle", | ||
| } | ||
|
|
||
| return sonoff_valve_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.
Uh oh!
There was an error while loading. Please reload this page.