Repository navigation
Conversation
custom-components#649) The time trigger cycle computes time_next_adj so that (time_next_adj - now) is the real time to wait across a DST change, but after sleeping it re-checked that target against naive local time. When the clocks go back, local time repeats an hour, so the re-check slept that hour again: period() triggers stopped for an hour and cron() triggers crossing the change fired an hour late. Measure the remaining wait in UTC instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #649.
When the clocks go back,
@time_triggerloses an hour. Aperiod()trigger stops for an hour, and acron()trigger whose next run crosses the change fires an hour late. I hit both on 2026-10-25 (Europe/Berlin) on 2.1.0. Aperiod(now, 5s)trigger went quiet from 02:59:44 CEST to 03:00:14 CET. Acron(*/5 * * * *)trigger went from 02:55 CEST straight to 04:00 CET instead of 03:00 CET.Cause
TimeTriggerDecorator._cyclegetstime_next_adjfromtimer_trigger_next. That value already accounts for the DST change, sotime_next_adj - nowis the real time to wait. After sleeping, though, the cycle re-checks the target against naive local time (dt_now()). When the clocks go back, naive local time repeats an hour. The re-check then finds the target an hour away and sleeps that hour again.cron(*/5)at 02:55 CEST: the next run is 03:00 CET, 65 minutes away. After 65 minutes the local clock reads 03:00, buttime_next_adjis02:55 + 65 min = 04:00. The trigger waits another hour.period(..., 5s)at 02:59:59 CEST: the next slot is naive 03:00:04, 5 s away. After 5 s the local clock reads 02:00:04 CET, so the trigger waits until the naive clock reaches 03:00:04 again.Change
The cycle now records a UTC deadline when it starts sleeping and re-checks the remaining wait against UTC. The loop still guards against the sleep returning slightly early. UTC doesn't repeat, so the computed wait is used once. Once a trigger fires,
nowis the repeated local time, soperiod()keeps its interval through the repeated hour.cron()behaviour across the change is otherwise unchanged. As the existing DST tests expect,*/5still doesn't fire during the repeated hour itself. It now fires once the clocks reach 03:00 CET.Tests
tests/test_time_trigger_dst.pyruns the cycle with a fake clock whose local reading follows America/Los_Angeles, like the existing DST tests.asyncio.sleepadvances the fake clock instead of sleeping. The tests check:period(now, 5s)keeps 5 s gaps across the fall-back. Without the fix there is a 3605 s gap.cron(*/5 * * * *)fires at 08:55, 10:00 and 10:05 UTC. Without the fix the second run is at 11:00.period(now, 5s)keeps 5 s gaps across the spring-forward. This passes before and after the fix and guards against regressions.All 205 tests pass. Ruff, ruff format and pylint are clean on the changed files.
Not changed
legacy_decorators: true,TrigInfointrigger.py) and the legacytask.wait_untilre-check againsttime_nextrather thantime_next_adj. So they don't double-wait forcron(), but they still stallperiod()for the repeated hour. The same UTC deadline would fix them. I left them alone to keep this change small. Happy to add them here or in a follow-up.period()whose start time falls inside the repeated hour, such as a script loaded at 01:30 on the first pass, still waits for that start time to come round again after the change. That's a separate naive-time limitation oftimer_trigger_next.