Skip to content

Sun events - #57

Closed
Dnovak043 wants to merge 2 commits into
ianperrin:masterfrom
Dnovak043:sun-events
Closed

Dnovak043 wants to merge 2 commits into
ianperrin:masterfrom
Dnovak043:sun-events

Conversation

@Dnovak043

Copy link
Copy Markdown

Add local sun events (sunrise, sunset, dusk, dawn…) as schedule times

Lets any from, to or schedule value be a sun event instead of a cron expression, so modules can follow daylight through the seasons:

config: {
  sun: { lat: 47.61, lon: -122.33 },
  global_schedule: [
    { from: "dusk", to: "dawn", groupClass: "night" },
    { from: "sunrise+30", to: "sunset-1h", groupClass: "day" }
  ]
}
  • Events: every suncalc event, including sunrise/sunset, civil, nautical and astronomical dawn/dusk, golden hour and solar noon. Custom events can be added by sun angle (sun.events).
  • Offsets: in minutes or hours, e.g. dusk+15, dawn-1.5h.
  • Calculated locally with suncalc (new dependency, ^2.0.2) from sun.lat/sun.lon. No network or other modules involved.
  • Recalculation is configurable with a cron expression: sun.recalculate (default daily at 00:05), overridable per schedule entry with recalculate.
  • Existing cron schedules are unaffected. No sun calculation or extra timers run unless a sun event is used.

Most of the logic is in a new sun_scheduler.js. node_helper.js changes are small: createCronJob returns a cron-compatible SunCronJob for sun expressions, so the startup-state check and job cleanup work unchanged. The README has a new “Sun Event Schedules” section covering options, event names, offsets and recalculation.

Existing unit tests, ESLint and Prettier all pass. I also tested it on MagicMirror 2.38: global, module and notification schedules, page reloads, daylight-saving days and polar day/night.

@Dnovak043 Dnovak043 closed this Nov 13, 2026
@Dnovak043
Dnovak043 deleted the sun-events branch November 13, 2026 01:32
@Dnovak043
Dnovak043 restored the sun-events branch November 13, 2026 01:36
@Dnovak043
Dnovak043 deleted the sun-events branch November 13, 2026 02:12
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.

1 participant