-
Notifications
You must be signed in to change notification settings - Fork 484
generic_zigbee_sensor_improvement #2093
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
pInksenberg
wants to merge
1
commit into
SmartThingsCommunity:main
Choose a base branch
from
pInksenberg:generic_zigbee_sensor_improvement
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
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
20 changes: 20 additions & 0 deletions
20
drivers/SmartThings/zigbee-sensor/profiles/generic-motion-illuminance.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,20 @@ | ||
name: generic-motion-illuminance | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: motionSensor | ||
version: 1 | ||
- id: illuminanceMeasurement | ||
version: 1 | ||
config: | ||
values: | ||
- key: "illuminance.value" | ||
range: [0, 32000] | ||
- id: battery | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: MotionSensor |
14 changes: 14 additions & 0 deletions
14
drivers/SmartThings/zigbee-sensor/profiles/generic-remote-control.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,14 @@ | ||
name: generic-remote-control | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: button | ||
version: 1 | ||
- id: battery | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: Button |
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,32 @@ | ||
-- Copyright 2025 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local defaults = require "st.zigbee.defaults" | ||
local capabilities = require "st.capabilities" | ||
|
||
local is_contact_sensor = function(opts, driver, device) | ||
if device:supports_capability(capabilities.contactSensor) then | ||
return true | ||
end | ||
end | ||
|
||
local generic_contact_sensor = { | ||
NAME = "Generic Contact Sensor", | ||
supported_capabilities = { | ||
capabilities.contactSensor | ||
}, | ||
can_handle = is_contact_sensor | ||
} | ||
defaults.register_for_default_handlers(generic_contact_sensor, generic_contact_sensor.supported_capabilities) | ||
return generic_contact_sensor |
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,70 @@ | ||
-- Copyright 2025 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local capabilities = require "st.capabilities" | ||
local defaults = require "st.zigbee.defaults" | ||
|
||
local EZVIZ_PRIVATE_CLUSTER = 0xFE05 | ||
local EZVIZ_PRIVATE_ATTRIBUTE = 0x0000 | ||
|
||
local EZVIZ_MFR = "EZVIZ" | ||
|
||
local is_ezviz_button = function(opts, driver, device) | ||
if device:supports_capability(capabilities.button) and device:get_manufacturer() == EZVIZ_MFR then | ||
return true | ||
end | ||
end | ||
|
||
-- We need an empty added here to override the added in root init.lua, because we already knows its profile | ||
local device_added = function(self, device) | ||
end | ||
|
||
local ezviz_private_cluster_button_handler = function(driver, device, zb_rx) | ||
local event | ||
local additional_fields = { | ||
state_change = true | ||
} | ||
if zb_rx.value == 0x01 then | ||
event = capabilities.button.button.pushed(additional_fields) | ||
elseif zb_rx.value == 0x02 then | ||
event = capabilities.button.button.double(additional_fields) | ||
elseif zb_rx.value == 0x03 then | ||
event = capabilities.button.button.held(additional_fields) | ||
end | ||
if event ~= nil then | ||
device:emit_event(event) | ||
end | ||
end | ||
|
||
local ezviz_button_handler = { | ||
NAME = "Ezviz Button", | ||
supported_capabilities = { | ||
capabilities.battery, | ||
capabilities.button, | ||
capabilities.refresh | ||
}, | ||
zigbee_handlers = { | ||
attr = { | ||
[EZVIZ_PRIVATE_CLUSTER] = { | ||
[EZVIZ_PRIVATE_ATTRIBUTE] = ezviz_private_cluster_button_handler | ||
} | ||
} | ||
}, | ||
lifecycle_handlers = { | ||
added = device_added | ||
}, | ||
can_handle = is_ezviz_button | ||
} | ||
defaults.register_for_default_handlers(ezviz_button_handler, ezviz_button_handler.supported_capabilities) | ||
return ezviz_button_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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,19 @@ local capabilities = require "st.capabilities" | |
local constants = require "st.zigbee.constants" | ||
local IasZoneType = require "st.zigbee.generated.types.IasZoneType" | ||
local device_management = require "st.zigbee.device_management" | ||
local PowerConfiguration = clusters.PowerConfiguration | ||
|
||
local CONTACT_SWITCH = IasZoneType.CONTACT_SWITCH | ||
local MOTION_SENSOR = IasZoneType.MOTION_SENSOR | ||
local WATER_SENSOR = IasZoneType.WATER_SENSOR | ||
local REMOTE_CONTROL = IasZoneType.REMOTE_CONTROL | ||
|
||
local ZIGBEE_GENERIC_SENSOR_PROFILE = "generic-sensor" | ||
local ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE = "generic-contact-sensor" | ||
local ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE = "generic-motion-sensor" | ||
local ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE = "generic-waterleak-sensor" | ||
local ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE = "generic-motion-illuminance" | ||
local ZIGBEE_GENERIC_REMOTE_CONTROL_PROFILE = "generic-remote-control" | ||
|
||
local ZONETYPE = "ZoneType" | ||
local IASZone = clusters.IASZone | ||
|
@@ -42,6 +46,7 @@ local do_configure = function(self, device) | |
device:configure() | ||
device:send(device_management.build_bind_request(device, IASZone.ID, self.environment_info.hub_zigbee_eui)) | ||
device:send(IASZone.attributes.ZoneStatus:configure_reporting(device, 30, 300, 1)) | ||
device:send(PowerConfiguration.attributes.BatteryPercentageRemaining:read(device)) | ||
end | ||
|
||
local function info_changed(driver, device, event, args) | ||
|
@@ -55,12 +60,18 @@ local function update_profile(device, zone_type) | |
local profile = ZIGBEE_GENERIC_SENSOR_PROFILE | ||
if zone_type == CONTACT_SWITCH then | ||
profile = ZIGBEE_GENERIC_CONTACT_SENSOR_PROFILE | ||
elseif zone_type == MOTION_SENSOR then | ||
profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE | ||
elseif zone_type == REMOTE_CONTROL then | ||
profile = ZIGBEE_GENERIC_REMOTE_CONTROL_PROFILE | ||
elseif zone_type == WATER_SENSOR then | ||
profile = ZIGBEE_GENERIC_WATERLEAK_SENSOR_PROFILE | ||
elseif zone_type == MOTION_SENSOR then | ||
profile = ZIGBEE_GENERIC_MOTION_SENSOR_PROFILE | ||
for _, ep in ipairs(device.zigbee_endpoints) do | ||
if device:supports_server_cluster(clusters.IlluminanceMeasurement.ID, ep.id) then | ||
profile = ZIGBEE_GENERIC_MOTION_ILLUMINANCE_PROFILE | ||
end | ||
end | ||
end | ||
|
||
device:try_update_metadata({profile = profile}) | ||
end | ||
|
||
|
@@ -70,44 +81,6 @@ local ias_zone_type_attr_handler = function (driver, device, attr_val) | |
update_profile(device, attr_val.value) | ||
end | ||
|
||
-- since we don't have button devices using IASZone, the driver here is remaining to be updated | ||
local generate_event_from_zone_status = function(driver, device, zone_status, zb_rx) | ||
local type = device:get_field(ZONETYPE) | ||
local event | ||
if type == CONTACT_SWITCH then | ||
if zone_status:is_alarm1_set() or zone_status:is_alarm2_set() then | ||
event = capabilities.contactSensor.contact.open() | ||
else | ||
event = capabilities.contactSensor.contact.closed() | ||
end | ||
elseif type == MOTION_SENSOR then | ||
if zone_status:is_alarm1_set() or zone_status:is_alarm2_set() then | ||
event = capabilities.motionSensor.motion.active() | ||
else | ||
event = capabilities.motionSensor.motion.inactive() | ||
end | ||
elseif type == WATER_SENSOR then | ||
if zone_status:is_alarm1_set() then | ||
event = capabilities.waterSensor.water.wet() | ||
else | ||
event = capabilities.waterSensor.water.dry() | ||
end | ||
end | ||
if event ~= nil then | ||
device:emit_event_for_endpoint( | ||
zb_rx.address_header.src_endpoint.value, | ||
event) | ||
end | ||
end | ||
|
||
local ias_zone_status_attr_handler = function(driver, device, zone_status, zb_rx) | ||
generate_event_from_zone_status(driver, device, zone_status, zb_rx) | ||
end | ||
|
||
local ias_zone_status_change_handler = function(driver, device, zb_rx) | ||
generate_event_from_zone_status(driver, device, zb_rx.body.zcl_body.zone_status, zb_rx) | ||
end | ||
|
||
local zigbee_generic_sensor_template = { | ||
supported_capabilities = { | ||
capabilities.battery, | ||
|
@@ -117,13 +90,7 @@ local zigbee_generic_sensor_template = { | |
zigbee_handlers = { | ||
attr = { | ||
[IASZone.ID] = { | ||
[IASZone.attributes.ZoneType.ID] = ias_zone_type_attr_handler, | ||
[IASZone.attributes.ZoneStatus.ID] = ias_zone_status_attr_handler | ||
} | ||
}, | ||
cluster = { | ||
[IASZone.ID] = { | ||
[IASZone.client.commands.ZoneStatusChangeNotification.ID] = ias_zone_status_change_handler | ||
[IASZone.attributes.ZoneType.ID] = ias_zone_type_attr_handler | ||
} | ||
} | ||
}, | ||
|
@@ -132,6 +99,14 @@ local zigbee_generic_sensor_template = { | |
doConfigure = do_configure, | ||
infoChanged = info_changed | ||
}, | ||
sub_drivers = { | ||
require("contact"), | ||
require("motion"), | ||
require("waterleak"), | ||
require("motion-illuminance"), | ||
require("meian"), | ||
require("ezviz") | ||
Comment on lines
+107
to
+108
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. How about changing to 'meian-button' / 'ezviz-button' for the clarity? (including the folder name of each sub drivers) |
||
}, | ||
ias_zone_configuration_method = constants.IAS_ZONE_CONFIGURE_TYPE.AUTO_ENROLL_RESPONSE | ||
} | ||
|
||
|
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,90 @@ | ||
-- Copyright 2025 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
local clusters = require "st.zigbee.zcl.clusters" | ||
local capabilities = require "st.capabilities" | ||
local read_attribute = require "st.zigbee.zcl.global_commands.read_attribute" | ||
local constants = require "st.zigbee.constants" | ||
local zcl_messages = require "st.zigbee.zcl" | ||
local data_types = require "st.zigbee.data_types" | ||
local messages = require "st.zigbee.messages" | ||
local defaults = require "st.zigbee.defaults" | ||
|
||
local IASZone = clusters.IASZone | ||
local IASACE = clusters.IASACE | ||
|
||
local TUYA_MFR_HEADER = "_TZ" | ||
|
||
local is_meian_sos_button = function(opts, driver, device) | ||
if device:supports_capability(capabilities.button) and string.sub(device:get_manufacturer(),1,3) == TUYA_MFR_HEADER then | ||
return true | ||
end | ||
end | ||
|
||
local function read_attribute_function(device, cluster_id, attr_id) | ||
local read_body = read_attribute.ReadAttribute( attr_id ) | ||
local zclh = zcl_messages.ZclHeader({ | ||
cmd = data_types.ZCLCommandId(read_attribute.ReadAttribute.ID) | ||
}) | ||
local addrh = messages.AddressHeader( | ||
constants.HUB.ADDR, | ||
constants.HUB.ENDPOINT, | ||
device:get_short_address(), | ||
device:get_endpoint(cluster_id), | ||
constants.HA_PROFILE_ID, | ||
cluster_id | ||
) | ||
local message_body = zcl_messages.ZclMessageBody({ | ||
zcl_header = zclh, | ||
zcl_body = read_body | ||
}) | ||
return messages.ZigbeeMessageTx({ | ||
address_header = addrh, | ||
body = message_body | ||
}) | ||
end | ||
|
||
local function info_changed(driver, device, event, args) | ||
if device.profile.id ~= args.old_st_store.profile.id then | ||
local magic_spell = {0x0004, 0x0000, 0x0001, 0x0005, 0x0007, 0xfffe} | ||
device:send(IASZone.attributes.ZoneStatus:read(device)) | ||
device:send(read_attribute_function(device, clusters.Basic.ID, magic_spell)) | ||
end | ||
end | ||
|
||
local ias_ace_emergency_handler = function(driver, device) | ||
device:emit_event(capabilities.button.button.pushed({ state_change = true })) | ||
end | ||
|
||
local meian_sos_button_handler = { | ||
NAME = "Meian Sos Button", | ||
supported_capabilities = { | ||
capabilities.battery, | ||
capabilities.button, | ||
capabilities.refresh | ||
}, | ||
lifecycle_handlers = { | ||
infoChanged = info_changed | ||
}, | ||
zigbee_handlers = { | ||
cluster = { | ||
[IASACE.ID] = { | ||
[IASACE.server.commands.Emergency.ID] = ias_ace_emergency_handler | ||
} | ||
} | ||
}, | ||
can_handle = is_meian_sos_button | ||
} | ||
defaults.register_for_default_handlers(meian_sos_button_handler, meian_sos_button_handler.supported_capabilities) | ||
return meian_sos_button_handler |
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.
if this device is a button it should be in the zigbee button driver
As far as I can tell it doesn't do any sensing, so it doesn't make much sense to put it here
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.
After our team discussions, we have no better solution for this yet. Could you please share your suggestions? How about just put it to Unofficial/ezviz directory?
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.
You could do that or you could put this exact same fingerprint in the
zigbee-button
driver.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.
@greens
Actually, this device is non-WWST device, so we can't put exact fingerprint in zigbee-button driver for this device.
As you know, zigbee-sensor have only generic fingerprint for generic purpose and scalability. I think by adding like this, we can support more ezviz button if they use same private cluster in the future(or now) for their new button devices. and If we need to support more other different types of ezviz devices in the future, then let's move this device into Unofficial/ezviz. but now, Let's just keep this device into zigbee-sensor for a while. What do you think?
deviceLabel: "Zigbee Generic Button"
clusters:
server:
- 0x0500
- 0xFE00 # EZVIZ private cluster
- 0xFE05 # EZVIZ private cluster
deviceProfileName: generic-remote-control
CC: @kdbang @varzac
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.
put this fingerprint:
under a new
zigbeeGeneric:
section here: https://github.com/SmartThingsCommunity/SmartThingsEdgeDrivers/blob/main/drivers/SmartThings/zigbee-button/fingerprints.ymlThere 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.
buttons should use the button driver