-
Notifications
You must be signed in to change notification settings - Fork 58
period time triggers with now and endtime #714
-
I want to use a period time trigger that starts at definition time and ends at a specified time but the function still triggers even after the time has passed.
@time_trigger("period(now, 1min, 10:15:00)")
When I specify a specific time as the start time it works.
@time_trigger("period(10:00:00, 1min, 10:15:00)")
It also works when the end time includes the date
@time_trigger("period(now, 1min, 2025年04月08日 10:22:00)")
This might be a bug but I wanted to ask here first just in case I am doing something wrong.
This is the function I used to test this.
@time_trigger("period(now, 1min, 10:15:00)")
def period_trigger_test(trigger_time: datetime):
task.unique("period_trigger_test")
log.warning("trigger_time %s", trigger_time)
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
You're not doing anything wrong. I don't think it's a bug, but an unexpected consequence of how pyscript
interprets times without dates. When a date isn't specified, several checks are done by trying yesterday, today and tomorrow. This is to allow the convenience of a start time > end time (without dates) to mean the evening period spanning midnight - the ending time is considered to be tomorrow. If now > end time, the end time is considered to be tomorrow. A couple of solutions are (untested):
- don't use
now
, instead use '0:0' or midnight. Then the trigger will happen from midnight to 10:15am every day, or from whenever you start. However, you might only want to trigger on the start day, not on subsequent days. - To trigger just on a startup day, keep the
now
start, andtoday 10:15:00
for the end time. That should disable the attempts to try tomorrow or yesterday. Then the trigger will only happen on the day of startup before 10:15am.
Hmm - I just tested the 2nd suggestion, and it doesn't work correctly - it triggers once at now
, even if it's after end time. It doesn't trigger again though. That does look like a bug.
Beta Was this translation helpful? Give feedback.