Docs
Global functions

Scheduling

schedule, unschedule, runDaily, runOnce, runIn, scheduleAtSunrise, scheduleAtSunset

Global functions available to smart-app code. Call them by bare name; there is no object to import.

FunctionSummary
scheduleRun a handler on a cron schedule, evaluated in the home’s time zone.
unscheduleCancel scheduled work: every schedule and pending timer of this app, or only those bound to one handler.
runDailyRun a handler every day at a wall-clock time in the home’s time zone.
runOnceRun a handler once at an absolute instant.
runInOne-shot delayed handler.
scheduleAtSunriseRun a handler once at the next sunrise (plus an optional offset).
scheduleAtSunsetRun a handler once at the next sunset (plus an optional offset).

schedule

Run a handler on a cron schedule, evaluated in the home’s time zone. Persisted across reboots.

Signature

function schedule(cron: string, handler: unknown): void

Parameters

NameTypeRequiredDefaultDescription
cronstringyes—Standard 5-field cron (minute hour day month weekday); a leading 6th field for seconds is also accepted.
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.

Returns

void

Notes

  • The expression fires in the zone returned by getHomeTimeZone(), not the process zone. Use formatDateParts(new Date(), getHomeTimeZone()) inside the handler for any additional time logic.

Examples

schedule('0 22 * * 1-5', lockUp); // 22:00 on weekdays, home time

See also

unschedule · runDaily · scheduling


unschedule

Cancel scheduled work: every schedule and pending timer of this app, or only those bound to one handler.

Signature

function unschedule(handler: unknown): void

Parameters

NameTypeRequiredDefaultDescription
handlerunknownyes—undefined cancels everything this instance scheduled (cron jobs, runIn, runOnce, sunrise/sunset). A function or name cancels only that handler’s entries.

Returns

void

Examples

unschedule(turnLightsOff); // motion resumed: drop the pending off-timer

See also

schedule · runIn


runDaily

Run a handler every day at a wall-clock time in the home’s time zone.

Signature

function runDaily(timeOfDay: string, handler: unknown): void

Parameters

NameTypeRequiredDefaultDescription
timeOfDaystringyes—HH:MM, 24-hour.
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.

Returns

void

Examples

runDaily('07:30', openBlinds);

See also

schedule · runOnce


runOnce

Run a handler once at an absolute instant.

Signature

function runOnce(whenIsoOrDate: string | Date, handler: unknown): void

Parameters

NameTypeRequiredDefaultDescription
whenIsoOrDatestring | Dateyes—An ISO-8601 string. Although the type also allows a Date, the helper currently ignores anything that is not a string, so pass date.toISOString().
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.

Returns

void — Silently does nothing when the instant is in the past or the string does not parse.

Notes

  • Timers are persisted; a timer that comes due while the hub is down fires once on boot.

Examples

const at = new Date(Date.now() + 90 * 60 * 1000);
runOnce(at.toISOString(), reminder);

See also

runIn · unschedule


runIn

One-shot delayed handler. Replace-by-default: re-arming the same handler supersedes its pending runIn timer(s). Pass { overwrite: false } to stack concurrent timers (e.g. token-keyed duration waits).

Signature

function runIn(delaySeconds: number, handler: unknown, data?: Record<string, unknown>, options?: { overwrite?: boolean }): void

Parameters

NameTypeRequiredDefaultDescription
delaySecondsnumberyes—Delay before the handler fires, in seconds.
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.
dataRecord<string, unknown>no{}Passed to the handler as its argument. Must be JSON-serialisable; persisted with the timer.
options{ overwrite?: boolean }no{}Timer behaviour flags.
options.overwritesee signaturenotruetrue (default) replaces any pending timer for the same handler; false stacks a new one alongside it.

Returns

void

Notes

  • Timers survive reboots and code updates; one that came due while the hub was off fires once on boot.
  • The handler runs in a fresh isolate — nothing but state, settings and data carries over.

Examples

runIn(minutes * 60, turnLightsOff);
Stacked timers keyed by data
runIn(300, releaseLock, { token: evt.entityId }, { overwrite: false });

function releaseLock(data) {
  console.log('releasing', data.token);
}

See also

unschedule · runOnce · scheduling


scheduleAtSunrise

Run a handler once at the next sunrise (plus an optional offset). One-shot: re-arm inside the handler or on systemStart for a daily effect.

Signature

function scheduleAtSunrise(handler: unknown, offsetMinutes?: number): void

Parameters

NameTypeRequiredDefaultDescription
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.
offsetMinutesnumberno0Minutes after sunrise; negative means before. If the offset time for today has passed, the next day’s sunrise is used.

Returns

void

Notes

  • Needs the hub’s location (monitoring address). Check getSunTimes().available if you must handle hubs without one.

Examples

function onSunrise() {
  $g.porch.turnOff();
  scheduleAtSunrise(onSunrise); // re-arm for tomorrow
}
scheduleAtSunrise(onSunrise, -15);

See also

scheduleAtSunset · getSunTimes


scheduleAtSunset

Run a handler once at the next sunset (plus an optional offset). One-shot: re-arm inside the handler or on systemStart for a daily effect.

Signature

function scheduleAtSunset(handler: unknown, offsetMinutes?: number): void

Parameters

NameTypeRequiredDefaultDescription
handlerunknownyes—A top-level named function (or its name as a string). Handlers are dispatched by name, so arrow functions assigned to variables cannot be used.
offsetMinutesnumberno0Minutes after sunset; negative means before.

Returns

void

Examples

scheduleAtSunset(onSunset, 30); // half an hour after sunset

See also

scheduleAtSunrise · getSunTimes

Generated from docs-bundle v0.1.0, novon-platform 9ce3486c (2026-10-09).

On this page