-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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 API not returning data from a specific time range when recorder runs are lost. Extending end time works #117793
Comments
Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) history documentation |
I copied the history component over as a custom component and added logger to it.
which produces following log line: |
I'm experiencing this as well. The history appears in the UI, but it doesn't appear in the API. There's also something quite strange about the behaviour:
In particular, the first timestamp reported by the second (working) request, should be included in the first request (which returns nothing), but it isn't.
|
I'm having the exact same issue, is there any known workaround? |
I copied https://github.com/home-assistant/core/tree/dev/homeassistant/components/history to config/custom_components and commented out
line 109-117 @bdraco can you suggest a better workaround? |
Sounds like you have identified where the problem is. Any chance you could open a PR to fix it? My backlog is quite large right now so it could be a while before I can investigate. |
Created a PR #123449 |
Thanks. Added a review comment to get the process started |
I have a similar issue with EMHASS in the days after Home Assistant restarts/upgrades. This works:
This doesn't:
In the database this is the only recorder_run:
For example when trying to get the values from the first days of November:
Looks like the purge cleans up all previous recorder_runs if they started before the purge period?
My runs are typically about a month long, the start will be well outside of the purge period when it the run is ended due to a restart. The next purge will then delete it. |
This should be fixed by #131702 which will be included in Home Assistant Core 2024.12.0b2 @tanelvakker @RudolfRendier can you verify you now get all data in the history queries, maybe once 2024.12.0b2 is available if you don't want to test on dev |
This only happened about once per month of not restarting. I have also increased the recorder purge_keep_days to 30, which should also make it even harder to reproduce |
OK, I'm closing this issue then. Please open a new issue if it happens again. |
The problem
I use emhass to automate energy usage. Emhass queries past power usage using /api/history/period/ endpoint. About once a month it fails to retrieve data from a specific time range. After a day or so the issue mitigates automatically. I have narrowed it down to something to do with end_time. By default it's start + 1 day.
I am getting a 200 OK response, but body is "[]" when it does not work.
https://HA:8123/api/history/period/2024-05-18T15:56:00+00:00?filter_entity_id=sensor.load_power does not work
https://HA:8123/api/history/period/2024-05-18T15:56:00+00:00?filter_entity_id=sensor.load_power&end_time=2024-05-19T18:56:00 also does not work
Extending it by 1 minute to https://HA:8123/api/history/period/2024-05-18T15:56:00+00:00?filter_entity_id=sensor.load_power&end_time=2024-05-19T18:57:00 returns data just fine.
I suspect the code path it takes is https://github.com/home-assistant/core/blob/7998f874c09afc0d0537279d92aefb92da6fc573/homeassistant/components/history/__init__.py#L110C31-L110C53
Is there a way to check recorder_runs_manager.first.start manually?
How can I troubleshoot this further?
What version of Home Assistant Core has the issue?
2024.5.4
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant OS
Integration causing the issue
history
Link to integration documentation on our website
https://www.home-assistant.io/integrations/history/
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
The text was updated successfully, but these errors were encountered: