diff --git a/src/common/string/has-template.ts b/src/common/string/has-template.ts new file mode 100644 index 0000000000..b54af3307d --- /dev/null +++ b/src/common/string/has-template.ts @@ -0,0 +1,17 @@ +const isTemplateRegex = new RegExp("{%|{{|{#"); +export const isTemplate = (value: string): boolean => + isTemplateRegex.test(value); + +export const hasTemplate = (value: unknown): boolean => { + if (!value) { + return false; + } + if (typeof value === "string") { + return isTemplate(value); + } + if (typeof value === "object") { + const values = Array.isArray(value) ? value : Object.values(value!); + return values.some((val) => hasTemplate(val)); + } + return false; +}; diff --git a/src/panels/config/automation/action/types/ha-automation-action-service.ts b/src/panels/config/automation/action/types/ha-automation-action-service.ts index 984c2f0a52..4930c86b9b 100644 --- a/src/panels/config/automation/action/types/ha-automation-action-service.ts +++ b/src/panels/config/automation/action/types/ha-automation-action-service.ts @@ -16,6 +16,7 @@ import type { HomeAssistant } from "../../../../../types"; import { EntityIdOrAll } from "../../../../../common/structs/is-entity-id"; import { ActionElement } from "../ha-automation-action-row"; import "../../../../../components/ha-service-control"; +import { hasTemplate } from "../../../../../common/string/has-template"; const actionStruct = object({ service: optional(string()), @@ -46,6 +47,15 @@ export class HaServiceAction extends LitElement implements ActionElement { assert(this.action, actionStruct); } catch (error) { fireEvent(this, "ui-mode-not-available", error); + return; + } + if (this.action && hasTemplate(this.action)) { + fireEvent( + this, + "ui-mode-not-available", + Error(this.hass.localize("ui.errors.config.no_template_editor_support")) + ); + return; } if (this.action.entity_id) { this._action = {