Clamp negative untracked energy to zero in detail graph#51623
Clamp negative untracked energy to zero in detail graph#51623loganrosen wants to merge 2 commits into
Conversation
Extract computeUntrackedConsumption() as a pure function in energy-chart-options.ts and use it in the devices detail graph card. Negative untracked values arise from meter resolution mismatches (e.g., integer grid meter reports 0 kWh while fractional device sensors report 0.2+ kWh). The other energy cards (pie, sankey, power-sankey) already guard against this with scalar checks; only the detail graph card was missing the clamp. Fixes home-assistant/core#125362 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
I am not sure about this one. Both sides make sense. |
|
Hi @loganrosen - Thanks for this. Now for my UX two cents. For consistency clamping to zero makes sense. But NOT fully silently (as you say.. "a dedicated warning or notification would be far more effective..." When there is a mismatch we should surface a small indicator below the graph, or a warning (maybe not a warning icon or something alarming, but something to indicate something to look at) on the untracked item. That keeps the value without needing a negative bar. Let me know where you think works best, (some screenshots if possible!) and we'll give some design direction. |
I don't think the chart should be hiding such edge cases where the data is plain wrong. What if your main grid sensor broke? We should not hide that. So even if we change this from negative bars to any kind of warning, you'll still see something wrong because your data for the day is just wrong. |
I have no gridsensor i am getting data from Tibber addon. |
You kind of have the option, you can go to untracked energy in the legend and turn it off, if your setup doesn't provide you enough high-fidelity data to make use of it. Then you won't see it anymore. |
I don't want to turn it off i just don't want it to show negative values for the last day. |
This is incorrect. Legend selection is remembered on the device. So you only have to do it once per device.
HA already has an incredible number of options and we get many requests for new options every day? It is unsustainable to add an option for every little thing. |
I don't want to hide it i just want to get rid of negative untracked consumption for the last day. |
For me it shows everytime it doesn't even work to turn it off i have to change date and then back again. |
When tracked devices report more energy than total grid consumption (common with integer-resolution meters), untracked energy is clamped to zero. This adds: - Info banner below chart explaining the adjustment - Tooltip info line showing the actual excess per bar - rawNegatives tracking in computeUntrackedConsumption Note: tooltip text is hardcoded in English since formatTooltip() lacks access to hass.localize() and the entire energy-chart-options file has zero localization calls. This can be addressed separately. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Marking as draft, also has conflicts to resolve |


Proposed change
Clamp negative "untracked" energy values to zero in the devices detail graph card.
The problem
When a grid meter has lower resolution than individual device sensors (e.g., an integer-resolution smart meter reporting 0 kWh while fractional device sensors report 0.2+ kWh), the untracked calculation produces negative values:
untracked = 0 - 0.2 = -0.2 kWh. These appear as confusing negative bars in the detail graph.This affects many users — core#125362 has 35 unique commenters and 10 upvotes, with the majority finding negative untracked energy confusing and misleading.
Prior discussion
This behavior was discussed in #23893: during the ECharts migration, @MindFreeze initially clamped negatives to zero, then reverted after @karwosts (who implemented the original untracked feature in #21632) argued that negative values serve as a diagnostic signal for misconfigured sensors.
However, I believe clamping is the right choice:
Consistency: The pie chart, sankey, and power-sankey cards already clamp negative untracked values (with
> 0or> 1guards). Only the detail graph card shows negatives, creating an inconsistent user experience.The diagnostic argument is undermined in practice. Most users seeing negative values have integer-resolution meters, not misconfigured sensors. A silent negative bar with no explanation doesn't help anyone diagnose anything — a dedicated warning or notification would be far more effective.
User impact. The 35+ users on core#125362 overwhelmingly find negative untracked values confusing rather than useful.
What this PR does
computeUntrackedConsumption()function inenergy-chart-options.tsMath.max(0, ...)The other cards use scalar (not per-timestamp) untracked values and already have their own guards, so they are not changed here.
Type of change
Additional information
Checklist
To help with the load of incoming pull requests: