diff --git a/src/panels/lovelace/cards/energy/common/energy-chart-options.ts b/src/panels/lovelace/cards/energy/common/energy-chart-options.ts index 0636e4cee34d..01b4d869349d 100644 --- a/src/panels/lovelace/cards/energy/common/energy-chart-options.ts +++ b/src/panels/lovelace/cards/energy/common/energy-chart-options.ts @@ -31,7 +31,11 @@ import { formatTime } from "../../../../../common/datetime/format_time"; import type { ECOption } from "../../../../../resources/echarts/echarts"; import { filterXSS } from "../../../../../common/util/xss"; -export function getSuggestedMax(dayDifference: number, end: Date): number { +export function getSuggestedMax( + dayDifference: number, + end: Date, + detailedDailyData = false +): number { let suggestedMax = new Date(end); // Sometimes around DST we get a time of 0:59 instead of 23:59 as expected. @@ -40,7 +44,9 @@ export function getSuggestedMax(dayDifference: number, end: Date): number { suggestedMax = subHours(suggestedMax, 1); } - suggestedMax.setMinutes(0, 0, 0); + if (!detailedDailyData) { + suggestedMax.setMinutes(0, 0, 0); + } if (dayDifference > 35) { suggestedMax.setDate(1); } @@ -77,7 +83,8 @@ export function getCommonOptions( unit?: string, compareStart?: Date, compareEnd?: Date, - formatTotal?: (total: number) => string + formatTotal?: (total: number) => string, + detailedDailyData = false ): ECOption { const dayDifference = differenceInDays(end, start); @@ -89,7 +96,7 @@ export function getCommonOptions( xAxis: { type: "time", min: start, - max: getSuggestedMax(dayDifference, end), + max: getSuggestedMax(dayDifference, end, detailedDailyData), }, yAxis: { type: "value", diff --git a/src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts b/src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts index fb6a4599e0f9..55f3c2b71a98 100644 --- a/src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts +++ b/src/panels/lovelace/cards/energy/hui-power-sources-graph-card.ts @@ -1,4 +1,4 @@ -import { endOfToday, isToday, startOfToday } from "date-fns"; +import { endOfToday, isSameDay, isToday, startOfToday } from "date-fns"; import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket"; import type { PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; @@ -132,7 +132,9 @@ export class HuiPowerSourcesGraphCard config, "kW", compareStart, - compareEnd + compareEnd, + undefined, + true ), legend: { show: this._config?.show_legend !== false, @@ -210,9 +212,12 @@ export class HuiPowerSourcesGraphCard const { positive, negative } = this._processData( statIds[key].stats.map((id: string) => { const stats = energyData.stats[id] ?? []; - const currentState = getPowerFromState(this.hass.states[id]); - if (currentState !== undefined) { - stats.push({ start: now, end: now, mean: currentState }); + if (isSameDay(now, this._start) && isSameDay(now, this._end)) { + // Append current state if we are showing today + const currentState = getPowerFromState(this.hass.states[id]); + if (currentState !== undefined) { + stats.push({ start: now, end: now, mean: currentState }); + } } return stats; })