@avantics/node-red-home-automation 4.0.0 → 4.0.2

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
@@ -134,7 +134,13 @@ One cover controller owns one position cover: a blind, shutter or curtain motor
134
134
  that takes and reports a position from 0 (closed) to 100 (open). Send it
135
135
  `"open"`, `"close"`, `"stop"`, a position, or the name of a preset such as
136
136
  `partial`. It confirms a move from what the cover reports, retries a bounded
137
- number of times, and leaves a cover a person moved where they put it. An
137
+ number of times, and leaves a cover a person moved where they put it. A move is
138
+ confirmed only once the cover has stopped at the target, from a `stopped`
139
+ motion report or the same position for the settle time (with or without
140
+ another report), so a transport that echoes the requested position at once
141
+ doesn't end the move early. Set the settle time to at least how often the
142
+ motor reports while it travels: otherwise an echo can be confirmed before the
143
+ first travel report arrives. An
138
144
  automatic target, such as a position computed from the weather, sets
139
145
  `msg.respectManual = true` so it waits while a person's move holds; a target
140
146
  the cover is already at is confirmed without a command. A button can send
@@ -194,11 +200,31 @@ also attaches the package tarball and its SHA-256 checksum. Install a downloaded
194
200
  tarball through **Manage palette → Install → Upload module**, or with:
195
201
 
196
202
  ```sh
197
- npm install /path/to/avantics-node-red-home-automation-4.0.0.tgz
203
+ npm install /path/to/avantics-node-red-home-automation-4.0.2.tgz
198
204
  ```
199
205
 
200
206
  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.
201
207
 
208
+ ### 4.0.2
209
+
210
+ Fixes the display controller switching the TV off before the projector was
211
+ ready: with a source playing, there was sound but no picture while the screen
212
+ opened and the projector warmed up. Projector mode now starts the projector and
213
+ waits for its warm-up, opens the screen, then puts the TV in standby, so the
214
+ picture stays up and the TV stays on if the projector fails to start. A request
215
+ made while the projector is warming up or cooling down now waits for that to
216
+ finish, so the lamp is no longer left on or toggled mid-warm-up.
217
+
218
+ ### 4.0.1
219
+
220
+ Fixes the cover controller ending a move too early when a transport echoes the
221
+ requested position as soon as the command is sent, before the motor moves: the
222
+ cover showed as stopped while it was still travelling, and the travel after it
223
+ was taken for a person's move. A move now confirms only once the cover has
224
+ stopped at the target, from a `stopped` motion report or the same position for
225
+ the settle time. Set the settle time to at least how often the motor reports
226
+ while it travels (see Covers).
227
+
202
228
  ### 4.0.0
203
229
 
204
230
  Adds cover control, a house schedule, and Home Assistant entities for every
@@ -291,9 +291,20 @@ function transitionCover(saved, msg, suppliedConfig = {}, nowValue = new Date())
291
291
  || (pending.startPosition !== null && Math.abs(position - pending.startPosition) > config.positionTolerance)) {
292
292
  pending.moved = true;
293
293
  }
294
- if (within && !moving) {
294
+ // A move confirms only once the cover has stopped at the target: some
295
+ // transports echo the requested position as soon as the command goes,
296
+ // before the motor moves, so a report at the target is not enough. A
297
+ // reliable "stopped", or the same position held for settleMs, is.
298
+ // Re-reading after a restart or an outage keeps confirming at once.
299
+ if (within && !moving && (pending.operation !== "set_position" || settled)) {
295
300
  ready(target);
296
301
  }
302
+ else if (within && !moving) {
303
+ // Settled once it holds here for settleMs, with or without another
304
+ // report: the tick then confirms it (see settledAtTarget).
305
+ pending.nextAt = Math.min(pending.nextAt, (pending.stableSince ?? observedAt) + config.settleMs);
306
+ trace("observation", "accepted", "awaiting-settle", { position, motion });
307
+ }
297
308
  else if (pending.verifying && !moving) {
298
309
  latchManual("moved-while-offline", target, position);
299
310
  }
@@ -328,6 +339,20 @@ function transitionCover(saved, msg, suppliedConfig = {}, nowValue = new Date())
328
339
  ready(state.desired.position);
329
340
  }
