diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts index 9a12ab7b55..12cb696d80 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-tag.ts @@ -15,7 +15,7 @@ export class HaTagTrigger extends LitElement implements TriggerElement { @property() public trigger!: TagTrigger; - @state() private _tags: Tag[] = []; + @state() private _tags?: Tag[]; public static get defaultConfig() { return { tag_id: "" }; @@ -27,14 +27,16 @@ export class HaTagTrigger extends LitElement implements TriggerElement { } protected render() { - const { tag_id } = this.trigger; + if (!this._tags) { + return html``; + } return html` ${this._tags.map( @@ -49,14 +51,17 @@ export class HaTagTrigger extends LitElement implements TriggerElement { } private async _fetchTags() { - this._tags = await fetchTags(this.hass); - this._tags.sort((a, b) => + this._tags = (await fetchTags(this.hass)).sort((a, b) => caseInsensitiveStringCompare(a.name || a.id, b.name || b.id) ); } private _tagChanged(ev) { - if (this.trigger.tag_id === ev.detail.value) { + if ( + !ev.detail.value || + !this._tags || + this.trigger.tag_id === ev.detail.value + ) { return; } fireEvent(this, "value-changed", {