From c166335aca713354b2eb159bb052ecc6daa85ef8 Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Tue, 31 Mar 2026 11:49:37 +0100 Subject: [PATCH] Fix above/below numeric state entity formatting (#51298) --- src/data/automation_i18n.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 0790fb9db3..f9bab67ec5 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -78,6 +78,19 @@ const localizeTimeString = ( } }; +const formatNumericLimitValue = ( + hass: HomeAssistant, + value?: number | string +) => { + if (typeof value !== "string" || !isValidEntityId(value)) { + return value; + } + + return hass.states[value] + ? computeStateName(hass.states[value]) || value + : value; +}; + export const describeTrigger = ( trigger: Trigger, hass: HomeAssistant, @@ -233,8 +246,8 @@ const describeLegacyTrigger = ( attribute: attribute, entity: formatListWithOrs(hass.locale, entities), numberOfEntities: entities.length, - above: trigger.above, - below: trigger.below, + above: formatNumericLimitValue(hass, trigger.above), + below: formatNumericLimitValue(hass, trigger.below), duration: duration, } ); @@ -246,7 +259,7 @@ const describeLegacyTrigger = ( attribute: attribute, entity: formatListWithOrs(hass.locale, entities), numberOfEntities: entities.length, - above: trigger.above, + above: formatNumericLimitValue(hass, trigger.above), duration: duration, } ); @@ -258,7 +271,7 @@ const describeLegacyTrigger = ( attribute: attribute, entity: formatListWithOrs(hass.locale, entities), numberOfEntities: entities.length, - below: trigger.below, + below: formatNumericLimitValue(hass, trigger.below), duration: duration, } ); @@ -1116,8 +1129,8 @@ const describeLegacyCondition = ( attribute, entity, numberOfEntities: entity_ids.length, - above: condition.above, - below: condition.below, + above: formatNumericLimitValue(hass, condition.above), + below: formatNumericLimitValue(hass, condition.below), } ); } @@ -1128,7 +1141,7 @@ const describeLegacyCondition = ( attribute, entity, numberOfEntities: entity_ids.length, - above: condition.above, + above: formatNumericLimitValue(hass, condition.above), } ); } @@ -1139,7 +1152,7 @@ const describeLegacyCondition = ( attribute, entity, numberOfEntities: entity_ids.length, - below: condition.below, + below: formatNumericLimitValue(hass, condition.below), } ); }