Docs
Examples

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:

ExamplePatternMainly uses
Fan auto-offturn something off a while after it turns onrunIn replace semantics, actorType gating
Porch lightsunset on, fixed time off, every dayscheduleAtSunset, runDaily, systemStart
Morning routinerun once per day, only inside a time windowhome-clock time maths, a date key in state, run()
Motion light by time of daypick different devices and levels by time of dayarray rows, per-row entity lists, multi-sensor motion
Door left openalert when a sensor stays in a state too longper-entity timers with data, push to chosen people
Temperature alertreact to a numeric reading with hysteresissubscribe(…, {}), numeric state, unit labels
Away setbackact on household presencesystem entities, thermostat services, a delayed action
Alarm webhooktell an outside service what happenedhttpRequest, event context, a password input
Scene schedulera container hosting many small rulesparent / child apps, app input, location events
Simple triggerlet the installer compose trigger and actionsdynamic 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

  • installed and updated both call initialize, and updated tears down first with unsubscribe() and unschedule(). See Lifecycle.
  • Every input is guarded. Unset inputs are undefined, not their default; multi-selects can be one wrapper or many. See Inputs to globals.
  • Wall-clock decisions use the home's clock, formatDateParts(new Date(), getHomeTimeZone()), never Date.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.

On this page