-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathinit.lua
More file actions
50 lines (43 loc) · 1.64 KB
/
init.lua
File metadata and controls
50 lines (43 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
-- Copyright 2025 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0
local clusters = require "st.zigbee.zcl.clusters"
local capabilities = require "st.capabilities"
local SimpleMetering = clusters.SimpleMetering
local constants = require "st.zigbee.constants"
local configurations = require "configurations"
local device_init = function(self, device)
local customEnergyDivisor = 10000
device:set_field(constants.SIMPLE_METERING_DIVISOR_KEY, customEnergyDivisor, {persist = true})
end
local do_configure = function(self, device)
device:refresh()
device:configure()
-- Additional one time configuration
if device:supports_capability(capabilities.powerMeter) then
-- Divisor and multipler for PowerMeter
device:send(SimpleMetering.attributes.Divisor:read(device))
device:send(SimpleMetering.attributes.Multiplier:read(device))
end
end
local instantaneous_demand_handler = function(driver, device, value, zb_rx)
local raw_value = value.value
local divisor = 10
raw_value = raw_value / divisor
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, capabilities.powerMeter.power({value = raw_value, unit = "W" }))
end
local zigbee_dimmer_power_energy_handler = {
NAME = "zigbee dimmer power energy handler",
zigbee_handlers = {
attr = {
[SimpleMetering.ID] = {
[SimpleMetering.attributes.InstantaneousDemand.ID] = instantaneous_demand_handler
}
}
},
lifecycle_handlers = {
init = configurations.reconfig_wrapper(device_init),
doConfigure = do_configure,
},
can_handle = require("zigbee-dimmer-power-energy.can_handle"),
}
return zigbee_dimmer_power_energy_handler