Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export interface StateCondition {
entity_id: string;
attribute?: string;
state: string | number;
for?: string | number | ForDict;
}

export interface NumericStateCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`
<ha-entity-picker
Expand Down Expand Up @@ -49,6 +66,14 @@ export class HaStateCondition extends LitElement implements ConditionElement {
.value=${state}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
.label=${this.hass.localize(
"ui.panel.config.automation.editor.triggers.type.state.for"
)}
.name=${"for"}
.value=${forTime}
@value-changed=${this._valueChanged}
></paper-input>
`;
}

Expand Down