@avantics/node-red-home-automation 2.2.0

Deterministic home automation components for Node-RED

npm install @avantics/node-red-home-automation

Node-RED Home Automation

CI Ko-fi

State-aware Node-RED controllers for reliable lighting and home-theatre automation.

View the smart-home programme and completed project records →

Most home automations translate an event directly into a command. This package adds a deterministic control layer between them: it tracks desired and observed state, preserves manual control, confirms outcomes, retries bounded failures, and rejects stale work.

What it solves

  • Occupancy without flicker: combine PIR motion with optional presence sensing before changing room state.
  • Adaptive lighting with manual ownership: calculate circadian brightness and colour temperature without immediately overwriting wall-switch changes.
  • Honest wall inputs: preserve restart baselines while exposing unconfirmed, stale and unavailable physical-input evidence.
  • Reliable AV transitions: coordinate AVR inputs, TV power, projector warm-up and cooldown, and motorised screens from observed state rather than blind toggles.
  • Honest source readiness: model controllable, externally controlled, and unavailable playback sources without claiming success from an input selection alone.
  • Owned theatre atmosphere: apply activity lighting only to active, non-manual room lights and confirm TV backlighting independently.
  • Bounded receiver volume: coordinate absolute and relative requests through one transport owner while preserving later physical adjustments.
  • Recoverable automation: adopt one fresh, uniquely matching physical activity after lost state; otherwise coordinate a safe Off request.
flowchart LR
  subgraph In[Inputs]
    SENS[Motion and presence sensors]
    LUX[Illuminance]
    WALL[Wall switches]
    REQ[Theatre request<br/>MQTT .../theatre/request]
  end
  subgraph Room[Room lighting]
    OCC[occupancy-fusion]
    MOT[motion-lighting-policy]
    SW[switch-lighting-policy]
    ROOM[room-lighting-controller]
  end
  subgraph Act[Theatre activities]
    CON[theatre-state-contract]
    ACT[theatre-activity-controller]
    ROUTE{{your flow: route by target}}
    AL[activity-lighting-controller]
  end
  subgraph Eq[Theatre equipment]
    EQ[avr / display-mode /<br/>source-capability /<br/>backlighting controllers]
  end
  LIGHTS[(Lights, e.g. Zigbee2MQTT)]
  DEV[(Device transports)]
  STATE[(Retained theatre state<br/>and HA discovery)]

  SENS --> OCC --> MOT
  LUX --> MOT
  WALL --> SW
  MOT --> ROOM
  SW --> ROOM
  ROOM -- set commands --> LIGHTS
  LIGHTS -. observed state .-> ROOM
  REQ --> CON
  CON -- activity intent --> ACT
  ACT -- state snapshot --> CON
  CON --> STATE
  ACT -- theatreCommand --> ROUTE
  ROUTE --> EQ
  ROUTE --> AL
  EQ -- device commands --> DEV
  EQ -. target state .-> ACT
  AL -. target state .-> ACT
  AL -- held-light intents --> ROOM

Each controller keeps the desired and the observed state, sends semantic commands, and reports done only when fresh observations confirm them.

Included nodes

The nodes come in three groups. Each group has an importable example flow (Import → Examples in the Node-RED editor).

Room lighting

Motion, presence, illuminance and wall switches drive one room's lights, with circadian styling and manual ownership. Wire occupancy fusion into the motion policy, and the motion and switch policies into the room controller. Example: Room lighting.json.

Node Purpose
home-occupancy-fusion Combines PIR motion with optional presence sensing.
home-motion-lighting-policy Converts occupancy and illuminance into lighting intent with observable wall-input baselines.
home-switch-lighting-policy Converts raw edges or pre-classified button actions into lighting intent while exposing input freshness and availability.
home-room-lighting-controller Owns the room's light commands, adaptive styling, manual and held lights, and lighting state.

Home theatre equipment

Each controller owns one kind of device. It accepts a generation-scoped intent, sends commands for your device transport on output 1, and reports target state on output 2. Example: Home theatre equipment.json.

Node Purpose
home-avr-controller Owns AVR power, zones, source selection and bounded absolute or relative volume from observed state.
home-display-mode-controller Coordinates TV, projector, and screen transitions.
home-source-capability-controller Gates source readiness on fresh availability, active-device, application or playback evidence.
home-backlighting-controller Owns TV-backlight power with observation-gated confirmation.

