diff --git a/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/EnergyFlowChart.vue b/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/EnergyFlowChart.vue index 2017b1dfc8..10e5620661 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/EnergyFlowChart.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/EnergyFlowChart.vue @@ -144,8 +144,10 @@ const notInHomeVariants = { iconColor: 'var(--q-secondary-counter-stroke)', }, }; +// follows the counters listed in the details: if all of them are hidden, the +// node only shows consumers const notInHomeVariant = computed(() => { - if (!countersNotInHome.value) { + if (mqttStore.shownCounterIds.notInHome.length === 0) { return notInHomeVariants.consumer; } return mqttStore.notInHomeConsumption.consumerIds.length > 0 @@ -171,12 +173,12 @@ const openDetails = (event: MouseEvent, component: FlowComponent) => { const homeHasDetails = computed( () => mqttStore.inHomeConsumption.consumerIds.length > 0 || - mqttStore.inHomeConsumption.counterIds.length > 0, + mqttStore.shownCounterIds.inHome.length > 0, ); const notInHomeHasDetails = computed( () => mqttStore.notInHomeConsumption.consumerIds.length > 0 || - mqttStore.notInHomeConsumption.counterIds.length > 0, + mqttStore.shownCounterIds.notInHome.length > 0, ); const showConsumerPower = computed( () => diff --git a/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/HomeConsumptionDetailsDialog.vue b/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/HomeConsumptionDetailsDialog.vue index cabef6a752..833f60e57c 100644 --- a/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/HomeConsumptionDetailsDialog.vue +++ b/packages/modules/web_themes/koala/source/src/components/charts/energyFlowChart/HomeConsumptionDetailsDialog.vue @@ -77,10 +77,11 @@ const visible = computed({ }); const items = computed((): DetailsItem[] => { - const { consumerIds, counterIds } = + const { consumerIds } = props.scope === 'inHome' ? mqttStore.inHomeConsumption : mqttStore.notInHomeConsumption; + const counterIds = mqttStore.shownCounterIds[props.scope]; const unmeasured = props.scope === 'inHome' && mqttStore.unmeasuredHomeConsumptionPower('value') !== undefined @@ -109,7 +110,7 @@ const items = computed((): DetailsItem[] => { color: mqttStore.secondaryCounterColor(id) || 'var(--q-secondary-counter-stroke)', - power: mqttStore.counterPower('textValue', id) as string, + power: mqttStore.counterLocalPower('textValue', id) as string, })), ...unmeasured, ]; 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 b245f09246..17ba8a3dbb 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 @@ -4267,6 +4267,32 @@ export const useMqttStore = defineStore('mqtt', () => { }; }); + /** + * Get the counter's own share of power: its power minus the power of the + * components directly below it. identified by counterId + * @param returnType type of return value, 'textValue', 'value', 'scaledValue', 'scaledUnit' or 'object' + * @param counterId counter ID + * @returns string | number | ValueObject | undefined + */ + const counterLocalPower = computed(() => { + return (returnType: string = 'textValue', counterId?: number) => { + const id = counterId; + let localPower = undefined; + if (id !== undefined) { + localPower = getValue.value(`openWB/counter/${id}/get/local_power`) as + number | undefined; + } + const valueObject = getValueObject.value(localPower); + if (returnType in valueObject) { + return valueObject[returnType as keyof ValueObject]; + } + if (returnType == 'object') { + return valueObject; + } + console.error('returnType not found!', returnType, localPower); + }; + }); + /** * Get daily counter energy imported identified by root grid counter in component hierarchy or counterId * @param returnType type of return value, 'textValue', 'value', 'scaledValue', 'scaledUnit' or 'object' @@ -4424,6 +4450,7 @@ export const useMqttStore = defineStore('mqtt', () => { const ids = () => ({ consumerIds: [] as number[], counterIds: [] as number[], + counterIdsWithChildren: [] as number[], }); const result = { inHome: ids(), notInHome: ids() }; function walk( @@ -4442,10 +4469,19 @@ export const useMqttStore = defineStore('mqtt', () => { AUTO, ) as string | undefined; const mode = own && own !== AUTO ? own : parentMode; + let bucket; if (mode === NOT_HOME) { - result.notInHome.counterIds.push(node.id); - } else if (!isRoot) { - result.inHome.counterIds.push(node.id); + bucket = result.notInHome; + } else if (isRoot) { + bucket = undefined; + } else { + bucket = result.inHome; + } + if (bucket) { + bucket.counterIds.push(node.id); + if (node.children?.length) { + bucket.counterIdsWithChildren.push(node.id); + } } walk(node.children, mode, false); } else if (node.type === 'consumer') { @@ -4490,6 +4526,34 @@ export const useMqttStore = defineStore('mqtt', () => { () => homeConsumptionAssignment.value.notInHome, ); + // own share in W below which a counter with components below it is hidden + // (threshold for showing in the home consumption details) + const COUNTER_OWN_SHARE_THRESHOLD = 50; + + /** + * Get the counters to list in the home consumption details. A counter with + * components below it is left out if its own share is negligible, as it + * then only measures those components. + * @returns object with the keys inHome and notInHome, each holding counter ids + */ + const shownCounterIds = computed(() => { + const shown = (bucket: { + counterIds: number[]; + counterIdsWithChildren: number[]; + }) => { + // a counter that only measures the components below it is hidden + const hidden = (id: number) => + bucket.counterIdsWithChildren.includes(id) && + Math.abs(Number(counterLocalPower.value('value', id) ?? 0)) < + COUNTER_OWN_SHARE_THRESHOLD; + return bucket.counterIds.filter((id) => !hidden(id)); + }; + return { + inHome: shown(inHomeConsumption.value), + notInHome: shown(notInHomeConsumption.value), + }; + }); + /** * Get the summed power of all consumers and counters that are not counted * in the home consumption. @@ -4899,6 +4963,7 @@ export const useMqttStore = defineStore('mqtt', () => { componentName, gridComponentColor, counterPower, + counterLocalPower, counterDailyImported, counterDailyExported, // Home data @@ -4906,6 +4971,7 @@ export const useMqttStore = defineStore('mqtt', () => { homeDailyYield, inHomeConsumption, notInHomeConsumption, + shownCounterIds, notInHomeConsumptionPower, unmeasuredHomeConsumptionPower, // PV data