From 8d42395938006e16aafea9c19c84fea684e2b235 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Fri, 6 Mar 2026 19:42:52 +0100 Subject: [PATCH] Fix stale data point in history-graph cards with sub-hour windows (#29998) Skip fetching hourly statistics when hours_to_show < 1 since hourly aggregates produce stale outlier points in sub-hour chart windows (e.g. hours_to_show: 0.1 or 0.05). Also fix Date object handling in ha-chart-base downsampling bounds extraction. --- src/components/chart/ha-chart-base.ts | 18 ++++++++++++++---- .../lovelace/cards/hui-history-graph-card.ts | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index e0c759cdfc..19f1d1bbe3 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -877,10 +877,20 @@ export class HaChartBase extends LitElement { }; } if (s.sampling === "minmax") { - const minX = - xAxis?.min && typeof xAxis.min === "number" ? xAxis.min : undefined; - const maxX = - xAxis?.max && typeof xAxis.max === "number" ? xAxis.max : undefined; + const minX = xAxis?.min + ? xAxis.min instanceof Date + ? xAxis.min.getTime() + : typeof xAxis.min === "number" + ? xAxis.min + : undefined + : undefined; + const maxX = xAxis?.max + ? xAxis.max instanceof Date + ? xAxis.max.getTime() + : typeof xAxis.max === "number" + ? xAxis.max + : undefined + : undefined; return { ...s, sampling: undefined, diff --git a/src/panels/lovelace/cards/hui-history-graph-card.ts b/src/panels/lovelace/cards/hui-history-graph-card.ts index b570839860..23e40041f8 100644 --- a/src/panels/lovelace/cards/hui-history-graph-card.ts +++ b/src/panels/lovelace/cards/hui-history-graph-card.ts @@ -185,6 +185,10 @@ export class HuiHistoryGraphCard extends LitElement implements LovelaceCard { } private async _fetchStatistics(sensorNumericDeviceClasses: string[]) { + if (this._hoursToShow < 1) { + // Statistics are hourly aggregates, not useful for sub-hour windows + return; + } const now = new Date(); const start = new Date(); start.setHours(start.getHours() - this._hoursToShow - 1);