Theatre activities

One request, such as "tv" or "off", drives every target. The state contract turns MQTT requests into activity intents and publishes retained state; the activity controller plans each target and sends msg.theatreCommand messages. Your flow routes each command by its target (avr, display, source, lighting, backlighting) to the matching controller's input (msg.avr, msg.display, msg.sourceCapability, msg.activityLighting, msg.backlighting), and wires each controller's output 2 back to the activity controller. Activity lighting feeds the room lighting controller. Example: Home theatre activity.json.

Node Purpose
home-theatre-state-contract Bridges non-retained activity requests to retained MQTT truth and HA discovery.
home-theatre-activity-controller Owns latest-request-wins activity state and aggregates target evidence.
home-activity-lighting-controller Applies activity styles to room lights and holds them while the activity is active.

Pure TypeScript policy modules live in lib/; thin Node-RED runtime and editor adapters live in nodes/.

Importable example flows for the Node-RED editor live in examples/ (Import → Examples). Executable, deployment-neutral contract examples live in contract-examples/ and exercise the same reducers as the runtime adapters.

Requirements

  • Node.js 22.9 or newer
  • Node-RED 5.0.x

Install

In Node-RED, open Manage palette → Install and search for @avantics/node-red-home-automation. Or install it from your Node-RED user directory (usually ~/.node-red) and restart Node-RED:

npm install @avantics/node-red-home-automation

Each GitHub Release also attaches the package tarball and its SHA-256 checksum. Install a downloaded tarball through Manage palette → Install → Upload module, or with:

npm install /path/to/avantics-node-red-home-automation-2.2.0.tgz

Add the installed nodes from the home automation section of the Node-RED palette, then configure the room, device hosts, MQTT topics, source mappings, and timing limits for your deployment.

The whole-theatre MQTT contract uses non-retained requests at home/<area>/theatre/request; every request supplies a unique requestId and an explicit configured activity. Controller output is retained under desired, current, phase, failure, availability, metrics, slo, and health/<target>. Metrics expose transition latency and outcome counts plus per-target retry, fallback, confirmation-latency, failure, manual-override, and availability evidence. The SLO evaluator keeps a bounded outcome window, publishes success rate plus p50/p95 transition latency, and exposes an actionable Home Assistant problem sensor. Defaults are a 60-second transition budget, 95% success objective, 20 outcomes and five samples before normal evaluation; active timeouts and explicit failures breach immediately. Expected waiting_for_source and physical manual ownership do not create false operational failures. Retained request messages are deliberately inert.

MQTT state topics may be retained so controllers can rebuild observed state after a restart. Command and request topics must not be retained. Raw wall-input reducers preserve a persisted baseline but report it as unconfirmed until this runtime receives an observation. Retained observations and messages marked msg.baseline = true establish an inert baseline; duplicate observations refresh freshness without replaying commands. When no baseline exists, a live non-retained state change remains an actionable edge for event-only inputs. Send source switch-availability to invalidate a disconnected input baseline; the first recovered observation then re-baselines without a gesture. An observation timestamp may be supplied as msg.observedAt or msg.payload.observedAt; otherwise only live, non-retained observations receive the current timestamp.

Unsolicited display, AVR, source, and backlighting changes latch manual ownership instead of issuing corrective commands. A newer explicit activity request resumes automation. Recovery adopts physical state only when fresh display, AVR, source, and backlighting evidence matches exactly one configured profile; missing or ambiguous startup evidence invokes the configured Off activity.

Room light control

The room lighting controller gives each target one control state:

  • in-control: circadian lighting may style and refresh the light (the default).
  • overridden: another owner, such as an activity or a scene, holds the light; refresh and circadian changes leave it alone until it is released.
  • manual: a person changed the light.

Add owner to an intent to override the targets it switches on. With preserveManual: true, manual lights are skipped:

msg.lighting = {
  kind: "intent",
  targets: ["wall", "lamp"],
  state: "ON",
  source: "activity",
  owner: "theatre",
  values: {brightness: 64, color_temp: 400},
  preserveManual: true
};

