logo elektroda
logo elektroda
X
logo elektroda

Implementing Moving Average for BL0942+BL0937 Power and Current in OBK

XJ_ 2949 4
ADVERTISEMENT
📢 Listen (AI):
  • Graph comparing the effect of different moving average settings on data.
    I've created a moving average modification for OpenBeken (BL0942+BL0937) for power and current values. Thanks to this, you can smooth the fluctuating power and current values, ​​so that they are more informative at first glance.

    So, if you have energy measuring devices like these (having energy monitor):
    EU smart plug with power monitor and 16A/20A current. Electrical installation diagram with a measuring device. AUBESS 16A smart switch module with power monitoring.
    You can use my mod based on a simple calculation, it averages the fluctuating power and current values .

    Reason: I have multiple devices (heating) at home that change the power input in seconds PWM (this way it controls the temperature proportionally). Thus, the value in HASS and OBK too "jumps". This mod allows you to activate values ​​averaging. The output is then smoother.

    For example, if you have a device that has 1000W and that out of 10 seconds interval is 4 seconds on and 6 seconds off, you normally see the same thing on the website or in HASS. For 4 seconds is there 1000W, and for 6 seconds is there 0W. So it depends on when you look at the website.

    When using this mod, you will see a value of 400W all the time. However, it will take a while for it to reach 400W, and similarly it will take a while for it to drop to 0. The speed depends on the setMovingAvg setting.

    It is clearly visible in the attached graph and the values ​​from the graph are in the table.

    Graph comparing the effect of different moving average settings on data.

    The grand total for a period of time is almost the same as the total without averaging (due to the averaging).

    Use this guide to build, firmware can be built on Github:
    https://www.elektroda.com/rtvforum/topic4033833.html
    Set ENABLE_BL_MOVINGAVG in obk_config.h.

    ENABLE_BL_MOVINGAVG is disabled by default. To make it working, it must be turned on for compilation in obk_config using ENABLE_BL_MOVINGAVG 1
    And in autoexec.bat the appropriate setMovingAvg value:
    - 2..20 to activate the average - higher value, slower changes
    - 0 or 1 is disabled (default)

    --------------------------------------------------------------------------------------------------------------------------------------
    Important !!!
    It only makes sense if the power interval has the same period. It must be basically the equivalent to PWM with "seconds" interval.
    --------------------------------------------------------------------------------------------------------------------------------------


    For BL0942 this does not affect the energy, the energy is calculated directly on BL0942.
    For others (BL0937, CSE7766, RN8209) the energy is calculated from the averaged values ​​(if setMovingAvg is set).

    Value flow in time - sample values used in graph:

    Table with raw power values and moving averages for different periods.

    Cool? Ranking DIY
    About Author
    XJ_
    Level 11  
    Offline 
    XJ_ wrote 135 posts with rating 32, helped 11 times. Been with us since 2024 year.
  • ADVERTISEMENT
  • #2 21500195
    p.kaczmarek2
    Moderator Smart Home
    Good job. This graph indeed looks much better and much much more readable, but I have a question about this:
    XJ_ wrote:

    For others (BL0937, CSE7766, RN8209) the energy is calculated from the averaged values ​​(if setMovingAvg is set).

    Is this the preferred behaviour or is it a byproduct of the implementation?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21500208
    XJ_
    Level 11  
    p.kaczmarek2 wrote:
    Is this the preferred behaviour or is it a byproduct of the implementation?


    I didn't change that, it's already so in the code. But the functionality will be similar, only the BL0942 measures the energy itself and is more accurate. The others sending NAN and because of that the energy is calculated internaly in OBK.

    Screenshot of a code editor displaying a section of a C program.

    Search results for BL_ProcessUpdate in source code projects.
  • ADVERTISEMENT
  • #4 21500693
    p.kaczmarek2
    Moderator Smart Home
    I am starting to think that I need your mod:
    Data chart showing information on voltage, current, and power.
    Helpful post? Buy me a coffee.
  • #5 21500858
    XJ_
    Level 11  
    >>21500693
    The calculation is based on and conditioned by the regularity of changes, it does not address the time between changes. But doesn't the OBK measurement run via runeverysecond? Then it would work normally.

    Added after 3 [minutes]:

    >>21500693
    A chart using a moving average looks much nicer indeed, doesn't it?
📢 Listen (AI):
ADVERTISEMENT