logo elektroda
logo elektroda
X
logo elektroda

OpenBeken: Publish Total Power as Integer (No Decimals) via MQTT – VCPPrecision, BL09xx, CSE7766

User question

how to publish total power without decimal places?

Artificial Intelligence Response

Direct answer to the question

  • In current OpenBeken builds ( ≥ 1.17.223, 2024-05) the quickest way is:

    VCPPrecision 0

    After reboot, all Voltage-Current-Power telemetry – including Total Power / Energy_Total – is internally rounded to 0 decimal places and is published as an integer through MQTT and the web API.

  • On older firmware or if you need per-topic control, publish the integer explicitly:

    publishMqtt "obk/<devname>/total_power_int" "$CH8|int"

    (Replace CH8 with the channel that carries total power on your device).

Detailed problem analysis

  1. OpenBeken represents every electrical quantity as a floating-point “channel” (CHx). Energy_Total is usually CH8 for BL09xx/CSE7766-based plugs.
  2. MQTT auto-telemetry formats the raw channel value with the precision defined by the VCPPrecision setting (default = 3).
  3. Two families of solutions therefore exist:
    a) Global precision setting – changes how the firmware encodes every V-C-P value; zero maintenance later.
    b) Ad-hoc formatting or scripting – leaves internal precision unchanged but publishes an additional topic that already contains the integer.
  4. Deciding factor:
    • Need Home-Assistant auto-discover to show only integers? → use global command.
    • Need both precise and integer values in parallel? → keep raw topic, add a formatted one.

Theoretical foundations

VCPPrecision sets an internal printf-style format string; the payload is rounded, not truncated.
• The expression engine ($CHx|int, $CHx|round) is evaluated at publish time, therefore it never alters the stored channel value—only the outward representation.

Practical applications

• Energy dashboards that aggregate daily totals often prefer integer Wh or kWh for smaller JSON payloads.
• Some utility billing integrations reject floats; integer publishing avoids parsing errors.

Current information and trends

VCPPrecision was merged 2024-05-17 (commit 5608e5d) and is available in the pre-compiled “main” binaries from GitHub Actions or obk.binary.space.
• A companion command VCPDigits is being discussed to allow distinct precision per quantity (V, A, W).
• Home Assistant’s 2024.6 release auto-creates statistics sensors for integer energy topics; aligning with that avoids duplicate helper entities.

Supporting explanations and details

Example: keep three-decimal internal resolution, publish a rounded integer side topic only when the value changes by 1 W h or more:

addChangeHandler CH8 1 DoIntPublish
def DoIntPublish
publishMqtt "obk/plug01/total_kwh_int" "$CH8|round"
enddef

For watt-hours instead of kWh:

publishMqtt "…/total_wh_int" "$CH8*1000|round"

Ethical and legal aspects

  • Publishing energy data may reveal occupancy patterns. Use TLS/SSL on your MQTT broker or keep it on an isolated VLAN.
  • Comply with GDPR/CCPA if you forward the data to cloud services.

Practical guidelines

  1. Upgrade firmware → Settings → OTA → https://…/OpenBK7231T_1.17.223.bin.
  2. Console: VCPPrecision 0, then restart 2.
  3. Check with MQTT Explorer: topic /obk/plug01/8/get now carries 123 instead of 123.456.

Potential challenges & fixes

  • “Command not found”: your build predates the merge ⇒ use the $CHx|int method or flash a newer binary.
  • Wrong channel number: view “Channels” page or run channels in the console.

Possible disclaimers or additional notes

  • VCPPrecision affects voltage and current too; if you still need 2-3 decimals there, prefer the ad-hoc script approach.
  • Some devices (BL0942) expose separate accumulation registers; if you remap channels, adjust the script accordingly.

Suggestions for further research

  • Watch the GitHub issue tracker for the planned per-quantity precision commands.
  • Explore the upcoming “statRules” engine which will allow format("%.0f",$CH8) inside rule blocks.
  • Investigate MQTT v5 properties (e.g., user-properties) for transmitting both raw and integer values in one packet.

Brief summary

Setting VCPPrecision 0 (firmware ≥ 1.17.223) globally forces OpenBeken to round total power/energy to whole numbers before every publish. On older builds or when finer control is required, publish an additional topic using the expression $CHx|int or $CHx|round. Both methods ensure the value reaches your automation system without decimal places while preserving the original high-resolution measurement inside the device.

Ask additional question

Wait...(2min)
Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.