From acc96d8eeefc51502c1bca23cd1ad6cbd89da54a Mon Sep 17 00:00:00 2001 From: Niklas Wagner Date: Sat, 11 Oct 2025 12:22:21 +0200 Subject: [PATCH 1/2] Allow selecting multiple states in state condition --- .../types/ha-automation-condition-state.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts index 701bc2868920..dbfa73d225b7 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts @@ -10,6 +10,7 @@ import { optional, string, union, + array, } from "superstruct"; import { createDurationData } from "../../../../../common/datetime/create_duration_data"; import { fireEvent } from "../../../../../common/dom/fire_event"; @@ -25,7 +26,7 @@ const stateConditionStruct = object({ condition: literal("state"), entity_id: optional(string()), attribute: optional(string()), - state: optional(string()), + state: optional(union([string(), array(string())])), for: optional(union([number(), string(), forDictStruct])), enabled: optional(boolean()), }); @@ -69,7 +70,7 @@ const SCHEMA = [ name: "state", required: true, selector: { - state: {}, + state: { multiple: true }, }, context: { filter_entity: "entity_id", @@ -88,7 +89,7 @@ export class HaStateCondition extends LitElement implements ConditionElement { @property({ type: Boolean }) public disabled = false; public static get defaultConfig(): StateCondition { - return { condition: "state", entity_id: "", state: "" }; + return { condition: "state", entity_id: "", state: [] }; } public shouldUpdate(changedProperties: PropertyValues) { @@ -129,10 +130,9 @@ export class HaStateCondition extends LitElement implements ConditionElement { : {} ); - // We should not cleanup state in the above, as it is required. - // Set it to empty string if it is undefined. - if (!newCondition.state) { - newCondition.state = ""; + // Ensure `state` stays an array for multi-select. If absent, set to [] + if (newCondition.state === undefined || newCondition.state === "") { + newCondition.state = []; } fireEvent(this, "value-changed", { value: newCondition }); From f2460b3cba9e7d30eb6347805c7d29196fbd3a9f Mon Sep 17 00:00:00 2001 From: Niklas Wagner Date: Mon, 13 Oct 2025 17:47:08 +0200 Subject: [PATCH 2/2] Make use of the ensureArray function --- .../condition/types/ha-automation-condition-state.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts index dbfa73d225b7..abebbda172d8 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-state.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-state.ts @@ -13,6 +13,7 @@ import { array, } from "superstruct"; import { createDurationData } from "../../../../../common/datetime/create_duration_data"; +import { ensureArray } from "../../../../../common/array/ensure-array"; import { fireEvent } from "../../../../../common/dom/fire_event"; import "../../../../../components/ha-form/ha-form"; import type { SchemaUnion } from "../../../../../components/ha-form/types"; @@ -106,7 +107,11 @@ export class HaStateCondition extends LitElement implements ConditionElement { protected render() { const trgFor = createDurationData(this.condition.for); - const data = { ...this.condition, for: trgFor }; + const data = { + ...this.condition, + state: ensureArray(this.condition.state) || [], + for: trgFor, + }; return html`