diff --git a/src/data/automation.ts b/src/data/automation.ts index 1b8de5855e..dda0711a2f 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -69,7 +69,7 @@ export interface BaseTrigger { export interface StateTrigger extends BaseTrigger { platform: "state"; - entity_id: string; + entity_id: string | string[]; attribute?: string; from?: string | number; to?: string | string[] | number; diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts index 44d3183e0d..60997afcde 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-state.ts @@ -1,6 +1,7 @@ import { html, LitElement, PropertyValues } from "lit"; import { customElement, property } from "lit/decorators"; import { + array, assert, assign, literal, @@ -10,6 +11,7 @@ import { union, } from "superstruct"; import memoizeOne from "memoize-one"; +import { ensureArray } from "../../../../../common/ensure-array"; import { fireEvent } from "../../../../../common/dom/fire_event"; import { hasTemplate } from "../../../../../common/string/has-template"; import { StateTrigger } from "../../../../../data/automation"; @@ -24,7 +26,7 @@ const stateTriggerStruct = assign( baseTriggerStruct, object({ platform: literal("state"), - entity_id: optional(string()), + entity_id: optional(union([string(), array(string())])), attribute: optional(string()), from: optional(string()), to: optional(string()), @@ -39,11 +41,15 @@ export class HaStateTrigger extends LitElement implements TriggerElement { @property() public trigger!: StateTrigger; public static get defaultConfig() { - return { entity_id: "" }; + return { entity_id: [] }; } private _schema = memoizeOne((entityId) => [ - { name: "entity_id", required: true, selector: { entity: {} } }, + { + name: "entity_id", + required: true, + selector: { entity: { multiple: true } }, + }, { name: "attribute", selector: { attribute: { entity_id: entityId } }, @@ -85,7 +91,11 @@ export class HaStateTrigger extends LitElement implements TriggerElement { protected render() { const trgFor = createDurationData(this.trigger.for); - const data = { ...this.trigger, ...{ for: trgFor } }; + const data = { + ...this.trigger, + entity_id: ensureArray(this.trigger.entity_id), + for: trgFor, + }; const schema = this._schema(this.trigger.entity_id); return html`