From d5fb924cb403e674cf8d3bbddccf38a9faa288e6 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 20 Feb 2023 06:30:40 -0800 Subject: [PATCH] Support for timestamp sensors in time trigger automation UI (#15292) * Support for timestamp sensors in time trigger automation UI * rename var * simply filter function Co-authored-by: Paul Bottein * rename var * use new entity filter options --------- Co-authored-by: Paul Bottein --- .../types/ha-automation-condition-time.ts | 24 +++++++++++++++---- .../types/ha-automation-trigger-time.ts | 9 ++++++- src/translations/en.json | 2 +- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/panels/config/automation/condition/types/ha-automation-condition-time.ts b/src/panels/config/automation/condition/types/ha-automation-condition-time.ts index 108644ffe5..ba12359de5 100644 --- a/src/panels/config/automation/condition/types/ha-automation-condition-time.ts +++ b/src/panels/config/automation/condition/types/ha-automation-condition-time.ts @@ -63,7 +63,14 @@ export class HaTimeCondition extends LitElement implements ConditionElement { { name: "after", selector: inputModeAfter - ? { entity: { domain: "input_datetime" } } + ? { + entity: { + filter: [ + { domain: "input_datetime" }, + { domain: "sensor", device_class: "timestamp" }, + ], + }, + } : { time: {} }, }, { @@ -88,7 +95,14 @@ export class HaTimeCondition extends LitElement implements ConditionElement { { name: "before", selector: inputModeBefore - ? { entity: { domain: "input_datetime" } } + ? { + entity: { + filter: [ + { domain: "input_datetime" }, + { domain: "sensor", device_class: "timestamp" }, + ], + }, + } : { time: {} }, }, { @@ -111,10 +125,12 @@ export class HaTimeCondition extends LitElement implements ConditionElement { protected render() { const inputModeBefore = this._inputModeBefore ?? - this.condition.before?.startsWith("input_datetime."); + (this.condition.before?.startsWith("input_datetime.") || + this.condition.before?.startsWith("sensor.")); const inputModeAfter = this._inputModeAfter ?? - this.condition.after?.startsWith("input_datetime."); + (this.condition.after?.startsWith("input_datetime.") || + this.condition.after?.startsWith("sensor.")); const schema = this._schema( this.hass.localize, diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts index 1375312e3f..4802243785 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts @@ -26,7 +26,14 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { private _schema = memoizeOne( (localize: LocalizeFunc, inputMode?: boolean) => { const atSelector = inputMode - ? { entity: { domain: "input_datetime" } } + ? { + entity: { + filter: [ + { domain: "input_datetime" }, + { domain: "sensor", device_class: "timestamp" }, + ], + }, + } : { time: {} }; return [ diff --git a/src/translations/en.json b/src/translations/en.json index 7330da095f..83fd86b304 100755 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2131,7 +2131,7 @@ }, "time": { "type_value": "Fixed time", - "type_input": "Value of a date/time helper", + "type_input": "Value of a date/time helper or timestamp-class sensor", "label": "Time", "at": "At time", "mode": "Mode"