home-activity-lighting-controller does this itself: while a profile is active it overrides that profile's lights under its configured owner (default activity), and when a new profile drops a light, including an off profile with no targets, it releases it. Give each activity-lighting node that feeds the same room controller its own Owner; with a shared name, one node's release hands back lights the other still holds. A flow that sets its own owner must set it on every lighting message from the node, releases included, or leave it to the node's Owner setting.

Release overridden targets (default: all; with owner, only that owner's lights). Released lights that are on are restyled as a refresh would:

msg.lighting = {kind: "release", targets: ["wall", "lamp"], owner: "theatre"};

A held (overridden) light changes only for an intent with an owner (its own, or a newer owner who takes it over), a person (manual: true, an external command on the command topic, or a change seen at the light), or a release. Other intents, such as motion ON or OFF and owner-less values, leave it alone and are traced as ignored held-by; their other targets are still handled. The package's wall-switch policies mark presses with person: true. Owner-less intents, with or without values, reach a held light only with manual: true or person: true; a flow acting for a person, such as a dashboard, sets one. Switching a light off by its owner or a person returns it to in-control. On startup and whenever a target's state changes, the controller sends a retained message on its command output:

{topic: "home/<area>/lighting/<target>/control", payload: {state: "overridden", owner: "theatre"}, retain: true}

Flows that filter that output by topic must pass the /control topics through.

Receiver volume ownership

Send semantic requests to the AVR controller rather than publishing protocol commands directly:

msg.avr = {
  kind: "volume",
  requestId: "volume-control-1",
  mode: "relative",
  value: 1
};

mode may be absolute or relative. The controller resolves relative input from fresh observed volume, accumulates rapid requests against the pending target, applies configured half-step bounds, retries through the existing bounded transport path, and confirms completion from fresh receiver evidence. Once confirmed, it releases the volume target; a later physical or external adjustment becomes the new baseline instead of being corrected.

Contract examples

Build and run all seven public contracts:

npm run examples
Example Boundary demonstrated
occupancy-fusion.mjs Motion establishes occupancy; optional presence can hold it.
motion-lighting.mjs Occupancy and illuminance produce semantic lighting intent.
switch-gestures.mjs Wall actions produce toggle or explicit manual-brightness intent.
room-lighting.mjs The room owner converts semantic intent into a transport command.
source-readiness.mjs Fresh application evidence confirms source readiness.
volume-ownership.mjs Bounded relative requests accumulate and release ownership after fresh confirmation.
theatre-activity.mjs Coordinated activity waits for fresh target-owner evidence.

Each example uses synthetic identifiers and configuration, asserts its central invariant, and prints the complete input/output contract as JSON.

Configuration and security

The repository contains no home-network addresses, deployment coordinates, or live credentials. Device hosts and room coordinates are required configuration where applicable.

The display controller stores its Bravia PSK as a Node-RED credential. Keep credentials in Node-RED's encrypted credential store rather than flow fields or repository files.

Report suspected vulnerabilities privately using the process in SECURITY.md, not through a public issue.

Public repository boundary

This repository contains reusable controller code and general delivery status. Live flows, private hostnames and IP addresses, Home Assistant entity IDs, backup paths, credentials, and infrastructure operations belong only in the private deployment repositories. npm run scan:public enforces the machine- detectable parts of that boundary.

Development

npm ci
npm test
npm run examples

The strict TypeScript build, compiled test suite, executable contract examples, dependency audit, public-content scan, and secret scan run in CI. See CONTRIBUTING.md for local checks and the optional pre-commit setup.

Contributing

Contributions are welcome: see CONTRIBUTING.md and the Code of Conduct.

License

MIT

Node Info

Version: 2.2.0
Updated 6 hours ago
License: MIT
Rating: not yet rated

Categories

Actions

Rate:

Downloads

0 in the last week

Nodes

  • home-occupancy-fusion
  • home-motion-lighting-policy
  • home-switch-lighting-policy
  • home-room-lighting-controller
  • home-avr-controller
  • home-display-mode-controller
  • home-source-capability-controller
  • home-activity-lighting-controller
  • home-backlighting-controller
  • home-theatre-activity-controller
  • home-theatre-state-contract

Keywords

  • node-red
  • home-automation
  • typescript
  • lighting
  • home-theatre
  • mqtt

Maintainers