Docs

Parent and child apps

Container apps that host many rules, how children are installed, and how instances find each other.

A parent declares childApps; a child declares parent. People install the parent once and then add any number of children under it from the parent's preferences. The built-in Rule Maker (parent) and SimpleRule (child) are the reference pair.

Declaring the relationship

In the definition metadata (built-ins put these in the JSDoc manifest):

parent:    childApps: [{ namespace: 'com.example', name: 'Rule' }], singleInstance: true
child:     parent: { namespace: 'com.example', name: 'Rule Maker' }

The app input

The parent's preferences show its children with an input of type app:

{
  key: 'rules',
  label: 'Rules',
  type: 'app',
  childRef: { namespace: 'com.example', name: 'Rule' },
  multiple: true,
}

The app renders it as the list of installed children plus an Add new button that starts the child's own install wizard with parentAppId set. The value is read live from the hub, not stored in the parent's settings, and it is not hydrated as a global.

Talking across instances

FunctionReturns
getChildApps()SmartAppInstanceHandle[] for this instance's children ([] if none)
getParent()the parent's handle or null
getChildAppById(appId)one child or null
listSmartAppInstances()every other instance on the hub, with label and parentAppId
runSmartApp(appId)fire the target's run()
pauseSmartApp(appId, seconds?) / resumeSmartApp(appId)pause / resume a target ('' for self)

Handles are identity only (appId, appDefinitionId, appName); runtime state is private to each instance. To exchange data, use location events:

// child → parent
sendLocationEvent('com.example.rule.fired', { from: definition.name });

// parent
subscribeToLocationEvent('com.example.rule.fired', onChildFired);

Lifecycle rules

  • Uninstalling a parent cascades: children are uninstalled first, then the parent's uninstalled runs.
  • Pausing a parent pauses every descendant.
  • singletonPerParent: true limits a child definition to one instance per parent.

Example: Scene Scheduler

The container itself has almost no code; all behaviour lives in the children, which report back with a location event. The complete pair is in the Scene Scheduler example.

On this page