logo elektroda
logo elektroda
X
logo elektroda

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

StrictFilterFlow 228 0
ADVERTISEMENT
  • Live HA discovery still publishes Wh despite flag 40 enabled

    #1 21932955
    StrictFilterFlow
    Level 1  
    Posts: 1
    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:
    Enable Flag 40 via SetFlag 40 1
    Confirm it's checked on the Config → General/Flags web page
    Restart the device
    Fully delete the device/entities from Home Assistant to eliminate any legacy state
    Purge all Home Assistant recorder history/statistics for the related entities (recorder.purge_entities, keep_days: 0) to eliminate any stale statistics metadata
    Trigger a fresh discovery via scheduleHADiscovery (or the "Do Discovery" button on the device's own Home Assistant Configuration page)
    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.
  • ADVERTISEMENT
ADVERTISEMENT