330
341
  }
342
+ // A set_position move whose last report is at the target, not moving, and
343
+ // has held there for settleMs. Travel reports after an echo reset the
344
+ // hold, so an echo alone settles only if nothing follows it for settleMs.
345
+ function settledAtTarget() {
346
+ const pending = state.pending;
347
+ const observed = state.observed;
348
+ if (!pending || pending.operation !== "set_position" || !observed || state.desired?.position === null || state.desired?.position === undefined)
349
+ return false;
350
+ if (observed.motion === "opening" || observed.motion === "closing")
351
+ return false;
352
+ if (pending.stableSince === null || pending.stablePosition !== observed.position)
353
+ return false;
354
+ return Math.abs(observed.position - state.desired.position) <= config.positionTolerance && nowMs - pending.stableSince >= config.settleMs;
355
+ }
331
356
  function latchManual(reason, expected, observed) {
332
357
  state.pending = null;
333
358
  state.classification = "manual_override";
@@ -356,6 +381,12 @@ function transitionCover(saved, msg, suppliedConfig = {}, nowValue = new Date())
356
381
  if (!state.desired || event.generation !== state.generation || !state.pending) {
357
382
  trace("tick", "ignored", "stale-generation");
358
383
  }
384
+ else if (settledAtTarget()) {
385
+ // At the target for settleMs, with no newer report: a cover that
386
+ // reports once on arrival, and doesn't answer polls, is done too.
387
+ trace("tick", "settled", "held-at-target", { position: state.observed.position });
388
+ ready(state.desired.position);
389
+ }
359
390
  else if (nowMs >= state.pending.deadlineAt) {
360
391
  retryOrFail(state.pending.operation === "observe" ? "confirmation-timeout" : "travel-timeout");
361
392
  }
@@ -290,17 +290,20 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
290
290
  return issueScreen(0);
291
291
  return markReady();
292
292
  }
293
+ // Make before break, as TV mode does: the projector warms up and the
294
+ // screen opens while the TV still shows the picture, which goes to
295
+ // standby last. A projector that fails to start leaves the TV on.
293
296
  if (mode === "projector") {
294
- if (state.observed.tv?.power !== "standby")
295
- return issueTv("standby");
296
- if (!screenAtPosition(state.observed.screen, config.screenOpenPosition, config.screenTolerance)) {
297
- return issueScreen(config.screenOpenPosition);
298
- }
299
297
  if (state.observed.projector?.power !== "on") {
300
298
  if (state.observed.projector?.power === "standby")
301
299
  return issueProjectorStart();
302
300
  return awaitProjectorPower();
303
301
  }
302
+ if (!screenAtPosition(state.observed.screen, config.screenOpenPosition, config.screenTolerance)) {
303
+ return issueScreen(config.screenOpenPosition);
304
+ }
305
+ if (state.observed.tv?.power !== "standby")
306
+ return issueTv("standby");
304
307
  return markReady();
305
308
  }
306
309
  if (state.observed.tv?.power !== "standby")
@@ -421,6 +424,23 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
421
424
  return;
422
425
  }
