Skip to content

HA discovery: total_increasing state_class only for Energy Total and Energy Today - #2308

Open
xjikka wants to merge 3 commits into
openshwprojects:mainfrom
xjikka:main
Open

xjikka wants to merge 3 commits into
openshwprojects:mainfrom
xjikka:main

Conversation

@xjikka

@xjikka xjikka commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Home Assistant discovery currently gives every energy-class sensor state_class: total_increasing. Several of them can decrease:

  • Energy Last Hour is a rolling sum over the stats period,
  • Energy Yesterday, 2 Days Ago and 3 Days Ago shift once a day and can go up or down (in BL twin mode the _b variants as well).

HA reads each decrease as a meter reset. The result:

  • a daily warning in the HA log:
    Entity sensor.xxx_energy_yesterday from integration mqtt has state class total_increasing, but its state is not strictly increasing. Triggered by state 7.827 (previous state: 8.436)
  • long-term statistics for these sensors that make no sense, because every "reset" adds the whole new value again.

Change: stat_cla: total_increasing is sent only for OBK_CONSUMPTION_TOTAL and OBK_CONSUMPTION_TODAY; the other energy sensors get no stat_cla. measurement would not work, because HA does not allow it with device_class: energy. Energy Today still works as expected, since HA handles its midnight reset as a new meter cycle. The check is on the sensor index, and both BL twin datasets use the same index, so it covers twin mode too.

The selftest Test_HassDiscovery expected total_increasing for energycounter_last_hour; it now checks the sensor without stat_cla.

Tested: HA 2026.10, 12 devices (BK7231N + BL0937, LN882H, BK7231N BL0942 twin). Energy Last Hour, Yesterday, 2 and 3 Days Ago come without stat_cla, Energy Total and Today keep total_increasing, other entities unchanged.

Yesterday's consumption changes once a day in both directions, so HA logs
'state class total_increasing, but its state is not strictly increasing'
and long-term statistics are wrong. Other energy sensors keep total_increasing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant