-
Notifications
You must be signed in to change notification settings - Fork 530
WWSTCERT-10189 Ledvance zigbee meter plug #2729
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
Changes from 6 commits
c8278e8
316276d
c01a9d0
5e5a387
98aafe1
6a76283
14de7ba
99ce6ea
22bc75b
b81fa6b
328797c
8f598e7
5004c95
09b89b7
3a46f9d
b7eb6b6
6b409cb
41d31e7
28e7783
875c75f
4011278
3347541
6063c89
9424f57
2f5fe4b
d02ef90
c6d53e8
6ee58b2
2c5a233
420f963
4650e24
5e6d9d6
542e724
bea9429
d0f3ccb
d555fe4
0d04304
d25cf5c
905fe30
c4f13dd
c651f91
c81e7e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| -- Copyright 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local can_handle_simple_metering_config = function(opts, driver, device) | ||
| -- 检查设备是否支持 Simple Metering 集群 (0x0702) | ||
| for _, cluster in ipairs(device.server_clusters) do | ||
| if cluster == 0x0702 then | ||
|
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. we have other devices for which this would return true where we would not want your specific device's logic to be used, which is why we usually gate subdrivers via fingerprints |
||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| return can_handle_simple_metering_config | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| -- Copyright 2025 SmartThings, Inc. | ||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| -- 定义支持该子驱动程序的设备指纹 | ||
| -- 这里可以指定特定的制造商和型号 | ||
| return { | ||
| ["Generic"] = { | ||
| ["SimpleMeteringDevice"] = true | ||
| } | ||
| } | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| -- Copyright 2025 SmartThings, Inc. | ||
|
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. date |
||
| -- Licensed under the Apache License, Version 2.0 | ||
|
|
||
| local capabilities = require "st.capabilities" | ||
| local zigbee_constants = require "st.zigbee.constants" | ||
| local SimpleMetering = require "st.zigbee.cluster".clusters.SimpleMetering | ||
| local zigbee_handlers = require "st.zigbee.handlers" | ||
|
|
||
| -- 设置 Simple Metering 集群的 multipliers 和 divisors 属性 | ||
| local function device_init(driver, device) | ||
| -- 在设备初始化时设置 multipliers 和 divisors | ||
| device:configure() | ||
|
|
||
| -- 设置 Multiplier 为 1 | ||
| local write_multiplier_cmd = SimpleMetering.server.commands.WriteAttributes(device) | ||
| if write_multiplier_cmd then | ||
| device:send_to_component( | ||
| write_multiplier_cmd({ | ||
| {id = SimpleMetering.attributes.Multiplier.ID, value = 1, DataType = 0x22} -- 0x22 is 24-bit integer | ||
|
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. we provide |
||
| }), | ||
| "main" | ||
| ) | ||
| end | ||
|
|
||
| -- 设置 Divisor 为 100 | ||
| local write_divisor_cmd = SimpleMetering.server.commands.WriteAttributes(device) | ||
| if write_divisor_cmd then | ||
| device:send_to_component( | ||
| write_divisor_cmd({ | ||
| {id = SimpleMetering.attributes.Divisor.ID, value = 100, DataType = 0x23} -- 0x23 is 32-bit integer | ||
|
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. in the ZCL this attribute is an |
||
| }), | ||
| "main" | ||
| ) | ||
| end | ||
| end | ||
|
LQ107 marked this conversation as resolved.
|
||
|
|
||
| -- 处理能量计量事件 | ||
| local function energy_meter_handler(driver, device, value, zb_rx) | ||
| local raw_value = value.value | ||
| local divisor = device:get_field(SimpleMetering.attributes.Divisor.ID) or 100 | ||
| local multiplier = device:get_field(SimpleMetering.attributes.Multiplier.ID) or 1 | ||
|
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. this field is not likely to be set. We do set a similar field from |
||
|
|
||
| local calculated_value = (raw_value * multiplier) / divisor | ||
| device:emit_event_for_endpoint( | ||
| zb_rx.address_header.src_endpoint.value, | ||
| capabilities.energyMeter.energy({value = calculated_value, unit = "kWh"}) | ||
| ) | ||
| end | ||
|
|
||
| -- 定义子驱动程序模板 | ||
| local simple_metering_config_subdriver = { | ||
| supported_capabilities = { | ||
| capabilities.energyMeter, | ||
| capabilities.powerMeter | ||
| }, | ||
|
LQ107 marked this conversation as resolved.
Outdated
|
||
| lifecycle_handlers = { | ||
| init = device_init | ||
| }, | ||
| zigbee_handlers = { | ||
| cluster = { | ||
| [SimpleMetering.ID] = { | ||
| [SimpleMetering.attributes.CurrentSummationDelivered.ID] = energy_meter_handler | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return simple_metering_config_subdriver | ||
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.
please remove the changes to this file