423
426
  if (now.getTime() >= pending.deadlineAt) {
427
+ // A projector step kept from an older request (see the intent) that
428
+ // never confirmed isn't the newer request's failure: its goal may
429
+ // already be met. Drop it, read the projector afresh, and let the
430
+ // newer request act on what it reports; its own steps fail it, under
431
+ // its own generation, if the projector really is stuck.
432
+ if (state.desired && pending.command.generation !== state.desired.generation) {
433
+ state.pending = null;
434
+ state.seen.projector = false;
435
+ state.querying.projector = true;
436
+ commands.push(queryFor(state, "projector"));
437
+ trace("transition", "dropped", "superseded-operation-unconfirmed", {
438
+ device: pending.device,
439
+ operation: pending.operation,
440
+ generation: pending.command.generation
441
+ });
442
+ return;
443
+ }
424
444
  if (pending.retryable && pending.attempt < config.maxAttempts) {
425
445
  retry(pending, null);
426
446
  return;
@@ -489,7 +509,11 @@ function transitionDisplay(saved, msg, suppliedConfig = {}, now = new Date()) {
489
509
  state.lastAttempt = 0;
490
510
  state.fallbackUsed = false;
491
511
  state.blockedGeneration = null;
492
- state.pending = null;
512
+ // As at startup, a projector power operation in flight (a warm-up, a
513
+ // shutdown or a cool-down) carries on under the new request: a toggle
514
+ // now could switch a warming lamp off or a cooling one back on. The
515
+ // new request's steps follow once it settles.
516
+ state.pending = state.pending && !state.pending.retryable ? state.pending : null;
493
517
  state.seen = { tv: false, screen: false, projector: false };
494
518
  state.querying = { tv: false, screen: false, projector: false };
495
519
  beginDiscovery();
@@ -108,7 +108,11 @@
108
108
  <script type="text/html" data-help-name="home-cover-controller">
109
109
  <p>Owns one position cover: a blind, shutter or curtain motor that takes and reports a position from 0 (closed) to
110
110
  100 (open). It sends a move, confirms it from what the cover reports, retries a bounded number of times, and
111
- leaves a cover a person moved where they put it.</p>
111
+ leaves a cover a person moved where they put it. A move is confirmed only once the cover has stopped at the
112
+ target: a <code>stopped</code> motion report, or the same position for the <b>Settle time</b>, with or without
113
+ another report. A transport that echoes the requested position as soon as the command goes doesn't end the move,
114
+ or make the travel after it look like a person's, as long as the <b>Settle time</b> is at least how often the
115
+ motor reports while it travels.</p>
112
116
  <h3>Inputs</h3>
113
117
  <dl class="message-properties">
114
118
  <dt>payload</dt><dd><code>"open"</code>, <code>"close"</code> or <code>"stop"</code>; a position from 0 to 100;
@@ -59,6 +59,11 @@
59
59
 
60
60
  <script type="text/html" data-help-name="home-display-mode-controller">
61
61
  <p>Owns Bravia power, projector lamp power and projector-screen position for <code>off</code>, <code>tv</code> and <code>projector</code> modes.</p>
62
+ <p>Switching between the TV and the projector is make before break, so a source that is already playing keeps a
63
+ picture: for the projector, the lamp starts and warms up, then the screen opens, and the TV goes to standby last;
64
+ for the TV, it comes on before the projector shuts down and the screen closes. If the projector fails to start, the
65
+ TV is left on. A projector warming up or cooling down finishes before a newer request changes it; if it doesn't finish in time, the
66
+ newer request carries on from what the projector then reports.</p>
62
67
  <p>Send <code>msg.display = {kind: "intent", requestId, generation, mode}</code>. Send <code>kind: "startup"</code> after deployment to query every owned device and reconcile persisted intent. Send <code>kind: "refresh"</code> to re-confirm a settled display from fresh readings.</p>
63
68
  <p>The Bravia and both Shelly devices use direct LAN APIs. Output 1 carries the projector power toggle (<code>msg.payload = "power"</code> with <code>msg.display_command</code>) for your infrared transport, commanded directly rather than through Home Assistant. Enable “Projector power is fallback” to include its use in activity metrics. Output 2 emits observed state plus ready, manual-override, failed, rejected and superseded results, and <code>msg.theatre</code> target state for the theatre activity controller: wire it straight back to that controller.</p>
64
69
  <p>An unsolicited physical-state change after readiness latches manual ownership. The controller observes and reports it without issuing corrective commands; a newer activity intent resumes automation.</p>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantics/node-red-home-automation",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Deterministic home automation components for Node-RED",
5
5
  "keywords": [
6
6
  "node-red",