@avantics/node-red-home-automation 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -274,11 +274,43 @@ also attaches the package tarball and its SHA-256 checksum. Install a downloaded
274
274
  tarball through **Manage palette → Install → Upload module**, or with:
275
275
 
276
276
  ```sh
277
- npm install /path/to/avantics-node-red-home-automation-6.0.0.tgz
277
+ npm install /path/to/avantics-node-red-home-automation-6.1.0.tgz
278
278
  ```
279
279
 
280
280
  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.
281
281
 
282
+ ### 6.1.0
283
+
284
+ Nothing to migrate from 6.0.0, but check one wiring change: publishing nodes
285
+ now announce themselves when MQTT out connects.
286
+
287
+ **Wire a Status node watching MQTT out into each publishing node.** Node-RED's
288
+ MQTT broker node connects after the flows start and drops anything sent before
289
+ then, so in 6.0.0 the Home Assistant discovery and availability a node announced
290
+ as the flows started could be lost after a restart or a full deploy (#185). A
291
+ message from a Status node whose scope is your MQTT out node now counts as the
292
+ node's startup message when it reports "connected", including after every
293
+ reconnect. An existing startup inject keeps working. The examples now use the
294
+ Status node.
295
+
296
+ **Room owners hold lights on or off, stack, and give lights back.** An owner,
297
+ such as an activity or the coming scene node, now keeps a light it switches
298
+ off held off, so motion leaves it alone. Owners stack per light: the newest
299
+ holds a shared light and hands it to the one beneath when it releases. When the
300
+ last owner lets go, a light the room was running is the room's again, a light
301
+ that was off goes off, and a light a person set gets its values back and stays
302
+ manual. In a home theatre, a light a person changed during an activity and a
303
+ later request took back now gets the person's values back when the activity
304
+ ends.
305
+
306
+ Also fixed:
307
+
308
+ - **Zigbee2MQTT light nodes** no longer log an error for every command meant for
309
+ another light in the same room (#184).
310
+ - **Zigbee2MQTT groups:** the docs recommend `retain: true` under the group in
311
+ Zigbee2MQTT's `configuration.yaml`, so the room has a group's state after a
312
+ restart (#186).
313
+
282
314
  ### 6.0.0
283
315
 
284
316
  Circadian lighting becomes its own node, the room controller reaches its
@@ -306,7 +338,9 @@ edit covers both moves:
306
338
  whose topics weren't Zigbee2MQTT's (`<base>/<name>` and `<base>/<name>/set`)
307
339
  is flagged: set it up by hand on the
308
340
  [neutral light contract](#neutral-light-contract). A Zigbee2MQTT group works
309
- the same way: tick **Zigbee2MQTT group** on its node.
341
+ the same way: tick **Zigbee2MQTT group** on its node, and set
342
+ `retain: true` under the group in Zigbee2MQTT's `configuration.yaml`, so the room has its state after a restart (a
343
+ group can't be asked for it).
310
344
  2. Add a **circadian lighting policy** from the palette and wire its first
311
345
  output into the room controller. One policy can feed several rooms that
312
346
  share its settings, but its Home Assistant switches and set topics are named
@@ -419,7 +453,12 @@ Also new in 6.0.0, with nothing to change:
419
453
  the wall switches guide).
420
454
  - **Discovery as the flows start.** Every publishing node, now including the
421
455
  room controller and the theatre state contract, announces its Home Assistant
422
- entities once the flows start, as well as at its startup message.
456
+ entities once the flows start, as well as at its startup message. On a
457
+ first start, a full deploy or a restart that announcement is lost, as
458
+ Node-RED's MQTT broker node connects only afterwards, so from 6.0.1 wire a
459
+ **Status node** watching your MQTT out node into each publishing node: it
460
+ announces again each time MQTT out connects (see "Send each publishing node
461
+ its startup message" below).
423
462
  - **A documentation site** with a guide for each area, a reference page for
424
463
  every node and a releases page:
425
464
  [avantics-hq.github.io/node-red-home-automation](https://avantics-hq.github.io/node-red-home-automation/).
@@ -626,9 +665,16 @@ Version 3.0 changed some behaviour, and later versions added to it. Check these
626
665
  publishing off entirely, are cleared only from the record. A node that never gets a startup message
627
666
  keeps clearing its old topics at every start, so to move an area from one older room node to another, send the old
628
667
  node a startup message, or delete it.
629
- - **Send each publishing node a startup message once, a few seconds after deploy.** The example flows do this with an
630
- inject node set to fire once after 3 seconds: by then the MQTT broker node has usually connected, and a message
631
- sent before it connects is dropped, along with the discovery and state it carried.
668
+ - **Send each publishing node its startup message once MQTT out has connected: wire in a Status node.** Node-RED's
669
+ MQTT broker node connects after the flows have started and drops anything it is given before then, without a
670
+ warning, so what a node announces as the flows start (its availability, discovery and state) is lost on a first
671
+ start, a full deploy or a restart. Add a **Status node** whose scope is your MQTT out node and wire it into each
672
+ publishing node (room, circadian policy, house schedule MQTT, motion, occupancy, cover controller, AVR controller,
673
+ theatre state contract, Shelly switch). Each time MQTT out shows "connected", including after the broker
674
+ reconnects, the Status node passes it on, and the node takes it as its startup message. Other status messages are
675
+ ignored, so a Status node watching every node on the flow works too; the example flows use one. Since 6.0.1; before
676
+ that, the examples sent the startup message from an inject node 3 seconds after a deploy, which is lost if the
677
+ broker takes longer. A node still takes its own startup message (each node's section gives it).
632
678
  - **Removing entities:** deleting a node clears its Home Assistant entities and retained state, but only when you
633
679
  deploy with "Modified nodes" or "Modified flows". On a full deploy (the deploy button's default), Node-RED stops the
634
680
  MQTT out node at the same moment, so the clearing never reaches the broker. Disabling a node or its flow keeps its
@@ -743,8 +789,8 @@ The room lighting controller gives each target one control state:
743
789
 
744
790
  - `in-control`: the room styles the light with the style it is sent, such as a
745
791
  circadian lighting policy's (the default).
746
- - `overridden`: another owner, such as an activity or a scene, holds the light;
747
- styles leave it alone until it is released.
792
+ - `overridden`: another owner, such as an activity or a scene, holds the light
793
+ on or off; styles and owner-less intents leave it alone until it is released.
748
794
  - `manual`: a person changed the light: an intent with `manual: true` (a wall
749
795
  switch's double press), or someone else's command with values on its command
750
796
  topic. An intent's values alone don't make a light manual. Switching circadian
@@ -760,8 +806,9 @@ nothing names can keep its start-time style all day; to bring it back into step,
760
806
  switch circadian lighting on (for example with the Home Assistant circadian
761
807
  switch), or let motion or a wall switch name it.
762
808
 
763
- Add `owner` to an intent to override the targets it switches on. With
764
- `preserveManual: true`, manual lights are skipped:
809
+ Add `owner` to an intent to hold its targets, on or off: an owner's OFF keeps
810
+ the light off, so motion can't switch it back on. With `preserveManual: true`,
811
+ manual lights are skipped:
765
812
 
766
813
  ```js
767
814
  msg.lighting = {
@@ -795,14 +842,31 @@ hands back lights the other still holds. A flow that sets its own `owner` must
795
842
  set it on every lighting message from the node, releases included, or leave it
796
843
  to the node's Owner setting.
797
844
 
845
+ Owners stack, per light. The first owner to take a light records what it was:
846
+ its control state, whether it was on, and the brightness and colour temperature
847
+ it last reported. A newer owner goes on top and sets the light; the owner
848
+ beneath keeps its own request, and sending again updates it without changing
849
+ the light.
850
+
798
851
  Release overridden targets (default: all; with `owner`, only that owner's
799
- lights). Released lights that are on are restyled with the room's style, over
800
- the style's own transition:
852
+ lights):
801
853
 
802
854
  ```js
803
855
  msg.lighting = {kind: "release", targets: ["wall", "lamp"], owner: "theatre"};
804
856
  ```
805
857
 
858
+ - Releasing the owner on top hands the light to the owner beneath, with what
859
+ that owner last asked for.
860
+ - Releasing an owner beneath a newer one just drops it; the light is left as
861
+ it is.
862
+ - When the last owner lets go (or a release without `owner`), the light goes
863
+ back to what was recorded. A light the room was running is the room's again,
864
+ on or off as it was: on, it takes the room's style as it is now (over the
865
+ style's own transition if it was still on, the room's turn-on transition if
866
+ it was held off). A light that was off goes off. A light a person had set
867
+ gets the brightness and colour temperature it last reported, and stays
868
+ `manual`.
869
+
806
870
  A held (`overridden`) light changes only for an intent with an `owner` (its own,
807
871
  or a newer owner who takes it over), a person (`manual: true`, an external
808
872
  command on the light (from its adapter), or a change seen at the light), or a release.
@@ -811,7 +875,9 @@ and are traced as `ignored held-by`; their other targets are still handled.
811
875
  The switch policy marks presses with `person: true`. Owner-less
812
876
  intents, with or without values, reach a held light only with `manual: true` or
813
877
  `person: true`; a flow acting for a person, such as a dashboard, sets one.
814
- Switching a light off by its owner or a person returns it to `in-control`. With
878
+ A person switching a held light off returns it to `in-control`; a person
879
+ switching on a light an owner holds off makes it `manual`. Either way it leaves
880
+ every owner, and their later releases leave it alone. With
815
881
  **Publish state over MQTT** on (new nodes start with it off; nodes saved before
816
882
  the setting existed keep it on), on startup and whenever a target's state
817
883
  changes, the controller sends a retained message on its command output:
@@ -1,6 +1,7 @@
1
1
  import type { TraceEntry } from "./bounded-trace";
2
2
  import type { LightStyle } from "./light-styling";
3
3
  import { type LightField, type LightRoomMessage } from "./light-contract";
4
+ import { type LightHold } from "./room-holds";
4
5
  import { type ExpectedCommand } from "./command-echo";
5
6
  export { fingerprint, parsePayload, type ExpectedCommand } from "./command-echo";
6
7
  export interface RoomTarget {
@@ -33,6 +34,7 @@ export type TargetControl = {
33
34
  state: "overridden";
34
35
  owner: string;
35
36
  };
37
+ export type { HeldSpec, LightHold } from "./room-holds";
36
38
  export declare const REMOVED_LIGHT_UNITS = "removed-light-units";
37
39
  export declare const INVALID_LIGHT_VALUES = "invalid-light-values";
38
40
  export declare const ON_OFF_ONLY = "on-off-only";
@@ -44,6 +46,7 @@ export interface RoomState {
44
46
  observed: Record<string, RoomObservation>;
45
47
  desired: Record<string, boolean>;
46
48
  control: Record<string, TargetControl>;
49
+ holds: Record<string, LightHold>;
47
50
  expected: Record<string, ExpectedCommand[]>;
48
51
  style: RoomStyle | null;
49
52
  personAt: Record<string, number>;
@@ -8,6 +8,7 @@ exports.intentValues = intentValues;
8
8
  exports.transitionRoom = transitionRoom;
9
9
  const light_contract_1 = require("./light-contract");
10
10
  const z2m_light_1 = require("./z2m-light");
11
+ const room_holds_1 = require("./room-holds");
11
12
  const command_echo_1 = require("./command-echo");
12
13
  var command_echo_2 = require("./command-echo");
13
14
  Object.defineProperty(exports, "fingerprint", { enumerable: true, get: function () { return command_echo_2.fingerprint; } });
@@ -66,10 +67,12 @@ function savedControl(saved) {
66
67
  .map(([target]) => [target, { state: "manual" }]));
67
68
  }
68
69
  function createRoomState(config, saved = {}) {
70
+ const control = savedControl(saved);
69
71
  return {
70
72
  observed: { ...(saved.observed || {}) },
71
73
  desired: { ...(saved.desired || {}) },
72
- control: savedControl(saved),
74
+ control,
75
+ holds: (0, room_holds_1.savedHolds)(saved.holds, (target) => control[target]?.state === "overridden"),
73
76
  expected: Object.fromEntries(Object.entries(saved.expected || {}).map(([target, entries]) => [target, entries.map((entry) => ({ ...entry }))])),
74
77
  style: savedStyle(saved.style),
75
78
  personAt: Object.fromEntries(Object.entries(saved.personAt || {})
@@ -159,6 +162,9 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
159
162
  return state.control[targetId]?.state ?? "in-control";
160
163
  }
161
164
  function setControl(targetId, next, reason) {
165
+ // A light no owner holds has no owners to remember.
166
+ if (next?.state !== "overridden")
167
+ delete state.holds[targetId];
162
168
  const previous = state.control[targetId] ?? null;
163
169
  if (JSON.stringify(previous) === JSON.stringify(next))
164
170
  return;
@@ -174,6 +180,72 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
174
180
  previous: previous?.state ?? "in-control"
175
181
  });
176
182
  }
183
+ // An overridden light's owners. A light held under state saved before 6.1
184
+ // has its one owner, with nothing known of what it was before.
185
+ function holdOf(targetId) {
186
+ const entry = state.control[targetId];
187
+ state.holds[targetId] ??= entry?.state === "overridden" ? (0, room_holds_1.legacyHold)(entry.owner) : { owners: [], before: null };
188
+ return state.holds[targetId];
189
+ }
190
+ // Whether the owner on top holds the light off.
191
+ function heldOff(targetId) {
192
+ return controlOf(targetId) === "overridden" && (0, room_holds_1.heldOff)(state.holds[targetId]);
193
+ }
194
+ // An owner taking a light, or asking again. The first owner records what
195
+ // the light was; a newer one goes on top. True when the owner is beneath
196
+ // a newer one: its request is remembered for when the newer lets go, and
197
+ // the light is left as it is.
198
+ function takeHold(targetId, owner, wasOn) {
199
+ const entry = state.control[targetId];
200
+ if (entry?.state !== "overridden") {
201
+ const observed = state.observed[targetId];
202
+ state.holds[targetId] = (0, room_holds_1.newHold)(owner, {
203
+ control: entry?.state === "manual" ? "manual" : "in-control",
204
+ on: wasOn,
205
+ ...(typeof observed?.brightnessPct === "number" ? { brightnessPct: observed.brightnessPct } : {}),
206
+ ...(typeof observed?.colorTempKelvin === "number" ? { colorTempKelvin: observed.colorTempKelvin } : {})
207
+ });
208
+ setControl(targetId, { state: "overridden", owner }, "owner-intent");
209
+ return false;
210
+ }
211
+ const added = (0, room_holds_1.addOwner)(holdOf(targetId), owner);
212
+ if (added === "pushed")
213
+ setControl(targetId, { state: "overridden", owner }, "owner-intent");
214
+ return added === "beneath";
215
+ }
216
+ // The last owner let go: the light goes back to what it was. One the room
217
+ // was running is the room's again, on or off as it was, in the style in
218
+ // force; one that was a person's gets their values back and stays theirs.
219
+ function restoreHeld(targetId, before, source) {
220
+ setControl(targetId, before?.control === "manual" ? { state: "manual" } : null, "released");
221
+ told(targetId);
222
+ const on = intendedOn(targetId);
223
+ if (before && !before.on) {
224
+ if (!on)
225
+ return;
226
+ state.desired[targetId] = false;
227
+ command(targetId, { state: "OFF" }, source);
228
+ }
229
+ else if (before?.control === "manual") {
230
+ state.desired[targetId] = true;
231
+ command(targetId, onOffOnly(targetId) ? { state: "ON" } : {
232
+ state: "ON",
233
+ ...(before.brightnessPct !== undefined ? { brightnessPct: before.brightnessPct } : {}),
234
+ ...(before.colorTempKelvin !== undefined ? { colorTempKelvin: before.colorTempKelvin } : {}),
235
+ transitionSeconds: config.initialTransitionSeconds
236
+ }, source);
237
+ }
238
+ else if (on) {
239
+ // Back in the room's style, over the style's own transition.
240
+ const style = state.style ? styled(targetId, state.style.transitionSeconds) : null;
241
+ if (style)
242
+ command(targetId, style, source);
243
+ }
244
+ else if (before) {
245
+ state.desired[targetId] = true;
246
+ command(targetId, styled(targetId, config.initialTransitionSeconds) ?? { state: "ON" }, source);
247
+ }
248
+ }
177
249
  function told(targetId) {
178
250
  state.untold = state.untold.filter((id) => id !== targetId);
179
251
  }
@@ -272,18 +344,24 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
272
344
  continue;
273
345
  if (event.preserveManual === true && controlOf(targetId) === "manual")
274
346
  continue;
275
- if (resolvedState === "OFF") {
347
+ // An owner holds a light on or off; a newer owner goes on top.
348
+ const beneath = owner ? takeHold(targetId, owner, wasOn) : false;
349
+ if (owner) {
350
+ // Held: set below.
351
+ }
352
+ else if (resolvedState === "OFF") {
276
353
  // An off light has no style to protect: it returns to the room controller.
277
354
  setControl(targetId, null, "off");
278
355
  }
279
- else if (owner) {
280
- setControl(targetId, { state: "overridden", owner }, "owner-intent");
281
- }
282
356
  else if (event.manual === true) {
283
357
  // Only a person's change makes a light manual: since 6.0, an intent's
284
358
  // values alone don't.
285
359
  setControl(targetId, { state: "manual" }, "manual-intent");
286
360
  }
361
+ else if (person && resolvedState === "ON" && heldOff(targetId)) {
362
+ // A person switching on a light an owner holds off: theirs now.
363
+ setControl(targetId, { state: "manual" }, "person-changed");
364
+ }
287
365
  let spec;
288
366
  if (resolvedState === "OFF") {
289
367
  spec = { state: "OFF" };
@@ -314,6 +392,13 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
314
392
  // otherwise just on.
315
393
  spec = (controlOf(targetId) === "in-control" ? styled(targetId, config.initialTransitionSeconds) : null) ?? { state: "ON" };
316
394
  }
395
+ if (owner) {
396
+ (0, room_holds_1.setOwnerSpec)(holdOf(targetId), owner, spec);
397
+ if (beneath) {
398
+ trace("intent", "held", "beneath-owner", { target: targetId, owner, top: state.control[targetId].owner });
399
+ continue;
400
+ }
401
+ }
317
402
  state.desired[targetId] = resolvedState === "ON";
318
403
  told(targetId);
319
404
  sent.push(command(targetId, spec, event.source || "intent"));
@@ -358,6 +443,9 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
358
443
  state.desired[target.id] = nextOn;
359
444
  if (!nextOn)
360
445
  setControl(target.id, null, "observed-off");
446
+ // Switched on while an owner holds it off: a person's now.
447
+ else if (heldOff(target.id))
448
+ setControl(target.id, { state: "manual" }, "person-changed");
361
449
  }
362
450
  }
363
451
  else if (reading?.kind === "echo-changed") {
@@ -394,6 +482,10 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
394
482
  if (reading.setsValues === true && !onOffOnly(target.id)) {
395
483
  setControl(target.id, { state: "manual" }, "external-values");
396
484
  }
485
+ else if (heldOff(target.id)) {
486
+ // Switched on while an owner holds it off: a person's now.
487
+ setControl(target.id, { state: "manual" }, "person-changed");
488
+ }
397
489
  else if (currentStyle() && !onOffOnly(target.id) && controlOf(target.id) === "in-control") {
398
490
  // At most one restyle per light per echo window, whatever comes
399
491
  // back: a bare ON delivered twice (two subscriptions, or a QoS
@@ -455,19 +547,30 @@ function transitionRoom(saved, msg, config, nowValue = new Date()) {
455
547
  }
456
548
  }
457
549
  else if (event.kind === "release") {
458
- // Hand overridden lights back; an owner name releases only that owner's lights.
550
+ // An owner name lets go of that owner's lights; none lets go of every
551
+ // owner's. A light goes to the owner beneath, with what it asked for, or
552
+ // with none left back to what it was before the first.
459
553
  const targets = Array.isArray(event.targets) ? event.targets : config.targets.map((target) => target.id);
460
554
  const owner = typeof event.owner === "string" && event.owner ? event.owner : null;
555
+ const source = event.source || "release";
461
556
  for (const targetId of targets) {
462
- const entry = state.control[targetId];
463
- if (!targetById[targetId] || entry?.state !== "overridden" || (owner && entry.owner !== owner))
557
+ if (!targetById[targetId] || state.control[targetId]?.state !== "overridden")
464
558
  continue;
465
- setControl(targetId, null, "released");
466
- told(targetId);
467
- // Back in the room's style, over the style's own transition.
468
- const style = intendedOn(targetId) && state.style ? styled(targetId, state.style.transitionSeconds) : null;
469
- if (style)
470
- command(targetId, style, event.source || "release");
559
+ const released = (0, room_holds_1.releaseOwner)(holdOf(targetId), owner);
560
+ if (released.kind === "dropped") {
561
+ trace("release", "dropped", "beneath-owner", { target: targetId, owner });
562
+ }
563
+ else if (released.kind === "next") {
564
+ setControl(targetId, { state: "overridden", owner: released.owner }, "released-to-owner");
565
+ told(targetId);
566
+ if (released.spec) {
567
+ state.desired[targetId] = released.spec.state === "ON";
568
+ command(targetId, released.spec, source);
569
+ }
570
+ }
571
+ else if (released.kind === "restore") {
572
+ restoreHeld(targetId, released.before, source);
573
+ }
471
574
  }
472
575
  }
473
576
  else if (event.kind === "intent") {
@@ -0,0 +1,34 @@
1
+ import type { LightCommandMessage } from "./light-contract";
2
+ export type HeldSpec = Pick<LightCommandMessage, "state" | "brightnessPct" | "colorTempKelvin" | "transitionSeconds" | "extra">;
3
+ export interface HeldFrom {
4
+ control: "in-control" | "manual";
5
+ on: boolean;
6
+ brightnessPct?: number;
7
+ colorTempKelvin?: number;
8
+ }
9
+ export interface LightHold {
10
+ owners: Array<{
11
+ owner: string;
12
+ spec: HeldSpec | null;
13
+ }>;
14
+ before: HeldFrom | null;
15
+ }
16
+ export type Released = {
17
+ kind: "none";
18
+ } | {
19
+ kind: "dropped";
20
+ } | {
21
+ kind: "next";
22
+ owner: string;
23
+ spec: HeldSpec | null;
24
+ } | {
25
+ kind: "restore";
26
+ before: HeldFrom | null;
27
+ };
28
+ export declare function newHold(owner: string, before: HeldFrom): LightHold;
29
+ export declare function legacyHold(owner: string): LightHold;
30
+ export declare function savedHolds(saved: unknown, overridden: (target: string) => boolean): Record<string, LightHold>;
31
+ export declare function addOwner(hold: LightHold, owner: string): "top" | "beneath" | "pushed";
32
+ export declare function setOwnerSpec(hold: LightHold, owner: string, spec: HeldSpec): void;
33
+ export declare function heldOff(hold: LightHold | undefined): boolean;
34
+ export declare function releaseOwner(hold: LightHold, owner: string | null): Released;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.newHold = newHold;
4
+ exports.legacyHold = legacyHold;
5
+ exports.savedHolds = savedHolds;
6
+ exports.addOwner = addOwner;
7
+ exports.setOwnerSpec = setOwnerSpec;
8
+ exports.heldOff = heldOff;
9
+ exports.releaseOwner = releaseOwner;
10
+ function newHold(owner, before) {
11
+ return { owners: [{ owner, spec: null }], before };
12
+ }
13
+ // The hold of a light overridden under state saved before 6.1: its one
14
+ // owner, with nothing known of what it was before.
15
+ function legacyHold(owner) {
16
+ return { owners: [{ owner, spec: null }], before: null };
17
+ }
18
+ function savedHolds(saved, overridden) {
19
+ if (!saved || typeof saved !== "object")
20
+ return {};
21
+ return Object.fromEntries(Object.entries(saved)
22
+ .filter(([target, hold]) => overridden(target) && Array.isArray(hold?.owners) && hold.owners.length > 0)
23
+ .map(([target, hold]) => [target, {
24
+ owners: hold.owners.map((entry) => ({ owner: String(entry.owner), spec: entry.spec ? { ...entry.spec } : null })),
25
+ before: hold.before ? { ...hold.before } : null
26
+ }]));
27
+ }
28
+ // An owner asking for a light already held: "top" when it already holds it,
29
+ // "beneath" when it is under a newer owner (its request is kept for when
30
+ // the newer lets go, and the light is left as it is), "pushed" when it is new
31
+ // and now on top.
32
+ function addOwner(hold, owner) {
33
+ const index = hold.owners.findIndex((entry) => entry.owner === owner);
34
+ if (index === hold.owners.length - 1)
35
+ return "top";
36
+ if (index >= 0)
37
+ return "beneath";
38
+ hold.owners.push({ owner, spec: null });
39
+ return "pushed";
40
+ }
41
+ function setOwnerSpec(hold, owner, spec) {
42
+ const entry = hold.owners.find((held) => held.owner === owner);
43
+ if (entry)
44
+ entry.spec = { ...spec, ...(spec.extra ? { extra: { ...spec.extra } } : {}) };
45
+ }
46
+ // Whether the owner on top holds the light off.
47
+ function heldOff(hold) {
48
+ return hold?.owners.at(-1)?.spec?.state === "OFF";
49
+ }
50
+ // Lets go of one owner, or of every owner (null).
51
+ function releaseOwner(hold, owner) {
52
+ const index = owner === null ? 0 : hold.owners.findIndex((entry) => entry.owner === owner);
53
+ if (index < 0)
54
+ return { kind: "none" };
55
+ if (owner !== null && index < hold.owners.length - 1) {
56
+ hold.owners.splice(index, 1);
57
+ return { kind: "dropped" };
58
+ }
59
+ if (owner !== null && hold.owners.length > 1) {
60
+ hold.owners.pop();
61
+ const next = hold.owners.at(-1);
62
+ return { kind: "next", owner: next.owner, spec: next.spec ? { ...next.spec } : null };
63
+ }
64
+ return { kind: "restore", before: hold.before };
65
+ }
66
+ //# sourceMappingURL=room-holds.js.map
@@ -52,6 +52,6 @@
52
52
  <p>While a profile is active, its lights are overridden in the room controller under <b>Owner</b>
53
53
  (default <code>activity</code>), so the room's style (from a circadian lighting policy) leaves the activity's alone. When a new profile
54
54
  no longer includes a light, including a switch to an off profile with no targets, the node emits
55
- <code>{kind: "release", owner, targets}</code> for those lights and the room controller restyles them.
55
+ <code>{kind: "release", owner, targets}</code> for those lights, and the room controller gives each back what it was before the activity took it: one the room was running is restyled.
56
56
  Give each activity-lighting node that feeds the same room controller its own owner.</p>
57
57
  </script>
@@ -4,7 +4,11 @@ import { type RetainedClear } from "../lib/retained-topics";
4
4
  export type Send = (msg: NodeMessage | Array<NodeMessage | NodeMessage[] | null>) => void;
5
5
  export type InputMessage = NodeMessage & Record<string, unknown>;
6
6
  export declare function objectField<T>(msg: InputMessage, key: string): T | undefined;
7
- export declare function onInput(node: Node, handle: (msg: InputMessage, send: Send) => void): void;
7
+ export declare function mqttConnected(msg: InputMessage): boolean;
8
+ export declare function onInput(node: Node, handle: (msg: InputMessage, send: Send) => void, startup?: {
9
+ message: Record<string, unknown>;
10
+ trace: TraceMetadata;
11
+ }): void;
8
12
  export declare function guarded(node: Node, work: () => void): () => void;
9
13
  export declare function runReducer<Saved, Result extends {
10
14
  state: unknown;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.objectField = objectField;
4
+ exports.mqttConnected = mqttConnected;
4
5
  exports.onInput = onInput;
5
6
  exports.guarded = guarded;
6
7
  exports.runReducer = runReducer;
@@ -18,11 +19,43 @@ function objectField(msg, key) {
18
19
  const value = msg[key];
19
20
  return value && typeof value === "object" ? value : undefined;
20
21
  }
22
+ // The status an MQTT out node shows each time its broker connects, as
23
+ // Node-RED's Status node passes it on (Node-RED 5.0.10:
24
+ // nodes/core/network/10-mqtt.js, setStatusConnected; runtime/lib/flows/Flow.js,
25
+ // handleStatus, which adds status.source).
26
+ const MQTT_CONNECTED = "node-red:common.status.connected";
27
+ // A Status node's message: msg.status with the node it came from as
28
+ // status.source.
29
+ function fromStatusNode(msg) {
30
+ const status = objectField(msg, "status");
31
+ return Boolean(status?.source && typeof status.source === "object");
32
+ }
33
+ // Whether a message is a Status node's report that an MQTT out node has
34
+ // connected: until then, the broker drops what it is given to publish.
35
+ function mqttConnected(msg) {
36
+ const status = objectField(msg, "status");
37
+ return fromStatusNode(msg) && status?.text === MQTT_CONNECTED && status.source?.type === "mqtt out";
38
+ }
21
39
  // Handle each input; an error is reported against the message and ends it.
22
- function onInput(node, handle) {
40
+ // With a startup message, a node that announces itself takes a Status
41
+ // node's "MQTT out connected" as that startup message, so it announces again
42
+ // once the broker can take it; any other Status node message is ignored, and
43
+ // traced. Any other message is handled as it is.
44
+ function onInput(node, handle, startup) {
23
45
  node.on("input", (msg, send, done) => {
24
46
  try {
25
- handle(msg, send);
47
+ const input = msg;
48
+ if (startup && mqttConnected(input)) {
49
+ handle(structuredClone(startup.message), send);
50
+ }
51
+ else if (startup && fromStatusNode(input)) {
52
+ const status = input.status;
53
+ (0, bounded_trace_1.appendTrace)(node.context(), startup.trace, [{ event: "input", outcome: "ignored", reason: "status-message",
54
+ details: { text: status.text, source: status.source.type } }]);
55
+ }
56
+ else {
57
+ handle(input, send);
58
+ }
26
59
  done();
27
60
  }
28
61
  catch (error) {
@@ -117,4 +117,9 @@
117
117
  </dl>
118
118
  <p>These go on the third output; wire it to an MQTT out node. The node announces itself once the flows have
119
119
  started, and again at <code>kind: "startup"</code>.</p>
120
+ <h3>When MQTT out connects</h3>
121
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
122
+ "connected", this node takes it as its startup message (<code>msg.avr = {kind: "startup"}</code>) and announces itself again:
123
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
124
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
120
125
  </script>
@@ -158,7 +158,7 @@ const registerAvrController = (RED) => {
158
158
  avr: (0, adapter_1.objectField)(msg, "avr"),
159
159
  payload: msg.payload
160
160
  }, send);
161
- });
161
+ }, { message: { avr: { kind: "startup" } }, trace: { area: controllerConfig.area, component: "avr-controller" } });
162
162
  node.on("close", (_removed, done) => {
163
163
  clearTimeout(retryTimer);
164
164
  clearTimeout(volumeSetTimer);
@@ -137,4 +137,9 @@
137
137
  clears the circadian entities older room controllers in its area published, migrated or not, in the same batch,
138
138
  so Home Assistant can give the new ones the same entity IDs.</dd>
139
139
  </dl>
140
+ <h3>When MQTT out connects</h3>
141
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
142
+ "connected", this node takes it as its startup message (<code>msg.lighting = {kind: "startup"}</code>) and announces itself again:
143
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
144
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
140
145
  </script>
@@ -143,7 +143,7 @@ const registerCircadianPolicy = (RED) => {
143
143
  else {
144
144
  process(lighting ?? { kind: undefined }, send);
145
145
  }
146
- });
146
+ }, { message: { lighting: { kind: "startup" } }, trace: { area: publishing.area, component: "circadian-policy" } });
147
147
  tickTimer = setInterval((0, adapter_1.guarded)(node, () => process({ kind: "tick" }, node.send.bind(node))), policyConfig.intervalSeconds * 1000);
148
148
  // Deleted: rooms stop styling at once rather than when the last style
149
149
  // runs out.
@@ -179,4 +179,9 @@
179
179
  </ul>
180
180
  <p>Battery and charging status, when the cover reports them, are kept as facts and shown in the status; the node
181
181
  never acts on them.</p>
182
+ <h3>When MQTT out connects</h3>
183
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
184
+ "connected", this node takes it as its startup message (<code>msg.cover = {kind: "startup"}</code>) and announces itself again:
185
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
186
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
182
187
  </script>
@@ -132,7 +132,7 @@ const registerCoverController = (RED) => {
132
132
  return;
133
133
  }
134
134
  handleRequest(inbound ? { payload: inbound.request, source: "home-assistant" } : msg, send);
135
- });
135
+ }, { message: { cover: { kind: "startup" } }, trace: trace });
136
136
  function handleRequest(msg, send) {
137
137
  requests += 1;
138
138
  // A cover group's own ID for its request, so it can match the answer.
@@ -58,4 +58,9 @@
58
58
  <ol class="node-ports">
59
59
  <li>MQTT publications.</li>
60
60
  </ol>
61
+ <h3>When MQTT out connects</h3>
62
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
63
+ "connected", this node takes it as its startup message (<code>msg.source = "startup"</code>) and announces itself again:
64
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
65
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
61
66
  </script>
@@ -72,7 +72,7 @@ const registerHouseScheduleMqtt = (RED) => {
72
72
  else if (inbound) {
73
73
  (0, adapter_1.runReducer)(node, trace, (state) => ({ state, traces: inbound.traces }));
74
74
  }
75
- });
75
+ }, { message: { lighting: { kind: "startup" } }, trace: trace });
76
76
  }
77
77
  RED.nodes.registerType("home-house-schedule-mqtt", HomeHouseScheduleMqtt);
78
78
  };
@@ -124,4 +124,9 @@
124
124
  <li>Lighting intents, for the room lighting controller.</li>
125
125
  <li>MQTT publications, when publishing is on.</li>
126
126
  </ol>
127
+ <h3>When MQTT out connects</h3>
128
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
129
+ "connected", this node takes it as its startup message (<code>msg.source = "startup"</code>) and announces itself again:
130
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
131
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
127
132
  </script>
@@ -125,7 +125,7 @@ const registerMotionPolicy = (RED) => {
125
125
  // else is an input as sent, with a pause's owner.
126
126
  const inbound = (0, motion_publishing_1.motionInbound)(msg, publishing);
127
127
  process(inbound?.input ?? { source: String(msg.source ?? ""), payload: msg.payload, owner: typeof msg.owner === "string" ? msg.owner : undefined }, send, inbound);
128
- });
128
+ }, { message: { source: "startup" }, trace: { area: policyConfig.area, component: "motion-policy" } });
129
129
  node.on("close", (_removed, done) => {
130
130
  clearTimeout(offTimer);
131
131
  done();
@@ -84,4 +84,9 @@
84
84
  <li>Occupancy events, for the motion lighting policy.</li>
85
85
  <li>MQTT publications, when publishing is on.</li>
86
86
  </ol>
87
+ <h3>When MQTT out connects</h3>
88
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
89
+ "connected", this node takes it as its startup message (<code>msg.source = "startup"</code>) and announces itself again:
90
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
91
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
87
92
  </script>
@@ -81,7 +81,7 @@ const registerOccupancyFusion = (RED) => {
81
81
  lifecycle.publish(send, (0, occupancy_publishing_1.occupancyStateOutputs)(publishing, output.payload.occupied));
82
82
  }
83
83
  updateStatus(result.status);
84
- });
84
+ }, { message: { source: "startup" }, trace: { area: fusionConfig.area, component: "occupancy-fusion" } });
85
85
  }
86
86
  RED.nodes.registerType("home-occupancy-fusion", HomeOccupancyFusion);
87
87
  };
@@ -225,8 +225,8 @@
225
225
  <h3>Style</h3>
226
226
  <p>Wire a <i>circadian lighting policy</i> into the room to style its lights over the day. The room keeps the
227
227
  latest style it was sent and uses it when a light it controls comes on with no values given (a motion ON, a
228
- wall-switch press), on each new style for lights that are on, after someone else's bare ON, and when an owner
229
- releases a light. A style never switches a light on or off and never reaches a light that an owner holds or a
228
+ wall-switch press), on each new style for lights that are on, after someone else's bare ON, and when the last
229
+ owner releases a light the room was running. A style never switches a light on or off and never reaches a light that an owner holds or a
230
230
  person set. With no style, or once a style has run out, the lights just go on and off. Any node may send a style:
231
231
  <code>msg.lighting = {kind: "style", values: {brightnessPct, colorTempKelvin} | null, transitionSeconds, until}</code>.</p>
232
232
  <p><b>From 5.x:</b> circadian lighting, sleep, the wake and bed times and the house schedule moved to the circadian
@@ -271,8 +271,8 @@
271
271
  <p>Each target has one control state:</p>
272
272
  <dl class="message-properties">
273
273
  <dt>in-control</dt><dd>the room styles the light with the style it is sent. This is the default.</dd>
274
- <dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light. Styles leave it alone until
275
- that owner releases it.</dd>
274
+ <dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light on or off. Styles and
275
+ owner-less intents leave it alone until it is released.</dd>
276
276
  <dt>manual</dt><dd>a person set the light: an intent with <code>manual: true</code> (a wall switch's double
277
277
  press), or someone else's command on the light with values, as its adapter reports it. An intent's values alone don't make a light
278
278
  manual. Switching circadian lighting on returns manual lights to in-control.</dd>
@@ -281,7 +281,15 @@
281
281
  it over), a person (a <code>manual: true</code> intent, <code>person: true</code>, set by the wall-switch policies, someone else's command on the light, or a change
282
282
  seen at the light), or a release. Any other intent, including motion ON or OFF and owner-less values, leaves it
283
283
  alone and is traced as <code>ignored held-by</code>; other targets in the same intent are still handled.
284
- Switching a light off by its owner or a person returns it to in-control.</p>
284
+ A person switching a held light off returns it to in-control; a person switching on a light an owner holds off
285
+ makes it manual. Either way it leaves every owner, and their later releases leave it alone.</p>
286
+ <p>Owners stack, per light. The first owner to take a light records what it was: its control state, whether it was
287
+ on, and the values it last reported. A newer owner goes on top and sets the light; the owner beneath keeps its
288
+ own request, and sending again updates it without changing the light. Releasing the owner on top hands the light
289
+ to the owner beneath, with what that owner last asked for; releasing an owner beneath just drops it. When the
290
+ last owner lets go, the light goes back to what was recorded: a light the room was running is the room's again,
291
+ on or off as it was, in the room's style as it is now; a light that was off goes off; a light a person had set
292
+ gets its values back and stays manual.</p>
285
293
  <p>The control states are kept in the node's context. When the node starts with nothing saved (its first deploy,
286
294
  or a redeploy or restart without a context store, see the README), it can't know which lights were held or set
287
295
  by a person, so it leaves every light as it is: no style restyles a light until an intent or release names it,
@@ -297,11 +305,12 @@
297
305
  <dt>lighting.kind = "style"</dt>
298
306
  <dd>how lights should look, usually from a circadian lighting policy (see Style).</dd>
299
307
  <dt>lighting.owner <span class="property-type">string</span></dt>
300
- <dd>on an <code>intent</code> that switches targets on, marks them overridden by this owner. With
308
+ <dd>on an <code>intent</code>, holds its targets on or off for this owner (overridden), on top of any other
309
+ owner's. With
301
310
  <code>preserveManual: true</code>, manual lights are skipped.</dd>
302
311
  <dt>lighting.kind = "release"</dt>
303
- <dd>returns overridden <code>targets</code> (default: all) to in-control. With <code>owner</code>, only lights
304
- held by that owner are released. Released lights that are on are restyled over the style's transition.</dd>
312
+ <dd>lets go of overridden <code>targets</code> (default: all) for <code>owner</code>, or for every owner without
313
+ one. A light goes to the owner beneath, or with none left back to what it was before the first.</dd>
305
314
  </dl>
306
315
  <h3>Outputs</h3>
307
316
  <ol class="node-ports">
@@ -315,4 +324,9 @@
315
324
  <li>Each light's reading, <code>msg.light</code>, passed on with <code>control</code> and <code>manual</code>, for
316
325
  activity lighting.</li>
317
326
  </ol>
327
+ <h3>When MQTT out connects</h3>
328
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
329
+ "connected", this node takes it as its startup message (<code>msg.lighting = {kind: "startup"}</code>) and announces itself again:
330
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
331
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
318
332
  </script>
@@ -145,7 +145,7 @@ const registerRoomController = (RED) => {
145
145
  payload: msg.payload,
146
146
  retain: msg.retain === true
147
147
  }, send);
148
- });
148
+ }, { message: { lighting: { kind: "startup" } }, trace: { area: controllerConfig.area, component: "room-controller" } });
149
149
  }
150
150
  RED.nodes.registerType("home-room-lighting-controller", HomeRoomLightingController);
151
151
  };
@@ -79,4 +79,9 @@
79
79
  No node of this package reads that state yet.</li>
80
80
  <li>Readings are timed when they arrive.</li>
81
81
  </ul>
82
+ <h3>When MQTT out connects</h3>
83
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
84
+ "connected", this node takes it as its startup message (<code>msg.shellySwitch = {kind: "startup"}</code>) and reads the device's configuration again:
85
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
86
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
82
87
  </script>
@@ -36,7 +36,7 @@ const registerShellySwitch = (RED) => {
36
36
  node.status({ fill: "grey", shape: "ring", text: "reading the device's configuration" });
37
37
  // Once the flows have started, so the MQTT out node is there to send through.
38
38
  (0, adapter_1.whenFlowsStarted)(RED, node, () => process({ shellySwitch: { kind: "startup" } }, node.send.bind(node)));
39
- (0, adapter_1.onInput)(node, (msg, send) => process(msg, send));
39
+ (0, adapter_1.onInput)(node, (msg, send) => process(msg, send), { message: { shellySwitch: { kind: "startup" } }, trace: trace });
40
40
  node.on("close", (_removed, done) => {
41
41
  clearTimeout(timer);
42
42
  done();
@@ -95,4 +95,9 @@
95
95
  <p>The <b>Area</b> names the discovery entities and the default base topic <code>home/&lt;area&gt;/theatre</code>,
96
96
  so it is needed when discovery is on or the base topic is empty. With discovery off and a base topic set, it is
97
97
  optional.</p>
98
+ <h3>When MQTT out connects</h3>
99
+ <p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
100
+ "connected", this node takes it as its startup message (<code>msg.theatreStateContract = {kind: "startup"}</code>) and announces itself again:
101
+ Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
102
+ start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
98
103
  </script>
@@ -80,7 +80,7 @@ const registerTheatreStateContract = (RED) => {
80
80
  theatre: (0, adapter_1.objectField)(msg, "theatre"),
81
81
  theatreStateContract: (0, adapter_1.objectField)(msg, "theatreStateContract")
82
82
  }, send);
83
- });
83
+ }, { message: { theatreStateContract: { kind: "startup" } }, trace: { area: controllerConfig.area, component: "theatre-state-contract" } });
84
84
  // Available again as soon as this node runs, as after a redeploy of it
85
85
  // alone, rather than waiting for the flow's startup message.
86
86
  }
@@ -61,6 +61,10 @@
61
61
  from what it sent and its members' reports, so a group's report follows a command at once. A group has no
62
62
  availability and can't be asked to report, so at the room's startup the node sends nothing: the room waits for
63
63
  Zigbee2MQTT's next state for the group. (Passing on an old state could settle a command still on its way.)</p>
64
+ <p>Switch on the group's <b>retain</b> in Zigbee2MQTT: <code>retain: true</code> under the group in Zigbee2MQTT's
65
+ <code>configuration.yaml</code> (it is off by default). Zigbee2MQTT doesn't retain a group's state by default, so after a restart the
66
+ room has no reading for the group until it changes, and an activity that holds it waits on it. With retain, the broker
67
+ gives this node the group's last state as soon as its MQTT in node subscribes.</p>
64
68
  <h3>Settings</h3>
65
69
  <dl class="message-properties">
66
70
  <dt>Target</dt><dd>The light's id in the room controller's Targets JSON.</dd>
@@ -18,8 +18,9 @@ const registerZ2mLight = (RED) => {
18
18
  (0, adapter_1.onInput)(node, (msg, send) => {
19
19
  const result = (0, adapter_1.runReducer)(node, trace, (saved, now) => {
20
20
  const decided = (0, z2m_light_adapter_1.transitionZ2mLight)(saved, msg, light, now);
21
- // Another light's command: nothing to keep or trace.
22
- return decided.ignored ? { state: saved ?? decided.state, traces: [] } : decided;
21
+ // Another light's command: nothing to keep or trace, and the result
22
+ // still says it was ignored.
23
+ return decided.ignored ? { ...decided, state: saved ?? decided.state, traces: [] } : decided;
23
24
  });
24
25
  if (result.ignored)
25
26
  return;
@@ -3,27 +3,16 @@
3
3
  "id": "example-cover-control-cover-control-example",
4
4
  "type": "comment",
5
5
  "name": "Cover control example",
6
- "info": "A position cover (blind, shutter or curtain motor) owned by the cover controller. Requests go in as \"open\", \"close\", \"stop\", a position from 0 to 100, or a preset name; an automatic target sets respectManual so a person's move holds. The Zigbee2MQTT cover adapter maps to and from a Zigbee2MQTT cover: set its friendly name, feed it from MQTT in nodes on the cover's topic and its availability topic, and wire its first output to an MQTT out node. A button can stop the cover if it is moving and open it otherwise, and the cover's availability report keeps requests from going to an offline device. Output 3 says whether the cover is moving, for other policies to react to. Here it pauses motion lighting while the cover moves, through the motion policy's pause input, which never touches the user's own enable.",
6
+ "info": "A position cover (blind, shutter or curtain motor) owned by the cover controller. Requests go in as \"open\", \"close\", \"stop\", a position from 0 to 100, or a preset name; an automatic target sets respectManual so a person's move holds. The Zigbee2MQTT cover adapter maps to and from a Zigbee2MQTT cover: set its friendly name, feed it from MQTT in nodes on the cover's topic and its availability topic, and wire its first output to an MQTT out node. A button can stop the cover if it is moving and open it otherwise, and the cover's availability report keeps requests from going to an offline device. Output 3 says whether the cover is moving, for other policies to react to. Here it pauses motion lighting while the cover moves, through the motion policy's pause input, which never touches the user's own enable.\n\nThe \"MQTT out connected\" status node sends the cover controller its startup message each time an MQTT out node connects to the broker, so what it announces reaches it: the broker drops anything sent before it connects. It watches every node on this flow, and the nodes act only on an MQTT out node's connected status; you can scope it to your MQTT out node instead.",
7
7
  "x": 170,
8
8
  "y": 40,
9
9
  "wires": []
10
10
  },
11
11
  {
12
- "id": "example-cover-control-startup",
13
- "type": "inject",
14
- "name": "startup",
15
- "props": [
16
- {
17
- "p": "cover",
18
- "v": "{\"kind\":\"startup\"}",
19
- "vt": "json"
20
- }
21
- ],
22
- "repeat": "",
23
- "crontab": "",
24
- "once": true,
25
- "onceDelay": 3,
26
- "topic": "",
12
+ "id": "example-cover-control-mqtt-connected",
13
+ "type": "status",
14
+ "name": "MQTT out connected",
15
+ "scope": null,
27
16
  "x": 130,
28
17
  "y": 100,
29
18
  "wires": [
@@ -3,7 +3,7 @@
3
3
  "id": "example-home-theatre-activity-home-theatre-activity-example",
4
4
  "type": "comment",
5
5
  "name": "Home theatre activity example",
6
- "info": "The state contract turns a request on home/<area>/theatre/request into an activity intent. The activity controller plans each target and sends msg.theatreCommand; the switch routes each command by its target, and a change node moves it onto that controller's input. Every controller reports msg.theatre target state on output 2, wired straight back to the activity controller, which publishes a complete snapshot through the contract.\n\nName the area on the state contract before deploying: it names the MQTT topics and Home Assistant entities, and until it is set the contract shows \"invalid configuration\". Put the same area in the \"request tv activity\" inject's topic. Set the display controller's device hosts and TV pre-shared key too; until then it shows \"invalid configuration\" and the activity waits for it. Wire the controllers' output 1 to your device transports and activity lighting to your room lighting controller. Activity lighting holds the room's lights through a room lighting controller, which reaches its light through a zigbee2mqtt light node and passes each light's reading back to activity lighting (its third output), so the lights confirm. Set the light's friendly name, wire the debug's place to MQTT out, and an MQTT in node on the light's topics (zigbee2mqtt/<your light>/#) into the light node.",
6
+ "info": "The state contract turns a request on home/<area>/theatre/request into an activity intent. The activity controller plans each target and sends msg.theatreCommand; the switch routes each command by its target, and a change node moves it onto that controller's input. Every controller reports msg.theatre target state on output 2, wired straight back to the activity controller, which publishes a complete snapshot through the contract.\n\nName the area on the state contract before deploying: it names the MQTT topics and Home Assistant entities, and until it is set the contract shows \"invalid configuration\". Put the same area in the \"request tv activity\" inject's topic. Set the display controller's device hosts and TV pre-shared key too; until then it shows \"invalid configuration\" and the activity waits for it. Wire the controllers' output 1 to your device transports and activity lighting to your room lighting controller. Activity lighting holds the room's lights through a room lighting controller, which reaches its light through a zigbee2mqtt light node and passes each light's reading back to activity lighting (its third output), so the lights confirm. Set the light's friendly name, wire the debug's place to MQTT out, and an MQTT in node on the light's topics (zigbee2mqtt/<your light>/#) into the light node.\n\nThe \"MQTT out connected\" status node sends the state contract its startup message each time an MQTT out node connects to the broker, so what it announces reaches it: the broker drops anything sent before it connects. It watches every node on this flow, and the nodes act only on an MQTT out node's connected status; you can scope it to your MQTT out node instead.",
7
7
  "x": 190,
8
8
  "y": 40,
9
9
  "wires": []
@@ -38,21 +38,10 @@
38
38
  ]
39
39
  },
40
40
  {
41
- "id": "example-home-theatre-activity-contract-startup",
42
- "type": "inject",
43
- "name": "contract startup",
44
- "props": [
45
- {
46
- "p": "theatreStateContract",
47
- "v": "{\"kind\":\"startup\"}",
48
- "vt": "json"
49
- }
50
- ],
51
- "repeat": "",
52
- "crontab": "",
53
- "once": true,
54
- "onceDelay": 3,
55
- "topic": "",
41
+ "id": "example-home-theatre-activity-contract-mqtt-connected",
42
+ "type": "status",
43
+ "name": "MQTT out connected",
44
+ "scope": null,
56
45
  "x": 170,
57
46
  "y": 140,
58
47
  "wires": [
@@ -3,7 +3,7 @@
3
3
  "id": "example-room-lighting-room-lighting-example",
4
4
  "type": "comment",
5
5
  "name": "Room lighting example",
6
- "info": "Motion and illuminance feed occupancy fusion and the motion policy; a wall switch feeds the switch policy. Both send lighting intents to the room controller, which owns the light's commands. The circadian lighting policy sends the room how its lights should look over the day; the room uses it for lights nobody has set otherwise.\n\nReplace the inject nodes with your sensors. The room reaches its light through the zigbee2mqtt light node: set its friendly name, wire the room's first output and the light node's first output to MQTT out, and an MQTT in node on the light's topics (zigbee2mqtt/<your light>/#) into the light node. Set the circadian policy's wake and bed times (Node-RED host time) before deploying. Give the room controller an area to publish each light's control state and its Home Assistant discovery, and the circadian policy one to publish its circadian and sleep switches; without one they still control and style the lights.",
6
+ "info": "Motion and illuminance feed occupancy fusion and the motion policy; a wall switch feeds the switch policy. Both send lighting intents to the room controller, which owns the light's commands. The circadian lighting policy sends the room how its lights should look over the day; the room uses it for lights nobody has set otherwise.\n\nReplace the inject nodes with your sensors. The room reaches its light through the zigbee2mqtt light node: set its friendly name, wire the room's first output and the light node's first output to MQTT out, and an MQTT in node on the light's topics (zigbee2mqtt/<your light>/#) into the light node. Set the circadian policy's wake and bed times (Node-RED host time) before deploying. Give the room controller an area to publish each light's control state and its Home Assistant discovery, and the circadian policy one to publish its circadian and sleep switches; without one they still control and style the lights.\n\nThe \"MQTT out connected\" status node sends the room controller and the circadian policy its startup message each time an MQTT out node connects to the broker, so what they announce reaches it: the broker drops anything sent before it connects. It watches every node on this flow, and the nodes act only on an MQTT out node's connected status; you can scope it to your MQTT out node instead.",
7
7
  "x": 170,
8
8
  "y": 40,
9
9
  "wires": []
@@ -96,21 +96,10 @@
96
96
  ]
97
97
  },
98
98
  {
99
- "id": "example-room-lighting-room-startup",
100
- "type": "inject",
101
- "name": "startup",
102
- "props": [
103
- {
104
- "p": "lighting",
105
- "v": "{\"kind\":\"startup\"}",
106
- "vt": "json"
107
- }
108
- ],
109
- "repeat": "",
110
- "crontab": "",
111
- "once": true,
112
- "onceDelay": 3,
113
- "topic": "",
99
+ "id": "example-room-lighting-room-mqtt-connected",
100
+ "type": "status",
101
+ "name": "MQTT out connected",
102
+ "scope": null,
114
103
  "x": 150,
115
104
  "y": 280,
116
105
  "wires": [
@@ -3,27 +3,16 @@
3
3
  "id": "example-shelly-cover-comment",
4
4
  "type": "comment",
5
5
  "name": "Shelly cover example",
6
- "info": "A Shelly Gen2 device in cover mode, owned by the cover controller, with no function nodes. In your flow, replace the injects marked 'from the device' with an MQTT in node subscribed to <prefix>/# (output: auto-detect), and the debug node with an MQTT out node, both on your broker. Set the adapter's MQTT topic prefix to your device's (its device ID unless you set one). The controller's device commands go to the adapter, which sends them to the device as its MQTT control commands; the device's status, change notifications and online state come back through the adapter as the controller's readings.",
6
+ "info": "A Shelly Gen2 device in cover mode, owned by the cover controller, with no function nodes. In your flow, replace the injects marked 'from the device' with an MQTT in node subscribed to <prefix>/# (output: auto-detect), and the debug node with an MQTT out node, both on your broker. Set the adapter's MQTT topic prefix to your device's (its device ID unless you set one). The controller's device commands go to the adapter, which sends them to the device as its MQTT control commands; the device's status, change notifications and online state come back through the adapter as the controller's readings.\n\nThe \"MQTT out connected\" status node sends the cover controller its startup message each time an MQTT out node connects to the broker, so what it announces reaches it: the broker drops anything sent before it connects. It watches every node on this flow, and the nodes act only on an MQTT out node's connected status; you can scope it to your MQTT out node instead.",
7
7
  "x": 150,
8
8
  "y": 40,
9
9
  "wires": []
10
10
  },
11
11
  {
12
- "id": "example-shelly-cover-startup",
13
- "type": "inject",
14
- "name": "startup",
15
- "props": [
16
- {
17
- "p": "cover",
18
- "v": "{\"kind\":\"startup\"}",
19
- "vt": "json"
20
- }
21
- ],
22
- "repeat": "",
23
- "crontab": "",
24
- "once": true,
25
- "onceDelay": 3,
26
- "topic": "",
12
+ "id": "example-shelly-cover-mqtt-connected",
13
+ "type": "status",
14
+ "name": "MQTT out connected",
15
+ "scope": null,
27
16
  "x": 130,
28
17
  "y": 100,
29
18
  "wires": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantics/node-red-home-automation",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "Deterministic home automation components for Node-RED",
5
5
  "keywords": [
6
6
  "node-red",