Hola Pierre-Gilles
Hola a todos,
Muy bien esta posibilidad de poner un offset directamente en la salida/puesta del sol, pero he constatado un pequeño error, probablemente desde las últimas versiones. En mi caso, las escenas de apertura por la mañana con un retraso de « después » de 5 minutos o sin offset ya no se activan.
Aclaro que:
las escenas de la noche con un offset de +15 minutos funcionan,
mi ubicación está bien configurada,
la zona horaria también es correcta,
Ver mis registros que indican que el cálculo de apertura se realiza en el pasado.
¿Soy el único que tiene este problema?
Gracias por sus respuestas
DamienLogs salida del sol
Hola (y bienvenido)
He movido tu mensaje a una nueva conversación para tratar el problema aquí.
No puedo recuperar tus registros. De todos modos, voy a ver si hay alguna diferencia en el código entre la mañana y la noche
¿Puedes ponerlos en https://pastebin.com/ y poner el enlace aquí?
Efectivamente hay un error. Hoy (bueno, mañana para el amanecer ) probaré una corrección y te mantendré informado.
Hola cicoub13,
Gracias por tu rapidez… efectivamente, me subo al tren en marcha en la comunidad .
Adjunto el enlace a los registros: https://pastebin.com/e35Q1hVb
Buen día
¡Perfecto, funciona
@pierre-gilles ¿Podrías echar un vistazo a la PR cuando tengas tiempo?
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**
* Improved daily sunrise/sunset scheduling so “today at 12:00” is computed correctly in the selected timezone, preventing missed events and incorrect day boundaries.
* **Tests**
* Added/updated coverage for past sunrise/sunset scenarios, including cases where no job is scheduled, and added a timezone regression test to verify the correct calendar day calculation.
¡Gracias por la PR @cicoub13 !
Te he hecho una revisión aquí: fix(scene): Fix issue with next sunrise trigger by cicoub13 · Pull Request #2548 · GladysAssistant/Gladys · GitHub
Creo que el problema raíz está en otra parte, tenemos un bug de zona horaria en el dailyUpdate creo
Vale, gracias, lo miraré (lunes)
Tenías razón. He corregido la PR y la prueba ha sido concluyente esta mañana
¡Gracias! Me parece bien, está fusionado y saldrá en la próxima versión de Gladys
He instalado la versión 4.80 y confirmo que las escenas activadas al amanecer/atardecer funcionan correctamente.
Me alegra haber podido contribuir modestamente a la detección del problema y gracias sobre todo a vosotros por haberlo resuelto rápidamente
Gracias por tu respuesta, eso es lo que hace avanzar a Gladys