Repository navigation
Add BL0937 energy metering: Electrical Measurement + Metering clusters - #497
Open
XaviSentis wants to merge 1 commit into
Open
XaviSentis wants to merge 1 commit into
XaviSentis wants to merge 1 commit into
Conversation
Adds optional power/energy metering for BL0937-based Tuya plugs (generic; no
board enabled here).
- New `E` config-str token for the pin wiring: E<CF><CF1><SEL>[i] (2-char pin
names; trailing `i` inverts SEL). Parsed in config_parser.
- BL0937 driver + a small GPIO hardware-counter HAL: counts CF/CF1 pulses,
multiplexes CF1 between voltage and current via SEL, produces
rmsVoltage/rmsCurrent/activePower and accumulated energy.
- ZCL clusters (metering_cluster): Electrical Measurement 0x0B04 (rms V/I/P +
AC multiplier/divisor incl. acPowerMultiplier 0x0604) and Metering 0x0702
(currentSummationDelivered, Status 0x0200, unit/multiplier/divisor/
formatting/deviceType).
- HAL fix (telink zigbee_zcl): get_register_func_by_cluster_id() now maps
0x0B04/0x0702 to a register function (via generic zcl_registerCluster), so
their attributes are actually served -- previously the clusters were
advertised but every attribute read returned UNSUPPORTED_ATTRIBUTE and no
reports were emitted.
- Z2M converter generator: emits electricityMeter({ endpointNames: [...] }) for
metering devices so exposes match the reported data on multi-endpoint devices.
- TC32 build fixes: 32-bit-only frequency math, stddef for NULL.
Coefficients are placeholder defaults and need per-board calibration.
XaviSentis
force-pushed
the
pr-bl0937-metering
branch
from
November 14, 2026 22:41
dac3633 to
50b7fb9
Compare
Author
|
Rebased onto current main. The only conflict was the |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Adds optional power/energy metering for BL0937-based Tuya plugs (a very common metering chip on TS011F and similar devices). Generic feature only — no specific board is enabled here (see the follow-up PR for the Aubess PM).
How it works
Econfig-str token for the pin wiring:E<CF><CF1><SEL>[i](2-char pin names; trailingiinverts the SEL level). Parsed inconfig_parser, mirrors the existing token style.base_components/metering_bl0937.c): counts CF/CF1 pulses via a small GPIO hardware-counter HAL (gpio_counter), multiplexes CF1 between voltage and current with SEL, and produces rmsVoltage / rmsCurrent / activePower / accumulated energy.zigbee/metering_cluster.c): serves Electrical Measurement (0x0B04: rmsVoltage/Current/activePower + AC multiplier/divisor incl.acPowerMultiplier 0x0604) and Metering (0x0702: currentSummationDelivered, Status0x0200, unit/multiplier/divisor/formatting/deviceType).telink/hal/zigbee_zcl.c):get_register_func_by_cluster_id()now maps0x0B04/0x0702to a register function (via the genericzcl_registerCluster()). Without this the clusters are advertised in the simple descriptor but every attribute read returnsUNSUPPORTED_ATTRIBUTEand no reports are emitted.electricityMeter({ endpointNames: [...] })for metering devices, so the exposed properties carry the endpoint suffix and match the reported data on multi-endpoint devices (otherwise HA discoverspower/currententities that never receive data while the values land underpower_switch/current_switch).Notes
stddef.hforNULL.DEFAULT_COEF_*) are placeholder defaults and need per-board calibration — a concrete calibrated board is added in the follow-up PR.Testing