diff --git a/src/data/timer.ts b/src/data/timer.ts index 4b0ab1ce2768..3290be645d7d 100644 --- a/src/data/timer.ts +++ b/src/data/timer.ts @@ -72,8 +72,8 @@ export const timerTimeRemaining = ( if (stateObj.state === "active") { const now = new Date().getTime(); - const madeActive = new Date(stateObj.last_changed).getTime(); - timeRemaining = Math.max(timeRemaining - (now - madeActive) / 1000, 0); + const finishes = new Date(stateObj.attributes.finishes_at).getTime(); + timeRemaining = Math.max((finishes - now) / 1000, 0); } return timeRemaining; diff --git a/test/common/entity/timer_time_remaining_test.ts b/test/common/entity/timer_time_remaining_test.ts index 13ba7eb20673..810f0e0f276a 100644 --- a/test/common/entity/timer_time_remaining_test.ts +++ b/test/common/entity/timer_time_remaining_test.ts @@ -42,8 +42,8 @@ describe("timerTimeRemaining", () => { state: "active", attributes: { remaining: "0:01:05", + finishes_at: "2018-01-17T16:16:17+00:00", }, - last_changed: "2018-01-17T16:15:12Z", } as any), 47 );