Skip to content

feat(alerts): send daily summary at sunset instead of fixed hour - #8

Merged
gnacho merged 1 commit into
mainfrom
feat/helios-sunset-summary
Aug 8, 2026
Merged

gnacho merged 1 commit into
mainfrom
feat/helios-sunset-summary

Conversation

@gnacho

@gnacho gnacho commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Closes #6.

What

The daily production summary is now scheduled at sunset + 10 min (from sun.sun next_setting) instead of a fixed 21:00, so it lands right when the production day ends — year-round, not just in summer when 21:00 happens to approximate dusk.

How

  • proximoEnvioResumen(ha, ahora) returns the next fire time: sun.sun.next_setting + RESUMEN_OFFSET_MIN when solar data is available (always the next sunset, today or tomorrow), falling back to the existing fixed hour HORA_RESUMEN_DIARIO (21:00) only when HAOS is down and there's no sunset data.
  • ejecutarResumenSiToca adds a same-day guard persisted in kv (resumen_ultimo_envio, survives restarts) so the summary is never sent twice on the same calendar day. This is required because the fallback (21:00) and the sunset path can both fall on the same day (summer: fallback before sunset; winter: sunset before fallback); without the guard the fallback would preempt sunset in steady state.
  • scheduleResumenDiario retries briefly (30 s) if sun.sun isn't cached yet at boot — the subscribe_entities ack arrives before the state dump, so without this the first scheduling after every restart would incorrectly commit to the fallback. Falls back to the fixed hour only if sunset data genuinely never arrives (HAOS down all day).
  • The user-facing notification label no longer promises a fixed hour (ajustes.notif.tipos.resumen_diario): "Resumen diario al anochecer" / "Daily summary at sunset" / "每日总结(日落时)".

Verification

  • Server tests 39/39 (was 33), with red-green confirmed for both the sunset-time computation and the same-day guard (each fails when the corresponding logic is stubbed out).
  • Front lint 0 errors; build OK; theme-audit OK.
  • Deployed to production: alerts.js md5 local == CT; front bundle hash local == CT == HTTPS. Service active, NRestarts 0, HAOS connected, /health ok.
  • Runtime log confirms the sunset path (not the fallback): after the 30 s boot retry, resumen diario programado para <sunset-tomorrow + 10min>.

Notes

  • RESUMEN_OFFSET_MIN (10 min) lets the last production interval of the day settle before the KPIs are read. It's an exported constant; making it user-configurable is left for a follow-up if needed.
  • No DB migration: the guard uses the existing kv store.

Schedule the daily production summary at sunset (sun.sun next_setting +
10 min offset to let the last production interval settle) instead of a
fixed 21:00. Falls back to 21:00 fixed when solar data is unavailable
(HAOS down) or today's sunset already passed, so no day is ever skipped
or double-sent. Stop promising a fixed hour in the user-facing label.

Closes #6
@gnacho
gnacho force-pushed the feat/helios-sunset-summary branch from c301dd2 to 0c39760 Compare August 8, 2026 20:11
@gnacho
gnacho merged commit 234f71b into main Aug 8, 2026
4 checks passed
@gnacho
gnacho deleted the feat/helios-sunset-summary branch August 8, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send daily production summary at sunset instead of a fixed hour

1 participant