time_pattern trigger: add optional after / before time window
#4130
Unanswered
AlexF090
asked this question in
Automations & scripts
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the feature
The time_pattern trigger currently fires on every matching interval, all day long — there is no way to restrict it to a specific time window natively.
I'd like to add optional
afterandbeforeparameters directly to the trigger:trigger:
minutes: "/15"
after: "05:00:00"
before: "09:30:00"
This would fire every 15 minutes, but only between 05:00 and 09:30. Outside that window the trigger would be suppressed entirely — no action block entered, no condition evaluated, nothing logged. Midnight-spanning ranges (e.g. after: "22:00:00", before: "06:00:00") should be supported as well.
Both parameters would be fully optional. Omitting them preserves today's behaviour exactly — zero breaking changes.
Use cases
Morning shutter automation: roller blinds should open when outdoor brightness exceeds a threshold (numeric_state trigger), active only between 05:00–09:30. In summer (Central Europe), sunrise can be before 05:00, so the numeric_state trigger fires too early and is blocked by a time condition. A time_pattern at /15 is used as a catch-up: if the sensor is already above threshold when the window opens, the interval check picks it up. With the current design, that /15 trigger fires 96 times a day even though only 18 of those runs are within the relevant window.
General pattern: any "keep trying until it's done" automation — turning lights off, checking a device state, polling a sensor — that should only be active during a defined part of the day.
Current workarounds
The standard workaround is a time condition in the automation:
trigger:
minutes: "/15"
conditions:
after: "05:00:00"
before: "09:30:00"
This works but has two downsides:
Anything else?
Prior community discussion (Nov 2020, no resolution):
https://community.home-assistant.io/t/time-pattern-needs-to-support-ranges/248976
Related stale PR that tried to make time_pattern more expressive (closed 2020):
home-assistant/core#33310
Implementation hint: the relevant file is
homeassistant/components/homeassistant/triggers/time_pattern.py
The after/before validation helpers (cv.time) and midnight-overlap logic already exist in the time condition and could be reused. The check would go into async_attach_trigger before invoking the job callback — a minimal, self-contained change.
Beta Was this translation helpful? Give feedback.
All reactions