diff --git a/src/data/automation.ts b/src/data/automation.ts index 272416abb0..058ea73223 100644 --- a/src/data/automation.ts +++ b/src/data/automation.ts @@ -157,6 +157,7 @@ export interface StateCondition { entity_id: string; attribute?: string; state: string | number; + for?: string | number | ForDict; } export interface NumericStateCondition { 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 2b42b53630..d0f18b1ab7 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 @@ -2,7 +2,7 @@ import "@polymer/paper-input/paper-input"; import { customElement, html, LitElement, property } from "lit-element"; import "../../../../../components/entity/ha-entity-attribute-picker"; import "../../../../../components/entity/ha-entity-picker"; -import { StateCondition } from "../../../../../data/automation"; +import { ForDict, StateCondition } from "../../../../../data/automation"; import { HomeAssistant } from "../../../../../types"; import { ConditionElement, @@ -21,6 +21,23 @@ export class HaStateCondition extends LitElement implements ConditionElement { protected render() { const { entity_id, attribute, state } = this.condition; + let forTime = this.condition.for; + + if ( + forTime && + ((forTime as ForDict).hours || + (forTime as ForDict).minutes || + (forTime as ForDict).seconds) + ) { + // If the trigger was defined using the yaml dict syntax, convert it to + // the equivalent string format + let { hours = 0, minutes = 0, seconds = 0 } = forTime as ForDict; + hours = hours.toString().padStart(2, "0"); + minutes = minutes.toString().padStart(2, "0"); + seconds = seconds.toString().padStart(2, "0"); + + forTime = `${hours}:${minutes}:${seconds}`; + } return html` + `; }