From 4930eb2e45d91c170526543e65b1ab3d0ae3ce48 Mon Sep 17 00:00:00 2001 From: BrettS Date: Mon, 1 Dec 2025 17:23:29 +0100 Subject: [PATCH] Add all counters to history chart --- .../charts/historyChart/HistoryChart.vue | 21 ++++++++++++ .../koala/source/src/stores/mqtt-store.ts | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue index 4ac4acbd29..942141836d 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/historyChart/HistoryChart.vue @@ -118,6 +118,26 @@ const chartRange = computed( () => mqttStore.themeConfiguration?.history_chart_range || 3600, ); +const secondaryCounterDatasets = computed(() => + mqttStore.getSecondaryCounterIds.map((id) => ({ + label: mqttStore.getComponentName(id), + category: 'component', + unit: 'kW', + borderColor: '#FFA9A8', + backgroundColor: 'rgba(255,169,168, 0.2)', + data: selectedData.value.map((item) => ({ + x: item.timestamp * 1000, + y: item[`counter${id}-power`] ?? 0, + })), + borderWidth: 2, + pointRadius: 0, + pointHoverRadius: 4, + pointHitRadius: 5, + fill: true, + yAxisID: 'y', + })), +); + const chargePointDatasets = computed(() => chargePointIds.value.map((cpId) => ({ label: `${chargePointNames.value(cpId)}`, @@ -233,6 +253,7 @@ const lineChartData = computed(() => { fill: true, yAxisID: 'y', }, + ...secondaryCounterDatasets.value, { label: 'PV ges.', category: 'component', diff --git a/packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts b/packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts index 25b4a837a4..bad1ca5fcf 100644 --- a/packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts +++ b/packages/modules/web_themes/koala/source/src/stores/mqtt-store.ts @@ -3288,6 +3288,38 @@ export const useMqttStore = defineStore('mqtt', () => { return undefined; }); + + /** + * Get all counter ids from component hierarchy + * @returns number[] + */ + const getAllCounterIds = computed(() => { + const hierarchy = getValue.value('openWB/counter/get/hierarchy') as + | Hierarchy[] + | undefined; + const getCounterIds = ( + nodes: Hierarchy[] | undefined, + allCounters: number[] = [], + ): number[] => { + if (!nodes) return allCounters; + nodes.forEach((node) => { + if (node.type === 'counter') allCounters.push(node.id); + allCounters = getCounterIds(node.children, allCounters); + }); + return allCounters; + }; + return getCounterIds(hierarchy); + }); + + /** + * Get all secondary counter ids from all configured counters excluding the grid counter + * @returns number[] + */ + const getSecondaryCounterIds = computed(() => { + const rootCounter = getGridId.value; + return getAllCounterIds.value.filter((id) => id !== rootCounter); + }); + /** * Get the power meter(counter) name identified by the Grid ID * @param counterId counter ID @@ -3670,6 +3702,8 @@ export const useMqttStore = defineStore('mqtt', () => { batteryMode, // Grid data getGridId, + getAllCounterIds, + getSecondaryCounterIds, getComponentName, getGridPower, gridDailyImported,