Examples
Ten small, complete smart apps you can register as they are, one per common pattern.
Every example on these pages is a whole file: paste it into Smart apps → Register a smart app
in the admin console, install it from the Novon app, and it runs. They are written in plain
JavaScript in the style used throughout this guide (top-level definition, preferences and
function handlers); the TypeScript authoring page shows how to
write the same code with types.
Start with Getting started if you have not built an app yet. Then pick the example closest to what you want to build:
| Example | Pattern | Mainly uses |
|---|---|---|
| Fan auto-off | turn something off a while after it turns on | runIn replace semantics, actorType gating |
| Porch light | sunset on, fixed time off, every day | scheduleAtSunset, runDaily, systemStart |
| Morning routine | run once per day, only inside a time window | home-clock time maths, a date key in state, run() |
| Motion light by time of day | pick different devices and levels by time of day | array rows, per-row entity lists, multi-sensor motion |
| Door left open | alert when a sensor stays in a state too long | per-entity timers with data, push to chosen people |
| Temperature alert | react to a numeric reading with hysteresis | subscribe(…, {}), numeric state, unit labels |
| Away setback | act on household presence | system entities, thermostat services, a delayed action |
| Alarm webhook | tell an outside service what happened | httpRequest, event context, a password input |
| Scene scheduler | a container hosting many small rules | parent / child apps, app input, location events |
| Simple trigger | let the installer compose trigger and actions | dynamic preferences, catalog introspection, action rows |
Built-in apps
The hub ships a set of built-in apps written against this same API. Their source is not published, but each one is built from the patterns above; the built-in apps page says which example covers which app.
Conventions the examples share
installedandupdatedboth callinitialize, andupdatedtears down first withunsubscribe()andunschedule(). See Lifecycle.- Every input is guarded. Unset inputs are
undefined, not theirdefault; multi-selects can be one wrapper or many. See Inputs to globals. - Wall-clock decisions use the home's clock,
formatDateParts(new Date(), getHomeTimeZone()), neverDate.getHours(). See Scheduling › Time zones. - Anything that must survive between handlers lives in
state. See State. - States are compared by label where a person would read them (
'Open','Detected'), which needs a hub on the friendly-state runtime; raw tokens ('on') work everywhere. See Raw tokens and friendly labels. - The namespace is
com.example. Change it to one you control before registering.