logo elektroda
logo elektroda
X
logo elektroda

Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?

kaleidoscopeit 3681 41
Best answers

How can I get the Tuya BK7231N HLW8112 SPI energy meter working in OpenBK7231T, and fix the readings that are off by a 1:5 ratio?

Use the dedicated HLW8112 SPI driver/build rather than TuyaMCU, because the meter IC is wired directly to the BK7231N over SPI and the driver is not in the default public build [#21694008][#21707701][#21707538] One working template uses pin 9 for `HLW_8112_SCSN` (with pins 24 for WiFi LED and 26 for the button), and a tested branch/build reported voltage, frequency, current A/B, power A/B, energy import/export, active power, power factor, and Home Assistant discovery [#21694008] For calibration, OpenBK supports the standard `VoltageSet`/`CurrentSet`/`PowerSet` commands, and the HLW8112 driver also has a custom `HLW8112_SetResistorGain` command [#21794549] A user fixed the 5× current error by running `HLW8112_SetResistorGain 0 1000 1`; using `... 1 1000 1` made voltage jump into the thousands, so the first parameter matters [#21795311] If the A/B display looks wrong, note that one tester found the current clamp physically on channel A but shown on channel B, because the outer case labels appear swapped relative to the board [#21795311][#21795363]
Generated by the language model.
ADVERTISEMENT
  • #31 21733747
    feiltom
    Level 5  
    Posts: 5
    Help: 1
    Rate: 2
    For information on mine I need to overwrite the bootloader for boot OK.
    I cannot flash it anymore, but it works!
  • ADVERTISEMENT
  • #32 21736669
    dweimena
    Level 1  
    Posts: 1
    I am using OpenBK7231N_1.18.206_hlw8112.rbl on a device like the one in the first post.
    It works very well.
    Is there a way to correct the measurements within very small limits?
    The VoltageSet command does not work.
  • #33 21794373
    alexsahka
    Level 3  
    Posts: 5
    Rate: 1
    Interestingly, after flashing the new firmware, my device is reporting current readings exactly 5× higher than the actual values. Is there a way to recalibrate the scaling factor or apply a correction offset in the configuration? Thank you!

    Screenshot showing energy monitoring interface with measured data for channels A and B Fluke 322 clamp meter display shows 7.20 amps AC Electronic module with PCB and communication chip mounted in a white enclosure Electrical module with input labels and certification symbols Dropdown list with selectable units and electrical measurement parameters
  • ADVERTISEMENT
  • #34 21794549
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    I am not the author of HLW8112 integration, but in OBK, we have VoltageSet/CurrentSet/PowerSet commands. We may need to check the source code for HLW8112 to be sure, but calibration is a standard procedure, like with Tasmota.
    Is this the driver used?
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_hlw8112.c
    It looks like the author added some extra commands - something like HLW8112_SetResistorGain.
    Helpful post? Buy me a coffee.
  • #35 21795249
    alexsahka
    Level 3  
    Posts: 5
    Rate: 1
    >>21794549 Thank you for the reply. I tried running some HLW8112 custom commands, but it looks like they aren't supported yet. I noticed a 'TODO' status in the code/documentation—am I interpreting that correctly?

    Also, the standard VoltageSet/CurrentSet/PowerSet commands are returning errors.

    Table with HLW8112 function names and TODO status for each entry
  • ADVERTISEMENT
  • #36 21795260
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    This does not mean that they are not supported. It means there is no docs for them yet. The author of HLW8112 SPI feature didn't fill their descriptions.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #37 21795311
    alexsahka
    Level 3  
    Posts: 5
    Rate: 1
    >>21795260 I managed to get it working. Using the command HLW8112_SetResistorGain 1 1000 1 caused the voltage readings to spike into the thousands. However, after running HLW8112_SetResistorGain 0 1000 1, the voltage returned to normal and the current readings became accurate (instead of being 5× too high).

    I also noticed a channel mismatch: my current clamp is physically connected to Channel A, but the interface displays the data on Channel B. If I plug the current clamp into Channel B, the interface shows no reading at all.

    I’m not sure who the original author of these HLW8112 drivers is. I tried reading through the forum thread, but it got a bit confusing—does anyone know who I should contact with questions?
  • #38 21795325
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Helpful post? Buy me a coffee.
  • #39 21795352
    alexsahka
    Level 3  
    Posts: 5
    Rate: 1
    >>21795325 As a non-coder, where is the best place to get support — here or GitHub? Thanks.
  • #40 21795356
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14416
    Help: 650
    Rate: 12371
    Well, usually the best place to get quick support is here (on Elektroda), but for HLW8112 the case is special, because for some question you may want to reach for PR author.

    maxters007 wrote:
    Hey @p.kaczmarek2 I have created a PR https://github.com/openshwprojects/OpenBK7231T_App/pull/1810
    driver is disabled in the code. please have a look and let me know


    @maxters007 are VoltageSet/CurrentSet/PowerSet commands working in your driver? Can you add command descriptions?
    Helpful post? Buy me a coffee.
  • #41 21795363
    alexsahka
    Level 3  
    Posts: 5
    Rate: 1
    >>21795356 Ah, I see—the manufacturer swapped the labels for Channel A and Channel B on the outer case compared to the actual circuit board.
    Internal connections of an energy metering module showing GND, IAP, IBP pins and screw terminals
  • #42 21862513
    divadiow
    Level 38  
    Posts: 4859
    Help: 424
    Rate: 860
    @maxters007

    Was
    HLW_8112_SCSN
    intentional, or is it just a typo of
    HLW8112_SCSN
    ? I’m asking because the parser accepts the underscored form, but I want to know which name you consider canonical and whether accepting both would be the right fix or if there should be an adjustment to a single one - my preference would be
    HLW8112_SCSN
    .

Topic summary

✨ The discussion focuses on the Tuya WiFi Energy Meter PM01_A002, specifically the CBS version with the BK7231N chip and HLW8112 power metering IC. The device, purchased from AliExpress, features a direct SPI connection between the HLW8112 and the CBU, without a TuyaMCU intermediary. The firmware is reported as unstable, with backup and restore operations causing incorrect measurements. It was discovered that power values are reported with a 1:5 ratio discrepancy. The thread aims to clarify confusion arising from mixed information about similar devices in other forums and provides detailed pinout and wiring information for the HLW8112 SPI interface on this specific model.
Generated by the language model.

FAQ

TL;DR: Tuya PM01_A002 (BK7231N + HLW8112) can work on OpenBeken; some stock units show a 1:5 power-reading ratio — “all power values are reported in a ratio 1:5.” [Elektroda, kaleidoscopeit, post #21608745]

Why it matters: This FAQ helps you flash, enable the HLW8112 SPI driver, set pins, and fix no‑reading issues fast — ideal for DIYers migrating Tuya meters to OpenBeken.

Quick Facts

Is there a working OpenBeken firmware for Tuya PM01_A002 (HLW8112, BK7231N)?

Yes. Users report success with HLW8112-enabled OpenBK builds (e.g., OpenBK7231N_1.18.206_hlw8112.rbl) on PM01_A002‑like devices. [Elektroda, dweimena, post #21736669]

Why do I get “Driver HLW8112SPI is not known in this build”?

Because public builds don’t ship the HLW8112 driver enabled. Rebuild with ENABLE_DRIVER_HLW8112SPI in obk_config.h or flash a driver‑enabled image. “You need to enable it in obk_config.h.” [Elektroda, p.kaczmarek2, post #21707538]

Which pins do I set for HLW8112 on this Tuya board?

Set chip‑select SCSN to P9. Example template used: P9=HLW_8112_SCSN; P24=WifiLED_n; P26=Btn. Then start the driver. [Elektroda, maxters007, post #21694008]

How do I flash an .rbl if my GUI flasher rejects it?

Flash a stock OpenBK QIO image first with your GUI tool, then perform OTA to the .rbl from the OpenBeken Web UI. [Elektroda, p.kaczmarek2, post #21723306]

How can I test quickly with a driver‑enabled build?

Flash a community HLW8112-enabled artifact (e.g., hlw8112_6ae422624810). Users confirmed it starts and shows data. [Elektroda, kdm6389, post #21707769]

HLW8112 roles or commands fail as “Invalid command.” What does that mean?

Your firmware lacks the HLW8112 role/driver, so role or startDriver calls fail. Flash a build with the driver enabled. [Elektroda, p.kaczmarek2, post #21707538]

How do I set up HLW8112 on OpenBeken (quick 3‑step)?

  1. Flash an HLW8112-enabled build (or rebuild with ENABLE_DRIVER_HLW8112SPI).
  2. Set P9 to HLW_8112_SCSN; add LED/Button pins if needed.
  3. Run: startDriver HLW8112SPI, then verify voltage/current/power A/B. [Elektroda, maxters007, post #21694008]

What about A/B channels and Home Assistant discovery?

Community code exposes voltage, frequency, current A/B, power A/B, import/export energy, PF, plus Home Assistant discovery. [Elektroda, maxters007, post #21694008]

Can I calibrate voltage and power (e.g., VoltageSet)?

A user on OpenBK7231N_1.18.206_hlw8112 reported VoltageSet didn’t work. Expect limited on‑device calibration until added. [Elektroda, dweimena, post #21736669]

I still see a 1:5 power reading ratio—what’s going on?

That behavior was observed on stock Tuya firmware. Switching to a working HLW8112 OpenBeken build removes the mismatch. [Elektroda, kaleidoscopeit, post #21608745]

What MQTT/command path should I use from Home Assistant?

One tester used a HA button to publish to /command/dev_name/, and reported HA discovery support in the driver. [Elektroda, maxters007, post #21694008]

Any flashing pitfalls (edge cases)?

One device required overwriting the bootloader to boot correctly; after that, it worked but couldn’t be reflashed the usual way. [Elektroda, feiltom, post #21733747]
Generated by the language model.
ADVERTISEMENT