From c7ff8d4996d4a7e915a9d43c3a0f7a1c1ed77678 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Thu, 31 Jan 2019 01:33:52 +0000 Subject: [PATCH] fix #20571 (#20589) --- homeassistant/components/sensor/history_stats.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/homeassistant/components/sensor/history_stats.py b/homeassistant/components/sensor/history_stats.py index a8d9276edc8..f5b76c89aba 100644 --- a/homeassistant/components/sensor/history_stats.py +++ b/homeassistant/components/sensor/history_stats.py @@ -282,6 +282,13 @@ class HistoryStatsSensor(Entity): if end is None: end = start + self._duration + if start > dt_util.now(): + # History hasn't been written yet for this period + return + if dt_util.now() < end: + # No point in making stats of the future + end = dt_util.now() + self._period = start, end