logo elektroda
logo elektroda
X

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

kaleidoscopeit 945 28
ADVERTISEMENT
  • #1 21608745
    kaleidoscopeit
    Level 2  
    I'll start a dedicated thread for this device.

    In another thread, a similar power meter is covered, but there'are mixed messages referring
    both devices, causing a little bit of confusion. (https://www.elektroda.com/rtvforum/topic4016609.html)

    The device I'll cover in this thread is the following:

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

    Bough from Aliexpress: https://it.aliexpress.com/item/1005007292927857.html

    What are my findings:

    - HLW8112 (https://redmine.laas.fr/attachments/download/3444/DS_HLW8110_HLW8112_EN_Rev1.01%20.pdf)
    - Unstable firmware (at least in my device)
    - Power MeterIC connected directly to CBU module via SPI (NO TuyaMCU)
    - Backup and restore firmware causes wrong measurement, but subsequently I discovered that all power values are reported in a ratio 1:5

    By reading the posts from the other thread I concluded that there is no way to use TuyaMCU driver because the Power Meter IC
    is directly connected to the Tuya module via SPI.

    In fact @dicamarques made an attempt to write a driver for it (21221637#21221637), but, at least with my device,
    by compiling the code he wrote from his GitHub repo, I was unable to get SPI working.

    Furthermore Dicamarques and other guys posted a lot of useful informations:
    - a schematc where you can see that P9 is used for "SCSN"  instead of the standard P15.
    - links where very complete and presumably working drivers can be found

    Subsequently I wanted to try to write my own driver... 
    Spoiler :( I wrote a lot of code, half of it, copy/pasted from the full driver source from the link above, but with no luck... the SPI still not send or receive data.

    This i the link to my repo, in case someone more experienced can tell me what I'm doing wrong :) https://github.com/kaleidoscopeit/OpenBK7231T_App_HLW8112
    (--> To start the driver, issue "startDriver HLW8112SPI" in the command field of the log console in the Web Application)

    It could be that I'm doing something crazy, like buying a logic analyzer and connect it to the SPI in order to understand what goin on when
    the original Tuya firmware speaks with the Power Meter IC.

    I thank the guys who posted in the other thread and I invite everyone to continue in this one.
  • ADVERTISEMENT
  • #2 21609085
    p.kaczmarek2
    Moderator Smart Home
    Interesting, have you seen BL0942 SPI driver in our repository? Maybe it could serve as a reference.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21610131
    kaleidoscopeit
    Level 2  
    Hi, yes I used it in order to build the base structure and get useful hints on how to write a driver. Thank you.

    I've updated the main topic message with the link to my fork of OpenBK7231T_App.
  • #4 21611254
    p.kaczmarek2
    Moderator Smart Home
    I think you should start with the most basic transmit and read code. Try to choose some register from HLW datasheet and then try to read it with OBK.
    Helpful post? Buy me a coffee.
  • #5 21694008
    maxters007
    Level 2  
    @kaleidoscopeit
    Hello. i have written something for hlw8112. I also have device and tiered of tuya firmware issues. If you still have device and willing to test please try mine and would welcome any feedback
    this is my first openBKN adventure i have no idea most of the things are supposed to work. So far I have got voltage, frequency current A/B, power A/B, energy ( import/export ) A/B. active power and power factor, homeassistant discovery
    https://github.com/netmaxt3r/OpenBK7231T_App/tree/hlw8112
    you can download build for OpenBK7231N build from GH actions.
    DONOT run firmware on the device for long as I still haven't figure out some stuff. might cause a lot of flash write which may cause degradation ( I dont know). Just test for some time and let me know how it goes my device template is this
    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "1024",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "9": "HLW_8112_SCSN;0",
        "24": "WifiLED_n;0",
        "26": "Btn;0"
      },
      "command": "",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }
    



    i still need to work on
    calibration params
    align code to existing power meter drivers etc.

    @p.kaczmarek2 nice job on OpenBK. as you can see my code is spaghetti right now. that is why i haven't opened PR on github. I am not a real C developer. I have couple of questions on how to fix it and properly integrate with platform. Where do you prefer github PR or here ?.
    Thanks for your time.
  • #6 21694368
    p.kaczmarek2
    Moderator Smart Home
    Thank you. As long as your driver is in separate file (‎src/driver/drv_hlw8112.c in your case, I see..), and you do not modify much of the obk core API and stuff, then I can easily accept PR. Just make sure your code is not build on default and encased in ENABLE_DRIVER_HLW8112SPI, also make sure that everything builds correctly with no errors. Then I can merge via PR on Github.

    The only stuff you need to fix/remove before merge is this:
    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?
    Helpful post? Buy me a coffee.
  • #7 21695267
    maxters007
    Level 2  
    sure, i will create PR early next week with all the build issues. meanwhile could you help with some questions

    1. Is it okay if my driver hijack current emetering struct (only if my driver is running) ? i tried to add new struct to flashvar and device refuse to boot past flashvar init. i think i need to make flash reinit i don't know how.
    2. Currently I have home assistant button sending mqtt topic to /command/dev_name/<cc> . Is this the correct way?. I have a feeling i should use channel for this
    3. Do I need to align with existing BL_ drivers ?. It might take more time to understand especially BL_TWIN logic
    thanks
  • #9 21703704
    kdm6389
    Level 4  
    >>21694008

    Script execution log:

    Send started... send 0/9... send 1/9... send 1/9... send 2/9... send 2/9... send 3/9... send 3/9... send 4/9... send 4/9...FAILED! Invalid command "backlog setPinRole 9 HLW_8112_SCSN; setPinChannel 9 0".FAILED! Invalid command "backlog setPinRole 9 HLW_8112_SCSN; setPinChannel 9 0".
  • #10 21703722
    p.kaczmarek2
    Moderator Smart Home
    Button looks interesting, but it's not called anywhere? Still, probably worth keeping...

    So this device can't easily mix with bl_shared because it has dual measurement, A/B? I see... I guess it's acceptable.

    Okay, but is your branch still working with BL0942, BL0937, etc? @divadiow can you check before merge?
    Helpful post? Buy me a coffee.
  • #11 21703742
    divadiow
    Level 36  
    BL0937 I can do now

    1810_merge_183015c253a3

    driver starts and readings are showing as before
    OpenBK7231N interface screen with electrical energy measurement data
  • #12 21703866
    kdm6389
    Level 4  
    my hlw8112 is still not working, can someone share pin details
  • #13 21703871
    divadiow
    Level 36  
    kdm6389 wrote:
    my hlw8112 is still not working, can someone share pin details

    are you running the PR build 1810_merge_183015c253a3?

    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?
  • #14 21707507
    kdm6389
    Level 4  
    Built on Sep 28 2025 08:25:04 version 1.18.181
    Online for 3 minutes and 18 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N

    Added after 16 [minutes]:

    updated to

    Built on Oct 1 2025 22:31:45 version 1.18.185
    Online for 3 minutes and 39 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N

    using https://github.com/openshwprojects/OpenBK7231...es/download/1.18.185/OpenBK7231N_1.18.185.rbl
    installed just now,

    still not working ....

    if there is pin configuration / setting to change please do share for both (A/B) channels

    trying https://www.elektroda.com/rtvforum/topic4130528.html#21694008


    Script execution log:
    Send started... send 0/9... send 1/9... send 2/9... send 3/9... send 4/9... send 5/9... send 6/9... send 7/9... send 8/9... Send done! Please restart device if needed.
      "pins": {
        "9": "HLW_8112_SCSN;0",
        "24": "WifiLED_n;0",
        "26": "Btn;0"0
      },



    still not working ....

    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5? Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?
    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?
    Tuya WiFi Energy Meter PM01_A002 [CBU][BK7231N] HLW8112 SPI Power Reading Ratio 1:5?
  • ADVERTISEMENT
  • #15 21707538
    p.kaczmarek2
    Moderator Smart Home
    I don't think this driver is enabled by default on the public build. You need to enable it in obk_config.h. If you do startDriver for it, does it even start? I don't think so - it's not in the build.
    Helpful post? Buy me a coffee.
  • #17 21707682
    kdm6389
    Level 4  
    How to flash bin file there is no option
  • #19 21707701
    kdm6389
    Level 4  
    Built on Oct 1 2025 22:32:02 version 1.18.185_powerMetering
    Online for just 25 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N

    this one also not worked

    ref:
    https://github.com/openshwprojects/OpenBK7231T_App/releases

    Added after 2 [minutes]:

    >>21707699 let me check it has rbl

    Added after 3 [minutes]:


    Control panel for device 0f-dual-energy showing system info and configuration options

    Built on Sep 27 2025 12:50:21 version 1810_merge_183015c253a3
    Online for 1 minutes and 9 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N

    no power output? why?
    I think I need the config?



    cmd:
    startDriver HLW8112SPI


    Info:MAIN:Driver HLW8112SPI is not known in this build.
    Info:MAIN:Available drivers:
    Info:MAIN:TuyaMCU
    Info:MAIN:, tmSensor
    Info:MAIN:, PixelAnim
    Info:MAIN:, NTP
    Info:MAIN:, HTTPButtons
    Info:MAIN:, I2C
    Info:MAIN:, BL0942
    Info:MAIN:, BL0942SPI
    Info:MAIN:, BL0937
    Info:MAIN:, CSE7766
    Info:MAIN:, SM16703P
    Info:MAIN:, SM15155E
    Info:MAIN:, IR
    Info:MAIN:, DDP
    Info:MAIN:, SSDP
    Info:MAIN:, DGR
    Info:MAIN:, Wemo
    Info:MAIN:, Hue
    Info:MAIN:, PWMToggler
    Info:MAIN:, DoorSensor
    Info:MAIN:, SM2135
    Info:MAIN:, BP5758D
    Info:MAIN:, BP1658CJ
    Info:MAIN:, SM2235
    Info:MAIN:, CHT83XX
    Info:MAIN:, KP18058
    Info:MAIN:, ADCSmoother
    Info:MAIN:, AHT2X
    Info:MAIN:, DS1820
    Info:MAIN:, Battery
    Info:MAIN:, Bridge
    Info:CMD:[WebApp Cmd 'startDriver HLW8112SPI' Result] OK
  • #21 21707751
    feiltom
    Level 5  
    you need to take a firmware with the driver built-in, it is not the case by default

    this build has the driver enabled : https://github.com/netmaxt3r/OpenBK7231T_App/actions/runs/18059811136/job/51394535502
    the firmware build is this one : https://github.com/netmaxt3r/OpenBK7231T_App/actions/runs/18059811136/artifacts/4121996251

    which way you use to flash ?
    with serial way it's OpenBK7231N_UA_hlw8112_6ae422624810.bin ( in zip )
  • ADVERTISEMENT
  • #22 21707769
    kdm6389
    Level 4  
    ================
    back to
    ================

    Built on Oct 1 2025 22:31:45 version 1.18.185
    Online for 1 minute and 0 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N

    ==========
    Info:MAIN:Driver HLW8112SPI is not known in this build.
    Info:MAIN:Driver HLW8112 is not known in this build.

    ============
    but,
    Info:MAIN:Started BL0942SPI.
    Info:CMD:[WebApp Cmd 'startDriver BL0942SPI' Result] OK
    works, which means HLW8112SPI still disabled

    Added after 7 [minutes]:

    >>21707751
    This one worked

    Built on Sep 27 2025 12:35:04 version hlw8112_6ae422624810
    Online for 1 minute and 3 seconds
    Device MAC: 38:A5:C9:42:DE:42
    Short name: 0f-de-obkDE42, Chipset BK7231N
  • #23 21707776
    feiltom
    Level 5  
    You take with firmware ?
    I see Built on Oct 1 2025 22:31:45 version 1.18.185
    The link I give you the firmware was built on Sep 27, 2:30 PM GMT 2
  • Helpful post
    #25 21710119
    setum
    Level 7  
    >>21707780

    here's how it looks (both sensors are clipped to the same wire):
    Interface showing measurement data from two energy sensor channels
  • #26 21723223
    1977ferrer
    Level 2  
    Hi everyone
    Is there a fully working OpenBeken firmware for the Tuya power meter with HLW8112 (BK7231N)? I have been reading but I’m still not completely sure if there is already a fully working OpenBeken firmware that supports it. If there is a working firmware already, where can I download it?

    Thanks a lot for your help
  • #27 21723280
    p.kaczmarek2
    Moderator Smart Home
    Helpful post? Buy me a coffee.
  • #28 21723285
    1977ferrer
    Level 2  
    Thank you. I use a bk7231guiflashtool-v130 but the .rbl file is not accepted. How I have flash this firmware?
  • #29 21723306
    p.kaczmarek2
    Moderator Smart Home
    BK7231 Easy GUI Flasher requires QIO, however, you can just flash stock OBK qio as well and then do OTA to RBL. Maybe it's easier.
    Helpful post? Buy me a coffee.

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.
Summary generated by the language model.
ADVERTISEMENT