Skip to content

Flag 40 (MQTT energy in kWh) confirmed enabled in UI, but live HA discovery still publishes Wh #2155

Description

@snaggyelk

Firmware version: OpenBK7231T 1.18.297, built Jul 3 2026
Chipset: BK7231T
Driver: BL0937
MQTT integration: Home Assistant, via standard MQTT discovery

Description:

Flag 40 ("[MQTT] Use kWh unit for energy consumption") is confirmed enabled and persists correctly across reboots (verified directly on the device's Config → General/Flags page). However, the live MQTT Home Assistant discovery payload for the energy sensors (Energy Total, Energy Last Hour) continues to declare unit_of_meas: "Wh", not "kWh", as if the flag were off.
I traced the relevant firmware source and confirmed the logic should work:

  • src/httpserver/hass.c line 914: cJSON_AddStringToObject(info->root, "unit_of_meas", CFG_HasFlag(OBK_FLAG_MQTT_ENERGY_IN_KWH) ? "kWh" : "Wh");
  • src/driver/drv_bl_shared.c line 613-618 (BL_ChangeEnergyUnitIfNeeded): correctly scales the value by 0.001 when the flag is set.

Despite this, the live output does not reflect the flag state.

Steps to reproduce:

  1. Enable Flag 40 via SetFlag 40 1
  2. Confirm it's checked on the Config → General/Flags web page
  3. Restart the device
  4. Fully delete the device/entities from Home Assistant to eliminate any legacy state
  5. Purge all Home Assistant recorder history/statistics for the related entities (recorder.purge_entities, keep_days: 0) to eliminate any stale statistics metadata
  6. Trigger a fresh discovery via scheduleHADiscovery (or the "Do Discovery" button on the device's own Home Assistant Configuration page)
  7. Check the resulting HA entity's unit_of_measurement attribute

Result: Still Wh, despite flag being confirmed on and all legacy HA-side state (both entity registry and statistics history) having been eliminated beforehand.
Expected: kWh, per the flag description and the source code logic.

Additional notes:

  • At one earlier point in a longer testing session, this did work correctly — confirmed via Home Assistant statistics metadata that briefly recorded kWh for this same sensor — but it has not been reproducible since, despite repeated attempts.

  • Happy to test a debug/logging build, or provide device console output during a discovery event, if that would help narrow this down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions