-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
History Stats doesn't work #71593
Comments
history_stats documentation |
Does it work if you change |
I have the same issue.
|
Current Version: 2022.5.3
Additional Info: I can see the sensor data in the history, so recorder is working. |
The post by chpacabra71 was solved as an issue with the |
I've spent a few hours with no luck replicating this. All of mine are working no matter how hard I try to break them. I'm not discounting that there is an issue here, I've just been unable to replicate it. |
In case it was my dev install, I also just tried it on my production instance. @MikaelHoogen Can you post a dump of the |
Hi, with this change it seem to work. Kinda strange |
Which time zone is your instance running in? |
Around 13:30 I did the change, end: "{{ now().replace(microsecond=0) }}" to a duration: 24:00:00 |
I think we have a race condition here
|
Hm I don't understand, can you elaborate? |
Can you try this change? diff --git a/homeassistant/components/history_stats/data.py b/homeassistant/components/history_stats/data.py
index 3f22f4cc32..6a10345df1 100644
--- a/homeassistant/components/history_stats/data.py
+++ b/homeassistant/components/history_stats/data.py
@@ -67,9 +67,10 @@ class HistoryStats:
current_period_end_timestamp = floored_timestamp(current_period_end)
previous_period_start_timestamp = floored_timestamp(previous_period_start)
previous_period_end_timestamp = floored_timestamp(previous_period_end)
- now_timestamp = floored_timestamp(datetime.datetime.now())
+ utc_now = dt_util.utcnow()
+ now_timestamp = floored_timestamp(utc_now)
- if now_timestamp < current_period_start_timestamp:
+ if current_period_start > utc_now:
# History cannot tell the future
self._history_current_period = []
self._previous_run_before_start = True |
When you had the issue was the state 0 or unknown? |
- history_stats ignores microseconds but it was not doing it for state_changed events Fixes home-assistant#71593
I'm using image homeassistant/home-assistant:stable, is there a way for me to make this change manually? I am able to login into the container by "docker exec" command but don't know where this file located. |
@atjshop Can you post a copy of your yaml config ? |
I found it, after login into docker container, the file location is at usr/src/homeassistant/homeassistant/components/history_stats/ thanks. |
Hi! This fix is still not in dev: This fixed the problem ...
|
While its been like this for a long time https://github.com/home-assistant/core/blob/5df747276f3a1b787c24b3225c457ca55bb5c84d/homeassistant/components/history_stats/sensor.py#L203 it fixes the issue reported here: home-assistant#71593 (comment)
The problem
Since the update to 2022.5 the history stats integration doesn't work properly. The first day it counted up time constantly regardless of the state of the entity_id. After midnight it stopped counting completely. When I restart HA it is updated the first minutes. Then it stops again.
What version of Home Assistant Core has the issue?
2022.5.3
What was the last working version of Home Assistant Core?
2022.4.x
What type of installation are you running?
Home Assistant OS
Integration causing the issue
History Stats
Link to integration documentation on our website
https://www.home-assistant.io/integrations/history_stats/
Diagnostics information
No response
Example YAML snippet
Anything in the logs that might be useful for us?
Additional information
No response
The text was updated successfully, but these errors were encountered: