Improve Tibber price coordinator#166175
Conversation
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
|
Added Tibber as a custum component. Uploaded the new coordinator.py, restarted HA but still getting errors (new to old). |
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
|
This PR isn't finished yet. Testing at this stage isn't really useful. Please let the PR author ask for testers before testing. |
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Tibber integration’s price/data refresh behavior to avoid losing existing sensor values when the upstream API intermittently fails (e.g., HTTP 504), addressing #166107.
Changes:
- Update the price coordinator to refresh price info only when local-day prices appear missing, and compute the next refresh interval as a
timedelta. - Trigger
async_config_entry_first_refresh()for the price and data coordinators during sensor platform setup. - In the
get_pricesservice, proactively refresh a home’s price info when cached prices don’t appear valid.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/tibber/services.py |
Adds validity checks and conditional refresh for get_prices service responses. |
homeassistant/components/tibber/sensor.py |
Ensures coordinators perform their first refresh during setup before entities rely on them. |
homeassistant/components/tibber/coordinator.py |
Refactors the price coordinator’s refresh criteria and update interval calculation. |
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
homeassistant/components/tibber/coordinator.py:338
- Add a regression test that simulates a temporary Tibber API failure after prices have already been fetched, and assert the price coordinator keeps the last successful data (and the price sensor stays available) when no refresh is needed.
try:
if homes_to_update:
await asyncio.gather(
*(home.update_info_and_price_info() for home in homes_to_update)
)
| if homes_to_update: | ||
| await asyncio.gather( | ||
| *(home.update_info_and_price_info() for home in homes_to_update) |
There was a problem hiding this comment.
Prevent the electricity price sensor from becoming unavailable on transient failures by ensuring errors from update_info_and_price_info() don’t cause the coordinator update to fail when existing price data is still usable (e.g., keep returning cached data and only fail if no valid prices are present).
|
With the changes on this PR so far I do get the following error: I guess |
|
I think this is something wrong with your local setup; |
yes, sorry. It's fixed now. |
MartinHjelmare
left a comment
There was a problem hiding this comment.
Let's merge this now. It may not solve the problem completely but I think it's an improvement.
|
I don't think you've tested the final version of this PR. There should at most be a single gap in the plot per afternoon with this version, unless there's something we've missed. As noted above we haven't solved the issue completely with this PR, but it should be an improvement. If you want to provide feedback, please test the merged version of the PR. Anything else is unfortunately not useful. |
|
I checked out the dev branch which should include the merge, but I'll double check and head back. |
|
Edit: after updating to 2026.4.2 and removing the override the price keeps being available even if the request fails. The integration is still getting stuck on the full hour more often than with the version in 2026.4.1 but that's not in scope of this MR. (It's discussed here: #168007) Thank you for your work! I made sure to have the merged version and double checked, that the custom override is actually loaded. Occasionally there is no price data for the first 15 minutes of the hour. It happens when the Tibber API is returning odd data. Price data is also unavailable after a HA restart until the next 15 minute slot. Both things were not happening in the commit I've used before, even when the API got crazy. Edit: If it gets unavailable on the full hour the complete Integration is hanging and requires my watchdog automation to reload it. I've still had this reloads before but not nearly that often and not coupled to the full hour.
|
Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Breaking change
Proposed change
Raising UpdateFailed makes the data we already have unavailable for the sensor
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: