logo elektroda
logo elektroda
X
logo elektroda

Meters capable of measuring negative AC power flow (For Solar) - and how to integrate with HA.

cdtdsilva 4362 11
ADVERTISEMENT
  • #1 21012850
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15
    So this point are my observations on negative current measurements using tuya devices.

    What's the deal about it? Well AC is constantly changing polarity, so in order to measure the flow of current, one needs to use the phase angle information, in addition to current and voltage. Many AC power meter's can't measure the direction of an AC current, they only report an absolute value, because... most devices only consume power!

    Now, with PV Solar modules becoming common, it's interesting to be able to measure the current in both directions, to understand if one is consuming from the grid or exporting to the grid. If one is exporting, the rates are often so low that it is desirable to first try and consume this energy by activating certain loads such heating, or hot water heating which can be timed to come on when there is an excess of production, avoiding the consumption of excessive energy from the grid and promoting self consumption.

    On the market there are many devices that feature a energy consumption feature. Most are based on the BL0937 and some on the BL0942. The BL0937 is an 8 pin device that uses a series of pulses to indicate the current flow. These can be reconstructed in a microcontroller to provide a representation of the actual current flow. These devices are the most common ones, but they are not able to indicate the direction of power, only it's absolute value. Another reason why you should stay away from them is because if deep sleep or power saving is enabled, pulses might be skipped and power readings will not be accurate.

    Another device, which is not so common is the BL0942 - a fully serial programmable power monitor which provides details on power and direction and can therefore be used for measurements of energy in either direction. Chinese firmware programs the device in order to only obtain the absolute values of power, so to be able to measure it's direction, it is necessary to flash it with Open Becken.
    The devices can be distinguished easily - The more common BL0937 is an 8 pin device, while the BL0942 is a 10 pin device.

    One challenge with OpenBecken is that even though instantaneous power is measured correctly as either a positive or negative value, cumulative power is not. The total KWh reading is always positive, so it simply adds consumption and export together as a single number, which is not very useful to monitor your solar installation or consumption over time.

    I guess one solution would be to poll the instantaneous values and reconstruct the total consumption, but I'm pretty sure the BL0942 chip can be initialized to do this. If someone has an idea how to get to the source code on openbecken, please let me know. In the meanwhile, if time allows, I might just buy myself a pair of CC1101 dongles and use my choice of microcontroller to communicate directly with the BL0942. This would also solve the problem of the WiFi module, as most of my fuse boxes are metal and shielded / grounded, which kills the 2.4Ghz signal.

    Here are some of the devices I found, which are based on the BL0942:

    The Aubess is by far my favourite. The relay cuts the Neutral (So you can wire it bypassing the relay), Power save works fine, reducing self heating, it's cheap, easy to open and easy to program. But It's limited to 16A as the current must go through PCB traces, so it's a stretch to use it in an incoming house supply. Particularly, in case of short circuit, I don't know if the surface mounted sense resistor would survive.

    Aubess power monitor switch on a keyboard Electronic measurement devices on a laptop keyboard.

    The Tongou TO-Q-SY1-JWT is possibly the most promising. The Relay is bystable (it keeps states without power), so that means a failure won't result in loss of power to the house. It is rated up to 63A and it's relatively easy to program once open. But I don't like that it is riveted and so, it's hard to close it back again. It also seems to draw 1W regardless of what, so I wonder about the durability of the caps inside, which run pretty hot. The power supply regulates at 12V, for the relay, and an LM1113 steps down the power to the WiFi module. So 3x it's consumption are just wasted as heat.

    Tongou TO-Q-SY1-JWT relay held in hand Close-up of the bottom part of a device with mounting holes and markings. View of the interior of an electronic device with a 60A 250VAC relay.

    Another interesting device is The SMTONFF. It appears to be the same device covered (https://www.elektroda.com/rtvforum/ttopic4022907.html
    The WB3S module has to be removed to program and it's obviously a larger device. There are others that can be programmed as the WiFi module can be de-attached from tuya MCU, releasing the Serial port. (https://www.elektroda.com/rtvforum/topic3995777.html and https://www.elektroda.com/rtvforum/topic3933839.html)
    I am not fully sure how to read from the Tuya MCU - Who manages the communication with the BL0942 - guess I will figure that out.
    This device can easily be opened (only two screws on the back), however, it relies on a relay that must be constantly powered, so a failure of the device will result in loss of power to the circuits downstream. The current measurement is inline with the relay, so no option to bypass without modifying it. It also heats up a bit inside, drawing the same 0.8W whenever the relay is on or off - I suspect some kind of current limited shunt power supply.
    My version doesn't measure negative values, and since communication with the BL0942 is managed by the tuya MCU, I guess there is not much that can be done other than waiting for tuya to update it's firmware. I also found it annoying that the display shows KWh and instantaneous voltage and current, but not power.

    Electronic module lying on a table with components and pins. Close-up of internal electronic components of a power measurement device. Close-up of a PCB with a BL0942 chip and electronic components. SMTONFF measuring device with a digital display showing current and voltage values.

    If you know of any additional devices based on the BL0942 or how to get under the hood on the programing of the BL0942 under Openbecken, please write here. I think we can all benefit. Meanwhile I will slowly update as I make modifications to the devices.
  • ADVERTISEMENT
  • #2 21014044
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15

    Here's an overview using the AUBESS Power monitor switch, showing both positive and negative energy flow:
    Screenshot of the AUBESS power monitor switch interface showing parameters. Power monitor AUBESS screen displaying energy data.

    You can see in one direction there's about 0.7W more. That's due to the device measuring its own power consumption :-)

    For this to work, the following flag must be enabled under 'CONFIG' -> 'CONFIGURE GENERAL FLAGS'
    Screenshot of a flag setting in a software.

    Don't be fooled by the description, this doesn't work with the BL0937.
  • ADVERTISEMENT
  • #3 21014383
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14395
    Help: 650
    Rate: 12317
    Yes, you've found correctly - there is a flag to allow that. This is because in the past we had devices that reported negative current/power in idle.
    If you want to see how it's implemented in code, first see the BL0942 driver itself:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl0942.c
    Then you can check the shared code between BL0942, BL0937, and CSE, etc:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl_shared.c
    Does the flag suit your needs or should I add anything else soon?
    Helpful post? Buy me a coffee.
  • #4 21014898
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15

    p.kaczmarek2 wrote:
    Yes, you've found correctly - there is a flag to allow that. This is because in the past we had devices that reported negative current/power in idle.
    If you want to see how it's implemented in code, first see the BL0942 driver itself:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl0942.c
    Then you can check the shared code between BL0942, BL0937, and CSE, etc:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl_shared.c
    Does the flag suit your needs or should I add anything else soon?


    Hi p.kaczmarek2.

    Thanks for your help.
    That flag only solves half of the problem. It does give me instantaneous power in both positive and negative directions, but it doesn't solve the fact that the total counter only goes up, regardless of the power direction. There should be two counters and a check to increment the correct one based on the instantaneous power being positive or negative.
    Screenshot of an interface displaying electrical network parameters showing the device is off.
    I'll have a look into the code. Is there a way I can send binary data straight to the serial port on the Open becken firmware? That would help me debug the registers on the BL0942.
  • ADVERTISEMENT
  • #5 21014932
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14395
    Help: 650
    Rate: 12317
    There is no need for that. You can just search for "abs" in the code, here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl0942.c
    I think this fabs here may be the culprit, it was submitted by contributor some time ago:
    Code snippet showing a function calculating energy based on power scale.
    Do you want to get a build without this fabs?

    See: OpenBeken online building system - compiling firmware for all platforms (BK7231, BL602, W800, etc)
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #6 21015581
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15

    I was able to replicate this behavior on another system initialized with the defaults (only the command 0x58 and 0xAA given to the chip to perform a reading), so I don't think this is a coding issue, rather an initialization.

    If my understanding is right, the total counter is derived from reads to the CF_CNT register
    Diagram and table describing the CF_CNT register in the BL0942 system.

    Assuming that is true, this register is initialized by default as '0b1' which means the absolute value (positive) is accumulated. I think if we were to initialize it as 0, it would count negative. We could initialize it as: 0xA8(Write command);0x19(Address) and then the 3 bytes of data 0x00; 0x00 and 0x04, which keeps everything on its defaults, except bit 7 which is toggled from 1 to 0.
    Operating Mode Register table with descriptions and default values.

    Unfortunately I can't send them directly through the serial terminal, but I think the following line of code issued at the startup of the BL0942 driver would do the trick:

    UART_WriteReg(24, 4)


    Added after 50 [minutes]:

    Having a closer look at the code, it seems we could do something a bit different:

    It seems like the user mode register is initialized as 0x87, as suggested on the datasheet
    #define BL0942_MODE_DEFAULT 0x87


    I suggest, instead initializing it as 0x07. This effectively clears bit 7. It's then possible to write a define as below, in case we want to re-enable it.
    #define BL0942_MODE_CF_CNT_ADD_SEL (1 << 7)

  • #7 21016027
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14395
    Help: 650
    Rate: 12317
    I have approved your PR, so we should get binaries soon:
    Screenshot showing a webpage with a request to merge changes in the file drv_bl0942.c on the GitHub platform.
    What about that abs call? Did you remove it? The only change I see is:
    The image shows a proposed change in the drv_bl0942.c code file, where the value defined as BL0942_MODE_DEFAULT was changed from 0x87 to 0x07.
    Helpful post? Buy me a coffee.
  • #8 21016125
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15
    p.kaczmarek2 wrote:
    I have approved your PR, so we should get binaries soon:
    Screenshot showing a webpage with a request to merge changes in the file drv_bl0942.c on the GitHub platform.
    What about that abs call? Did you remove it? The only change I see is:
    The image shows a proposed change in the drv_bl0942.c code file, where the value defined as BL0942_MODE_DEFAULT was changed from 0x87 to 0x07.


    Thanks,
    I didn't remove the abs call, wanted to do one at a time.
    Do you know where I can download the binaries? Will they show here? Link
  • #9 21016416
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14395
    Help: 650
    Rate: 12317
    PR is not released yet. You need to download binaries from PR. See guide:
    p.kaczmarek2 wrote:
    Helpful post? Buy me a coffee.
  • #10 21016484
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15
    I checked this, but the images were 'skipped' according to this page

    Computer screen showing results of an application build process on GitHub.

    So I created my own fork. Removing the function results in the counter not working. I'm investigating why.
  • #11 21016717
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14395
    Help: 650
    Rate: 12317
    This skipped is not a problem. Only main release is skipped, binaries are still created.
    I am speaking about this PR:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1136
    https://github.com/openshwprojects/OpenBK7231T_App/actions/runs/8398182427?pr=1136
    Binaries are here:
    CI/CD actions summary on GitHub for the OpenBK7231T project.
    Helpful post? Buy me a coffee.
  • #12 21017599
    cdtdsilva
    Level 11  
    Posts: 164
    Help: 4
    Rate: 15
    I made a pull request to the OpenBK7231T_App repository with the changes to allow the BL0942 to measure forward and reverse energy flow.

    2 file edits: drv_bl0942.c & drv_bl_shared.c

    Summary of the changes:

    CF_CNT - the 24bit variable that collected the data from active energy accumulation could overflow, causing false readings periodically. The way this varianble reports data was changed, to be cleared after every reading (by setting CF_CNT_CLR_SEL (bit [6], reg 0x19) to one). This also simplifies the calculations, without a need to deduct previous readings (Values are simpply summed to those exixting).

    CF_CNT_ADD_SEL was set to it's default (bit [6], reg 0x19) - counting positive, so the variable doesn't roll over. In order to identify the direction of power flow, CF_REVP_F (bit [0], reg 0x09) is monitored. This bit indicates the direction of the last energy Pulse CF
    0: forward; 1: reverse. Therefore when performing the reading, the value of CF_CNT (Accumulated energy) can be assigned to either the forward or reverse register. At the moment, being there is only one counter register, it increases it or decreases it. In order to get this behaviour, a line on the drv_bl_shared.c file had to be commented out, to allow negative values.

    One other modification: register 0x14 (Active power anti-passage register) was programmed to zero out the instantaneous power at idle (for example, when device measures noise or it's own power consumption). A Value of 64 works well and still allows a 6W light bulb power consumption to be measured. It would be good to have an entry on webpage to adjust this value.

    Energy monitoring panel OpenBK7231N with negative power reading. Screenshot of the OpenBK7231N user interface with active power measurement mode.

    The 'Periodic Statistics' doesn't work well under negative flow. As it can be seen on the pictures above, only the first value can be read negative. Following ones default to zero, which caps the field 'Consumption (during this period)'.

    Where I now need help:
    Fix the inability of the periodic statistics to deal with negative readings
    Add 3 counters, instead of 1, for total power.

    - Forward Energy (Consumption)
    - Reverse Energy (Production)
    - Absolute Energy (Consumption - Production)

    I would like statistics to apply to the "absolute energy" - with an option to set a timer, with an adjustable duration, to reset it. This is to assist with net metering, where utilities allow 15 or 60minutes net metering. After that period, any left over unused energy is 'given' to the network, so the counter should be reset.

Topic summary

✨ The discussion centers on the challenges and solutions related to measuring negative AC power flow using Tuya devices, particularly in the context of solar energy systems. Users highlight the importance of measuring both consumption and export of energy to optimize self-consumption of solar power. The AUBESS Power monitor switch is mentioned as capable of showing both positive and negative energy flow, but issues arise with total energy counters only incrementing positively. Solutions involve modifying firmware, specifically the BL0942 driver, to implement dual counters for positive and negative energy flow. Key modifications include adjusting the CF_CNT register initialization and monitoring the CF_REVP_F bit to determine energy direction. Users share code snippets and links to repositories for further development and troubleshooting.
Generated by the language model.

FAQ

TL;DR: “You can see in one direction there’s about 0.7W more.” Enable OpenBeken’s negative-power flag on BL0942-based Tuya meters (e.g., AUBESS) to view export/import; BL0937 won’t show direction. [Elektroda, cdtdsilva, post #21014044]

Why it matters: Solar users need true bidirectional power to automate self-consumption and avoid undercounting exports.

Quick Facts

What’s the practical difference between BL0937 and BL0942 for solar import/export metering?

BL0937 is an 8‑pin pulse chip that reports absolute power only. It cannot indicate direction, and deep-sleep can skip pulses, degrading accuracy. BL0942 is a 10‑pin serial chip with full power and direction data. Many Tuya firmwares read only absolute values, so flash OpenBeken to expose directional readings. For solar, choose BL0942-based hardware and firmware that preserves sign. “Most devices only consume power,” so direction wasn’t prioritized in legacy designs. [Elektroda, cdtdsilva, post #21012850]

Which Tuya meters can read negative power flow out of the box or after flashing?

Reported devices using BL0942 include AUBESS, Tongou TO‑Q‑SY1‑JWT, and an SMTONFF variant. AUBESS is easy to open and program, but limited to 16A. Tongou supports up to 63A and uses a bistable relay. Some SMTONFF units route BL0942 via a Tuya MCU, so negative direction may be blocked by stock firmware. When the Tuya MCU controls BL0942, you might need firmware updates or a different device. [Elektroda, cdtdsilva, post #21012850]

How do I enable negative power readings in OpenBeken?

Enable the dedicated flag in OpenBeken: CONFIG → CONFIGURE GENERAL FLAGS. This exposes negative values on BL0942 devices, letting you see export/import in Live View. “For this to work, the following flag must be enabled” and note the setting does not apply to BL0937 hardware. After enabling, compare readings under load in both directions. If you see a small offset, it’s likely device self‑consumption. [Elektroda, cdtdsilva, post #21014044]

Why do my kWh totals only increase even when I’m exporting power?

By default, cumulative energy adds absolute values and ignores direction. The fix is to separate accumulation by direction or change BL0942 initialization so firmware can assign pulses to forward or reverse counters. The author requested two counters and noted the single total counter “only goes up.” Polling instantaneous power and reconstructing totals is a temporary workaround until firmware maintains separate import and export totals. [Elektroda, cdtdsilva, post #21014898]

What firmware changes were proposed to make BL0942 track forward and reverse energy correctly?

The PR clears CF_CNT on each read (enabling CF_CNT_CLR_SEL), simplifying accumulation and avoiding overflow artifacts. It keeps CF_CNT_ADD_SEL counting positive to prevent rollovers, and determines direction using CF_REVP_F, assigning pulses to forward or reverse. The anti‑passage register (0x14) is set to 64 to zero idle noise while still detecting a 6W bulb. Periodic Statistics currently mishandle negative values and need fixes. [Elektroda, cdtdsilva, post #21017599]

Do I need to remove the fabs/fabsf call in the driver to get negative values?

Not directly. A contributor suspected fabs, but removing fabsf caused the counter to stop working in testing. Address initialization and counter logic first. Directional logic via BL0942 registers and proper accumulation solves the core issue. If you still need to change math operations, proceed cautiously and test counters thoroughly after each change. [Elektroda, cdtdsilva, post #21016484]

Where do I download OpenBeken binaries that include the BL0942 fixes?

They are attached to the GitHub Actions build for the pull request, not the main release. Look at the PR’s Actions run and download artifacts from there. “Skipped is not a problem. Only main release is skipped, binaries are still created.” Grab the image matching your platform from the PR run page. [Elektroda, p.kaczmarek2, post #21016717]

How can I integrate directional energy with Home Assistant today?

Poll instantaneous power and reconstruct consumption and export in your controller. Use the sign of instantaneous power to increment separate import/export counters and compute net energy. The thread author suggested polling as an interim solution while firmware counters evolve. This approach works with OpenBeken exposing signed power values from BL0942. Later, switch to native counters when available. [Elektroda, cdtdsilva, post #21012850]

How does the anti‑passage threshold improve low‑power accuracy?

Setting the BL0942 anti‑passage register (0x14) to 64 zeros out idle noise and self‑consumption. It still detects a 6W light bulb, preserving low‑load visibility. This reduces false readings at no-load and stabilizes export/import near zero. You can expose this threshold as a tunable parameter for your installation if firmware adds UI support. It improves clarity around small parasitic loads and noise. [Elektroda, cdtdsilva, post #21017599]

Are there thermal or reliability concerns with these DIN devices?

Tongou’s supply regulates at 12V and uses an LM1113 step‑down, wasting heat; the unit draws about 1W continuously, warming capacitors. SMTONFF variants draw about 0.8W regardless of relay state and lose downstream power if they fail because the relay must stay powered. AUBESS routes current through PCB traces, so 16A is its practical limit and short circuits may stress the shunt. [Elektroda, cdtdsilva, post #21012850]

Why do readings differ by about 0.7W when power flow reverses?

That offset reflects the meter’s own self‑consumption. The author demonstrated about 0.7W higher in one direction and identified it as the device powering itself. Expect small offsets to persist across polarity changes. Quote: “You can see in one direction there’s about 0.7W more.” Account for this in automations that trigger on near‑zero thresholds to avoid chatter. [Elektroda, cdtdsilva, post #21014044]

Can BL0937-based devices ever show export vs import?

No. BL0937 reports absolute power via pulses and lacks direction information. It was designed for consumption metering. Deep sleep can also skip pulses, corrupting totals. If you need direction, choose BL0942 hardware and compatible firmware. That gives phase‑aware measurement and signed power essential for solar export detection and self‑consumption control. [Elektroda, cdtdsilva, post #21012850]

How easy are these units to open and flash? Any gotchas?

AUBESS is easy to open and program, with a neutral‑cut relay you can bypass in wiring. Tongou has a riveted enclosure that’s harder to reassemble. Some SMTONFF units require removing the WB3S Wi‑Fi module to access programming. If the Tuya MCU owns BL0942, you may not get directional data until firmware changes. Plan access before installation. [Elektroda, cdtdsilva, post #21012850]

Why does Wi‑Fi perform poorly inside my metal fuse box?

Metal enclosures shield and ground RF, attenuating 2.4GHz signals heavily. The author noted Wi‑Fi “kills” inside grounded metal boxes. Consider external antennas, repositioning the radio, or alternative links like CC1101 with a separate microcontroller to reach the meter. That preserves telemetry when the enclosure blocks Wi‑Fi. [Elektroda, cdtdsilva, post #21012850]

How do I enable negative flow on an AUBESS/BL0942 device in three steps?

  1. Flash OpenBeken onto the BL0942-based device (e.g., AUBESS).
  2. In CONFIG → CONFIGURE GENERAL FLAGS, enable the negative-power direction display.
  3. Verify Live View shows positive and negative readings; expect ~0.7W offset from self-consumption near zero. [Elektroda, cdtdsilva, post #21014044]
Generated by the language model.
ADVERTISEMENT