Hello Pierre-Gilles
Hello everyone,
It’s great to have the option to set an offset directly on sunrise/sunset, but I’ve noticed a small bug, probably since the latest versions. For my part, morning opening scenes with a « after » delay of 5 minutes or without an offset no longer trigger.
I specify that:
evening scenes with a +15 minute offset work,
my location is correctly set,
the time zone is also correct,
See my logs which indicate that the opening calculation is done in the past.
Am I the only one having this problem?
Thanks for your feedback
DamienLogs sunrise
Hello (and welcome)
I’ve moved your message to a new conversation to handle the issue here.
I can’t retrieve your logs. I’ll still check if there’s a difference in the code between morning and evening
Can you put them on https://pastebin.com/ ? and share the link here?
There is indeed a bug. I’m testing a fix today (well, tomorrow for sunrise ) and I’ll keep you posted.
Hi cicoub13,
Thanks for your quick response… I’m actually taking the train on the way in the community .
Here’s the link to the logs: Gladys sunrise scene not scheduled - Pastebin.com
Have a great day
It’s good, it works
@pierre-gilles Could you take a look at the PR when you have time?
master ← cicoub13:fix-sunrise-trigger
ouvert 08:52PM - 10 Jun 26 UTC
**Problem**
Since #2474 (configurable offset before/after sunrise/sunset), mo… rning scenes triggered on sunrise (with no offset or a small "after" offset) stopped firing, while evening sunset scenes (e.g. +15 min) kept working — even though location and timezone were correctly configured.
**Root cause**: that PR changed two things in how sun jobs are scheduled.
1. `dailyUpdate()` is now replayed on every scene save. create/update/addScene/destroy now call await this.dailyUpdate(), and it also runs on every server restart via init. Previously, sun jobs were only (re)computed by the midnight cron.
2. `dailyUpdate()` cancels all sun jobs and only reschedules the ones still in the future. node-schedule returns null for a past date, so the job is dropped (time is in the past, not scheduling for today).
As a result, whenever dailyUpdate() runs after sunrise — which happens when a user saves/configures a scene during the day, or when the server restarts in the afternoon — the sunrise jobs (~6am, already passed) are dropped while sunset jobs (~9pm, still ahead) are kept. Hence: morning triggers silently disappear, evening triggers keep working.
**Solution**
In `scene.dailyUpdate.js`, when today's occurrence has already passed, schedule the next day's occurrence instead of dropping it. A pending sun job therefore always exists regardless of when `dailyUpdate()` is replayed; the midnight cron then realigns it to the exact time of the day.
```
let occurrence = baseTime.add(offset, 'minute');
// If today's occurrence already passed, schedule the next day's occurrence so the
// trigger isn't silently dropped until the next midnight reschedule.
if (occurrence.toDate().getTime() < Date.now()) {
occurrence = occurrence.add(1, 'day');
}
const time = occurrence.toDate();
```
**Tests**
- Added should schedule sunrise/sunset for the next day when today's occurrence is already in the past, verifying past occurrences are rolled over (2 jobs created, both scheduled in the future) instead of being lost.
- Clarified the existing "scheduler returns null" test.
- All scene dailyUpdate and sunriseSunset trigger tests pass; eslint clean.
## Summary by CodeRabbit
* **Bug Fixes**
* Daily sunrise/sunset scheduling now shifts past occurrences to the next day so events aren't missed.
* Scheduled event timestamps are logged with improved timezone-aware formatting.
* **Tests**
* Updated tests to cover scheduling behavior for past events and handling when scheduling yields no job.
Thanks for the PR @cicoub13 !
I’ve left a review here: fix(scene): Fix issue with next sunrise trigger by cicoub13 · Pull Request #2548 · GladysAssistant/Gladys · GitHub
I think the root issue is elsewhere, we have a timezone bug in the dailyUpdate I think
Okay, thanks, I’ll check (Monday)
You were right. I fixed the PR and the test is conclusive this morning
Thanks! That’s good for me, it’s merged and it will go out in the next version of Gladys
I’ve installed version 4.80 and confirm that scenes triggered at sunrise/sunset are working properly.
Happy to have been able to contribute modestly to the detection of the issue and thank you especially for resolving it quickly
Thanks for your feedback, that’s what makes Gladys progress