From 984b50bac74b16790f61a276e849b2e6ed6cace4 Mon Sep 17 00:00:00 2001 From: Tom Carpenter Date: Mon, 23 Mar 2026 11:36:15 +0000 Subject: [PATCH] Fix water/gas total badge unit when sensor value is zero (#30279) Fix water/gas badge when rate is 0 If there is only one flow rate sensor, and it has a value <=0, the badge would be displayed without a unit because the sensor gets skipped. Instead of skipping <=0 values, continue to process sensor, but clamp the value to a minimum of 0. This ensures for single sensors we have a unit, and for multiple sensors the chosen unit is consistent even if the first sensor value drops to zero. --- src/data/energy.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/data/energy.ts b/src/data/energy.ts index ccdb0f81f9..79d0cd1d18 100644 --- a/src/data/energy.ts +++ b/src/data/energy.ts @@ -1526,11 +1526,15 @@ export const computeTotalFlowRate = ( return; } - const rawValue = parseFloat(stateObj.state); - if (isNaN(rawValue) || rawValue <= 0) { + let rawValue = parseFloat(stateObj.state); + if (isNaN(rawValue)) { return; } + if (rawValue < 0) { + rawValue = 0; + } + const entityUnit = stateObj.attributes.unit_of_measurement; if (!entityUnit) { return;