diff --git a/gallery/src/demos/demo-automation-editor-action.ts b/gallery/src/demos/demo-automation-editor-action.ts
new file mode 100644
index 0000000000..1aea950b92
--- /dev/null
+++ b/gallery/src/demos/demo-automation-editor-action.ts
@@ -0,0 +1,91 @@
+/* eslint-disable lit/no-template-arrow */
+import { LitElement, TemplateResult, html } from "lit";
+import { customElement, state } from "lit/decorators";
+import { provideHass } from "../../../src/fake_data/provide_hass";
+import type { HomeAssistant } from "../../../src/types";
+import "../components/demo-black-white-row";
+import { mockEntityRegistry } from "../../../demo/src/stubs/entity_registry";
+import { mockDeviceRegistry } from "../../../demo/src/stubs/device_registry";
+import { mockAreaRegistry } from "../../../demo/src/stubs/area_registry";
+import { mockHassioSupervisor } from "../../../demo/src/stubs/hassio_supervisor";
+import "../../../src/panels/config/automation/action/ha-automation-action";
+import { HaChooseAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-choose";
+import { HaDelayAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-delay";
+import { HaDeviceAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-device_id";
+import { HaEventAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-event";
+import { HaRepeatAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-repeat";
+import { HaSceneAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-scene";
+import { HaServiceAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-service";
+import { HaWaitForTriggerAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-wait_for_trigger";
+import { HaWaitAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-wait_template";
+import { Action } from "../../../src/data/script";
+import { HaConditionAction } from "../../../src/panels/config/automation/action/types/ha-automation-action-condition";
+
+const SCHEMAS: { name: string; actions: Action[] }[] = [
+ { name: "Event", actions: [HaEventAction.defaultConfig] },
+ { name: "Device", actions: [HaDeviceAction.defaultConfig] },
+ { name: "Service", actions: [HaServiceAction.defaultConfig] },
+ { name: "Condition", actions: [HaConditionAction.defaultConfig] },
+ { name: "Delay", actions: [HaDelayAction.defaultConfig] },
+ { name: "Scene", actions: [HaSceneAction.defaultConfig] },
+ { name: "Wait", actions: [HaWaitAction.defaultConfig] },
+ { name: "WaitForTrigger", actions: [HaWaitForTriggerAction.defaultConfig] },
+ { name: "Repeat", actions: [HaRepeatAction.defaultConfig] },
+ { name: "Choose", actions: [HaChooseAction.defaultConfig] },
+ { name: "Variables", actions: [{ variables: { hello: "1" } }] },
+];
+
+@customElement("demo-automation-editor-action")
+class DemoHaAutomationEditorAction extends LitElement {
+ @state() private hass!: HomeAssistant;
+
+ private data: any = SCHEMAS.map((info) => info.actions);
+
+ constructor() {
+ super();
+ const hass = provideHass(this);
+ hass.updateTranslations(null, "en");
+ hass.updateTranslations("config", "en");
+ mockEntityRegistry(hass);
+ mockDeviceRegistry(hass);
+ mockAreaRegistry(hass);
+ mockHassioSupervisor(hass);
+ }
+
+ protected render(): TemplateResult {
+ const valueChanged = (ev) => {
+ const sampleIdx = ev.target.sampleIdx;
+ this.data[sampleIdx] = ev.detail.value;
+ this.requestUpdate();
+ };
+ return html`
+ ${SCHEMAS.map(
+ (info, sampleIdx) => html`
+
+ ${["light", "dark"].map(
+ (slot) =>
+ html`
+
+ `
+ )}
+
+ `
+ )}
+ `;
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ "demo-ha-automation-editor-action": DemoHaAutomationEditorAction;
+ }
+}
diff --git a/gallery/src/demos/demo-automation-editor-condition.ts b/gallery/src/demos/demo-automation-editor-condition.ts
new file mode 100644
index 0000000000..4b1ebd8a13
--- /dev/null
+++ b/gallery/src/demos/demo-automation-editor-condition.ts
@@ -0,0 +1,127 @@
+/* eslint-disable lit/no-template-arrow */
+import { LitElement, TemplateResult, html } from "lit";
+import { customElement, state } from "lit/decorators";
+import { provideHass } from "../../../src/fake_data/provide_hass";
+import type { HomeAssistant } from "../../../src/types";
+import "../components/demo-black-white-row";
+import { mockEntityRegistry } from "../../../demo/src/stubs/entity_registry";
+import { mockDeviceRegistry } from "../../../demo/src/stubs/device_registry";
+import { mockAreaRegistry } from "../../../demo/src/stubs/area_registry";
+import { mockHassioSupervisor } from "../../../demo/src/stubs/hassio_supervisor";
+import type { Condition } from "../../../src/data/automation";
+import "../../../src/panels/config/automation/condition/ha-automation-condition";
+import { HaDeviceCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-device";
+import { HaLogicalCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-logical";
+import HaNumericStateCondition from "../../../src/panels/config/automation/condition/types/ha-automation-condition-numeric_state";
+import { HaStateCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-state";
+import { HaSunCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-sun";
+import { HaTemplateCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-template";
+import { HaTimeCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-time";
+import { HaTriggerCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-trigger";
+import { HaZoneCondition } from "../../../src/panels/config/automation/condition/types/ha-automation-condition-zone";
+
+const SCHEMAS: { name: string; conditions: Condition[] }[] = [
+ {
+ name: "State",
+ conditions: [{ condition: "state", ...HaStateCondition.defaultConfig }],
+ },
+ {
+ name: "Numeric State",
+ conditions: [
+ { condition: "numeric_state", ...HaNumericStateCondition.defaultConfig },
+ ],
+ },
+ {
+ name: "Sun",
+ conditions: [{ condition: "sun", ...HaSunCondition.defaultConfig }],
+ },
+ {
+ name: "Zone",
+ conditions: [{ condition: "zone", ...HaZoneCondition.defaultConfig }],
+ },
+ {
+ name: "Time",
+ conditions: [{ condition: "time", ...HaTimeCondition.defaultConfig }],
+ },
+ {
+ name: "Template",
+ conditions: [
+ { condition: "template", ...HaTemplateCondition.defaultConfig },
+ ],
+ },
+ {
+ name: "Device",
+ conditions: [{ condition: "device", ...HaDeviceCondition.defaultConfig }],
+ },
+ {
+ name: "And",
+ conditions: [{ condition: "and", ...HaLogicalCondition.defaultConfig }],
+ },
+ {
+ name: "Or",
+ conditions: [{ condition: "or", ...HaLogicalCondition.defaultConfig }],
+ },
+ {
+ name: "Not",
+ conditions: [{ condition: "not", ...HaLogicalCondition.defaultConfig }],
+ },
+ {
+ name: "Trigger",
+ conditions: [{ condition: "trigger", ...HaTriggerCondition.defaultConfig }],
+ },
+];
+
+@customElement("demo-automation-editor-condition")
+class DemoHaAutomationEditorCondition extends LitElement {
+ @state() private hass!: HomeAssistant;
+
+ private data: any = SCHEMAS.map((info) => info.conditions);
+
+ constructor() {
+ super();
+ const hass = provideHass(this);
+ hass.updateTranslations(null, "en");
+ hass.updateTranslations("config", "en");
+ mockEntityRegistry(hass);
+ mockDeviceRegistry(hass);
+ mockAreaRegistry(hass);
+ mockHassioSupervisor(hass);
+ }
+
+ protected render(): TemplateResult {
+ const valueChanged = (ev) => {
+ const sampleIdx = ev.target.sampleIdx;
+ this.data[sampleIdx] = ev.detail.value;
+ this.requestUpdate();
+ };
+ return html`
+ ${SCHEMAS.map(
+ (info, sampleIdx) => html`
+
+ ${["light", "dark"].map(
+ (slot) =>
+ html`
+
+ `
+ )}
+
+ `
+ )}
+ `;
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ "demo-ha-automation-editor-condition": DemoHaAutomationEditorCondition;
+ }
+}
diff --git a/gallery/src/demos/demo-automation-editor-trigger.ts b/gallery/src/demos/demo-automation-editor-trigger.ts
new file mode 100644
index 0000000000..0bc04b7435
--- /dev/null
+++ b/gallery/src/demos/demo-automation-editor-trigger.ts
@@ -0,0 +1,159 @@
+/* eslint-disable lit/no-template-arrow */
+import { LitElement, TemplateResult, html } from "lit";
+import { customElement, state } from "lit/decorators";
+import { provideHass } from "../../../src/fake_data/provide_hass";
+import type { HomeAssistant } from "../../../src/types";
+import "../components/demo-black-white-row";
+import { mockEntityRegistry } from "../../../demo/src/stubs/entity_registry";
+import { mockDeviceRegistry } from "../../../demo/src/stubs/device_registry";
+import { mockAreaRegistry } from "../../../demo/src/stubs/area_registry";
+import { mockHassioSupervisor } from "../../../demo/src/stubs/hassio_supervisor";
+import type { Trigger } from "../../../src/data/automation";
+import { HaGeolocationTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location";
+import { HaEventTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-event";
+import { HaHassTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant";
+import { HaNumericStateTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-numeric_state";
+import { HaSunTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-sun";
+import { HaTagTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-tag";
+import { HaTemplateTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-template";
+import { HaTimeTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time";
+import { HaTimePatternTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-time_pattern";
+import { HaWebhookTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-webhook";
+import { HaZoneTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-zone";
+import { HaDeviceTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-device";
+import { HaStateTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-state";
+import { HaMQTTTrigger } from "../../../src/panels/config/automation/trigger/types/ha-automation-trigger-mqtt";
+import "../../../src/panels/config/automation/trigger/ha-automation-trigger";
+
+const SCHEMAS: { name: string; triggers: Trigger[] }[] = [
+ {
+ name: "State",
+ triggers: [{ platform: "state", ...HaStateTrigger.defaultConfig }],
+ },
+
+ {
+ name: "MQTT",
+ triggers: [{ platform: "mqtt", ...HaMQTTTrigger.defaultConfig }],
+ },
+
+ {
+ name: "GeoLocation",
+ triggers: [
+ { platform: "geo_location", ...HaGeolocationTrigger.defaultConfig },
+ ],
+ },
+
+ {
+ name: "Home Assistant",
+ triggers: [{ platform: "homeassistant", ...HaHassTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Numeric State",
+ triggers: [
+ { platform: "numeric_state", ...HaNumericStateTrigger.defaultConfig },
+ ],
+ },
+
+ {
+ name: "Sun",
+ triggers: [{ platform: "sun", ...HaSunTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Time Pattern",
+ triggers: [
+ { platform: "time_pattern", ...HaTimePatternTrigger.defaultConfig },
+ ],
+ },
+
+ {
+ name: "Webhook",
+ triggers: [{ platform: "webhook", ...HaWebhookTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Zone",
+ triggers: [{ platform: "zone", ...HaZoneTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Tag",
+ triggers: [{ platform: "tag", ...HaTagTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Time",
+ triggers: [{ platform: "time", ...HaTimeTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Template",
+ triggers: [{ platform: "template", ...HaTemplateTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Event",
+ triggers: [{ platform: "event", ...HaEventTrigger.defaultConfig }],
+ },
+
+ {
+ name: "Device Trigger",
+ triggers: [{ platform: "device", ...HaDeviceTrigger.defaultConfig }],
+ },
+];
+
+@customElement("demo-automation-editor-trigger")
+class DemoHaAutomationEditorTrigger extends LitElement {
+ @state() private hass!: HomeAssistant;
+
+ private data: any = SCHEMAS.map((info) => info.triggers);
+
+ constructor() {
+ super();
+ const hass = provideHass(this);
+ hass.updateTranslations(null, "en");
+ hass.updateTranslations("config", "en");
+ mockEntityRegistry(hass);
+ mockDeviceRegistry(hass);
+ mockAreaRegistry(hass);
+ mockHassioSupervisor(hass);
+ }
+
+ protected render(): TemplateResult {
+ const valueChanged = (ev) => {
+ const sampleIdx = ev.target.sampleIdx;
+ this.data[sampleIdx] = ev.detail.value;
+ this.requestUpdate();
+ };
+ return html`
+ ${SCHEMAS.map(
+ (info, sampleIdx) => html`
+
+ ${["light", "dark"].map(
+ (slot) =>
+ html`
+
+ `
+ )}
+
+ `
+ )}
+ `;
+ }
+}
+
+declare global {
+ interface HTMLElementTagNameMap {
+ "demo-ha-automation-editor-trigger": DemoHaAutomationEditorTrigger;
+ }
+}
diff --git a/src/data/automation.ts b/src/data/automation.ts
index b6ea4c90c6..eedb752483 100644
--- a/src/data/automation.ts
+++ b/src/data/automation.ts
@@ -194,10 +194,10 @@ export interface NumericStateCondition extends BaseCondition {
export interface SunCondition extends BaseCondition {
condition: "sun";
- after_offset: number;
- before_offset: number;
- after: "sunrise" | "sunset";
- before: "sunrise" | "sunset";
+ after_offset?: number;
+ before_offset?: number;
+ after?: "sunrise" | "sunset";
+ before?: "sunrise" | "sunset";
}
export interface ZoneCondition extends BaseCondition {
diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-logical.ts b/src/panels/config/automation/condition/types/ha-automation-condition-logical.ts
index 47fbba8de6..35e9685463 100644
--- a/src/panels/config/automation/condition/types/ha-automation-condition-logical.ts
+++ b/src/panels/config/automation/condition/types/ha-automation-condition-logical.ts
@@ -1,10 +1,11 @@
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { fireEvent } from "../../../../../common/dom/fire_event";
-import { LogicalCondition } from "../../../../../data/automation";
+import { Condition, LogicalCondition } from "../../../../../data/automation";
import { HomeAssistant } from "../../../../../types";
import "../ha-automation-condition";
import { ConditionElement } from "../ha-automation-condition-row";
+import { HaStateCondition } from "./ha-automation-condition-state";
@customElement("ha-automation-condition-logical")
export class HaLogicalCondition extends LitElement implements ConditionElement {
@@ -13,7 +14,14 @@ export class HaLogicalCondition extends LitElement implements ConditionElement {
@property() public condition!: LogicalCondition;
public static get defaultConfig() {
- return { conditions: [{ condition: "state" }] };
+ return {
+ conditions: [
+ {
+ condition: "state",
+ ...HaStateCondition.defaultConfig,
+ },
+ ] as Condition[],
+ };
}
protected render() {
diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts
index 33dd859b45..ffb16e28ec 100644
--- a/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts
+++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-geo_location.ts
@@ -10,7 +10,7 @@ import { handleChangeEvent } from "../ha-automation-trigger-row";
const includeDomains = ["zone"];
@customElement("ha-automation-trigger-geo_location")
-export default class HaGeolocationTrigger extends LitElement {
+export class HaGeolocationTrigger extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public trigger!: GeoLocationTrigger;
@@ -19,7 +19,7 @@ export default class HaGeolocationTrigger extends LitElement {
return {
source: "",
zone: "",
- event: "enter",
+ event: "enter" as GeoLocationTrigger["event"],
};
}
diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts
index 5e64f7fd47..c660b8f132 100644
--- a/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts
+++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-homeassistant.ts
@@ -8,14 +8,14 @@ import "../../../../../components/ha-formfield";
import "../../../../../components/ha-radio";
@customElement("ha-automation-trigger-homeassistant")
-export default class HaHassTrigger extends LitElement {
+export class HaHassTrigger extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property({ attribute: false }) public trigger!: HassTrigger;
public static get defaultConfig() {
return {
- event: "start",
+ event: "start" as HassTrigger["event"],
};
}
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 7a1327e2ef..218bb8273b 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
@@ -12,7 +12,7 @@ import { handleChangeEvent } from "../ha-automation-trigger-row";
import "../../../../../components/ha-duration-input";
@customElement("ha-automation-trigger-numeric_state")
-export default class HaNumericStateTrigger extends LitElement {
+export class HaNumericStateTrigger extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@property() public trigger!: NumericStateTrigger;
diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts
index 0d6bf97980..b996cbdcbf 100644
--- a/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts
+++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-sun.ts
@@ -20,7 +20,8 @@ export class HaSunTrigger extends LitElement implements TriggerElement {
public static get defaultConfig() {
return {
- event: "sunrise",
+ event: "sunrise" as SunTrigger["event"],
+ offset: 0,
};
}
diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts
index 98301e4f83..333f3dc529 100644
--- a/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts
+++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-zone.ts
@@ -27,7 +27,7 @@ export class HaZoneTrigger extends LitElement {
return {
entity_id: "",
zone: "",
- event: "enter",
+ event: "enter" as ZoneTrigger["event"],
};
}