diff --git a/src/data/automation.ts b/src/data/automation.ts index b207f7095b..d39d10cd48 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -99,7 +99,7 @@ export interface HassTrigger extends BaseTrigger { export interface NumericStateTrigger extends BaseTrigger { platform: "numeric_state"; - entity_id: string; + entity_id: string | string[]; attribute?: string; above?: number; below?: number; diff --git a/src/data/automation_i18n.ts b/src/data/automation_i18n.ts index 1793425d24..87023c64f5 100644 --- a/src/data/automation_i18n.ts +++ b/src/data/automation_i18n.ts @@ -141,8 +141,26 @@ const tryDescribeTrigger = ( // Numeric State Trigger if (trigger.platform === "numeric_state" && trigger.entity_id) { - const stateObj = hass.states[trigger.entity_id]; - const entity = stateObj ? computeStateName(stateObj) : trigger.entity_id; + const entities: string[] = []; + const states = hass.states; + + const stateObj = Array.isArray(trigger.entity_id) + ? hass.states[trigger.entity_id[0]] + : hass.states[trigger.entity_id]; + + if (Array.isArray(trigger.entity_id)) { + for (const entity of trigger.entity_id.values()) { + if (states[entity]) { + entities.push(computeStateName(states[entity]) || entity); + } + } + } else if (trigger.entity_id) { + entities.push( + states[trigger.entity_id] + ? computeStateName(states[trigger.entity_id]) + : trigger.entity_id + ); + } const attribute = trigger.attribute ? computeAttributeNameDisplay( @@ -157,35 +175,38 @@ const tryDescribeTrigger = ( ? describeDuration(hass.locale, trigger.for) : undefined; - if (trigger.above && trigger.below) { + if (trigger.above !== undefined && trigger.below !== undefined) { return hass.localize( `${triggerTranslationBaseKey}.numeric_state.description.above-below`, { attribute: attribute, - entity: entity, + entity: formatListWithOrs(hass.locale, entities), + numberOfEntities: entities.length, above: trigger.above, below: trigger.below, duration: duration, } ); } - if (trigger.above) { + if (trigger.above !== undefined) { return hass.localize( `${triggerTranslationBaseKey}.numeric_state.description.above`, { attribute: attribute, - entity: entity, + entity: formatListWithOrs(hass.locale, entities), + numberOfEntities: entities.length, above: trigger.above, duration: duration, } ); } - if (trigger.below) { + if (trigger.below !== undefined) { return hass.localize( `${triggerTranslationBaseKey}.numeric_state.description.below`, { attribute: attribute, - entity: entity, + entity: formatListWithOrs(hass.locale, entities), + numberOfEntities: entities.length, below: trigger.below, duration: duration, } diff --git a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts index 0db6ca2e38..9df81236ec 100644 --- a/src/panels/config/automation/trigger/ha-automation-trigger-row.ts +++ b/src/panels/config/automation/trigger/ha-automation-trigger-row.ts @@ -152,9 +152,7 @@ export default class HaAutomationTriggerRow extends LitElement { class="trigger-icon" .path=${TRIGGER_TYPES[this.trigger.platform]} > - ${capitalizeFirstLetter( - describeTrigger(this.trigger, this.hass, this._entityReg) - )} + ${describeTrigger(this.trigger, this.hass, this._entityReg)} diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts index 4f27495023..f2d0d72e5f 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state.ts @@ -9,6 +9,7 @@ import "../../../../../components/ha-form/ha-form"; import type { SchemaUnion } from "../../../../../components/ha-form/types"; import type { NumericStateTrigger } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; +import { ensureArray } from "../../../../../common/array/ensure-array"; @customElement("ha-automation-trigger-numeric_state") export class HaNumericStateTrigger extends LitElement { @@ -25,15 +26,21 @@ export class HaNumericStateTrigger extends LitElement { private _schema = memoizeOne( ( localize: LocalizeFunc, + entityId: string | string[], inputAboveIsEntity?: boolean, inputBelowIsEntity?: boolean ) => [ - { name: "entity_id", required: true, selector: { entity: {} } }, + { + name: "entity_id", + required: true, + selector: { entity: { multiple: true } }, + }, { name: "attribute", selector: { attribute: { + entity_id: entityId ? entityId[0] : undefined, hide_attributes: [ "access_token", "auto_update", @@ -125,9 +132,6 @@ export class HaNumericStateTrigger extends LitElement { ], }, }, - context: { - filter_entity: "entity_id", - }, }, { name: "mode_above", @@ -235,7 +239,7 @@ export class HaNumericStateTrigger extends LitElement { public static get defaultConfig() { return { - entity_id: "", + entity_id: [], }; } @@ -257,6 +261,7 @@ export class HaNumericStateTrigger extends LitElement { const schema = this._schema( this.hass.localize, + this.trigger.entity_id, inputAboveIsEntity, inputBelowIsEntity ); @@ -265,6 +270,7 @@ export class HaNumericStateTrigger extends LitElement { mode_above: inputAboveIsEntity ? "input" : "value", mode_below: inputBelowIsEntity ? "input" : "value", ...this.trigger, + entity_id: ensureArray(this.trigger.entity_id), for: trgFor, }; diff --git a/src/translations/en.json b/src/translations/en.json index d46f6e6770..5cc06e6afc 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2455,9 +2455,9 @@ "type_value": "Fixed number", "type_input": "Numeric value of another entity", "description": { - "above": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above}{duration, select, \n undefined {} \n other { for {duration}}\n }", - "below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }", - "above-below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} is above {above} and below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }" + "above": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} {numberOfEntities, plural,\n one {is}\n other {are}\n} above {above}{duration, select, \n undefined {} \n other { for {duration}}\n }", + "below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} {numberOfEntities, plural,\n one {is}\n other {are}\n} below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }", + "above-below": "When {attribute, select, \n undefined {} \n other {{attribute} from }\n }{entity} {numberOfEntities, plural,\n one {is}\n other {are}\n} above {above} and below {below}{duration, select, \n undefined {} \n other { for {duration}}\n }" } }, "persistent_notification": {