@avantics/node-red-home-automation 6.2.0 → 6.3.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.
Files changed (64) hide show
  1. package/README.md +60 -8
  2. package/dist/lib/activity-lighting-controller.d.ts +1 -0
  3. package/dist/lib/activity-lighting-controller.js +37 -10
  4. package/dist/lib/avr-controller.d.ts +3 -0
  5. package/dist/lib/avr-controller.js +24 -2
  6. package/dist/lib/backlighting-controller.d.ts +5 -2
  7. package/dist/lib/backlighting-controller.js +27 -2
  8. package/dist/lib/display-mode-controller.d.ts +3 -0
  9. package/dist/lib/display-mode-controller.js +43 -16
  10. package/dist/lib/esphome-sensor.d.ts +73 -0
  11. package/dist/lib/esphome-sensor.js +261 -0
  12. package/dist/lib/occupancy-fusion.d.ts +1 -0
  13. package/dist/lib/occupancy-fusion.js +15 -2
  14. package/dist/lib/scene.d.ts +9 -1
  15. package/dist/lib/scene.js +61 -8
  16. package/dist/lib/source-capability-controller.d.ts +4 -1
  17. package/dist/lib/source-capability-controller.js +49 -2
  18. package/dist/lib/target-observation.d.ts +14 -0
  19. package/dist/lib/target-observation.js +22 -0
  20. package/dist/lib/theatre-activity-controller.d.ts +5 -0
  21. package/dist/lib/theatre-activity-controller.js +87 -12
  22. package/dist/lib/theatre-state.d.ts +2 -0
  23. package/dist/lib/theatre-state.js +10 -1
  24. package/dist/lib/wled.d.ts +48 -0
  25. package/dist/lib/wled.js +105 -0
  26. package/dist/lib/z2m-power.d.ts +38 -0
  27. package/dist/lib/z2m-power.js +83 -0
  28. package/dist/lib/z2m-sensor.d.ts +37 -0
  29. package/dist/lib/z2m-sensor.js +88 -0
  30. package/dist/nodes/apollo-r-pro-1.d.ts +2 -0
  31. package/dist/nodes/apollo-r-pro-1.html +80 -0
  32. package/dist/nodes/apollo-r-pro-1.js +4 -0
  33. package/dist/nodes/avr-controller.js +1 -1
  34. package/dist/nodes/backlighting-controller.js +3 -2
  35. package/dist/nodes/device-side.d.ts +1 -0
  36. package/dist/nodes/device-side.js +7 -3
  37. package/dist/nodes/display-mode-controller.js +11 -2
  38. package/dist/nodes/esphome-sensor.d.ts +2 -0
  39. package/dist/nodes/esphome-sensor.js +77 -0
  40. package/dist/nodes/everything-presence-one.d.ts +2 -0
  41. package/dist/nodes/everything-presence-one.html +78 -0
  42. package/dist/nodes/everything-presence-one.js +4 -0
  43. package/dist/nodes/occupancy-fusion.html +3 -0
  44. package/dist/nodes/occupancy-fusion.js +2 -1
  45. package/dist/nodes/scene.html +24 -3
  46. package/dist/nodes/scene.js +9 -2
  47. package/dist/nodes/shelly-cover.html +1 -0
  48. package/dist/nodes/shelly-switch.html +1 -0
  49. package/dist/nodes/source-capability-controller.js +3 -2
  50. package/dist/nodes/theatre-activity-controller.html +4 -2
  51. package/dist/nodes/wled.d.ts +3 -0
  52. package/dist/nodes/wled.html +56 -0
  53. package/dist/nodes/wled.js +53 -0
  54. package/dist/nodes/z2m-cover.html +1 -0
  55. package/dist/nodes/z2m-light.html +3 -1
  56. package/dist/nodes/z2m-light.js +17 -0
  57. package/dist/nodes/z2m-power.d.ts +3 -0
  58. package/dist/nodes/z2m-power.html +58 -0
  59. package/dist/nodes/z2m-power.js +53 -0
  60. package/dist/nodes/z2m-sensor.d.ts +3 -0
  61. package/dist/nodes/z2m-sensor.html +69 -0
  62. package/dist/nodes/z2m-sensor.js +62 -0
  63. package/examples/Scene.json +8 -56
  64. package/package.json +7 -2
@@ -0,0 +1,80 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-apollo-r-pro-1", {
3
+ category: "home automation",
4
+ color: "#e2d96e",
5
+ defaults: {
6
+ name: {value: ""},
7
+ // Node-RED's MQTT broker node, through which it subscribes to the
8
+ // device's topics. The editor offers the first broker when the dialog is
9
+ // opened and saved.
10
+ broker: {value: "", type: "mqtt-broker", required: true},
11
+ // No default: it names the user's own device.
12
+ device: {value: "", required: true, validate: function (v) {
13
+ var device = String(v || "").trim().replace(/^\/+|\/+$/g, "");
14
+ return device !== "" && !/[+#]/.test(device);
15
+ }},
16
+ // Where the device's discovery is: ESPHome's default. A node saved
17
+ // before this setting loads without it (the editor applies no defaults
18
+ // to deployed flows); missing or empty means homeassistant, as the
19
+ // runtime reads it.
20
+ discoveryPrefix: {value: "homeassistant", validate: function (v) {
21
+ return !/[+#]/.test(String(v === undefined || v === null ? "" : v));
22
+ }}
23
+ },
24
+ inputs: 1,
25
+ outputs: 2,
26
+ outputLabels: ["motion and presence, to occupancy fusion", "light level, to the motion lighting policy"],
27
+ icon: "font-awesome/fa-eye",
28
+ label: function () { return this.name || this.device || "apollo r pro-1"; },
29
+ paletteLabel: "apollo r pro-1"
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="home-apollo-r-pro-1">
34
+ <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
35
+ <div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
36
+ <div class="form-row"><label for="node-input-device">Device</label><input type="text" id="node-input-device" placeholder="its ESPHome name"></div>
37
+ <div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
38
+ <div class="form-tips">It subscribes to the device's entities and status itself: no MQTT in, change or function nodes.</div>
39
+ </script>
40
+
41
+ <script type="text/html" data-help-name="home-apollo-r-pro-1">
42
+ <p>Connects an <b>Apollo R PRO-1</b> (Apollo Automation's ESPHome presence sensor) to a room: its two radars and its
43
+ light sensor become the messages <b>home occupancy fusion</b> and the <b>home motion lighting policy</b> take, over
44
+ ESPHome's own MQTT messages: no function or change nodes, and never Home Assistant.</p>
45
+ <p>The device: <a href="https://wiki.apolloautomation.com/products/rpro1/introduction/" target="_blank">Apollo R PRO-1</a> (Apollo Automation's documentation).</p>
46
+ <h3>Wiring</h3>
47
+ <ol>
48
+ <li>Output 1 (motion and presence) → occupancy fusion, with its presence sensor set to hold.</li>
49
+ <li>Output 2 (light level) → the motion lighting policy.</li>
50
+ </ol>
51
+ <p>Choose the <b>Broker</b> the device uses (MQTT on in its ESPHome configuration), and set <b>Device</b> to its ESPHome
52
+ name, the prefix of its MQTT topics (such as <code>apollo-r-pro-1-1a2b3c</code>).</p>
53
+ <h3>What it reads</h3>
54
+ <p>It has two radars, an LD2450 and an LD2412, and no PIR. Each role counts as on when any radar that has reported
55
+ says so, and off when every one that has reported says off. Apollo's firmware has named the LD2450's entities
56
+ without a prefix on earlier releases and with <code>ld2450_</code> on current ones; the node reads both.</p>
57
+ <ul>
58
+ <li><b>Motion</b>: <code>binary_sensor/moving_target</code> (or <code>ld2450_moving_target</code>) and
59
+ <code>binary_sensor/ld2412_moving_target</code>: a moving target.</li>
60
+ <li><b>Presence</b>: <code>binary_sensor/presence</code> (or <code>ld2450_presence</code>) and
61
+ <code>binary_sensor/ld2412_presence</code>: anyone there, still or moving.</li>
62
+ <li><b>Light level</b>: <code>sensor/ltr390_light</code>, the LTR390, in lux.</li>
63
+ </ul>
64
+ <h3>How it finds its entities</h3>
65
+ <p>From the device's own MQTT discovery first: each entity it describes, by device class (motion; occupancy or
66
+ presence; illuminance), with its state topic, skipping those it marks disabled by default, so a firmware that renames an entity still works. The device's model
67
+ in its discovery must be this one. Without discovery (turn it on with <code>mqtt: discovery: true</code> in the
68
+ device's ESPHome configuration and flash it again), or with another model's, it uses the entity names below. Its
69
+ status ends with <i>discovered</i> or <i>preset</i>.</p>
70
+ <h3>Readings</h3>
71
+ <ul>
72
+ <li>Output 1: <code>{source: "motion" | "presence", payload: true | false}</code>, from ON and OFF only.</li>
73
+ <li>Output 2: <code>{source: "illuminance", payload: &lt;lux&gt;}</code>, from a number only.</li>
74
+ <li>Anything else (such as <code>nan</code>) is ignored with a trace, and only a change is sent.</li>
75
+ <li>As Node-RED starts, ESPHome's retained states are the device's current ones while its status is online. They
76
+ are sent with <code>msg.baseline = true</code>: an occupied room switches nothing on, and an empty one starts its
77
+ vacancy, so its lights go off when the motion policy's delay runs out. A retained state from a device that isn't
78
+ online is ignored.</li>
79
+ </ul>
80
+ </script>
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const esphome_sensor_1 = require("./esphome-sensor");
3
+ module.exports = (0, esphome_sensor_1.esphomeSensorNode)("home-apollo-r-pro-1", "apollo-r-pro-1");
4
+ //# sourceMappingURL=apollo-r-pro-1.js.map
@@ -108,7 +108,7 @@ const registerAvrController = (RED) => {
108
108
  node.warn("volume requests with value in the receiver's own 0-98 were removed in 6.0 and are rejected: " +
109
109
  "send valueDb (dB, where the receiver's 80 is 0 dB) instead");
110
110
  }
111
- const outputs = [...result.events, ...result.targetStates];
111
+ const outputs = [...result.events, ...result.targetStates, ...result.observations];
112
112
  if (commands.length || outputs.length) {
113
113
  send([
114
114
  commands.length ? commands : null,
@@ -50,8 +50,9 @@ const registerBacklightingController = (RED) => {
50
50
  null
51
51
  ]);
52
52
  }
53
- if (result.events.length) {
54
- send([null, result.events.map((event) => ({ payload: undefined, ...event }))]);
53
+ const theatre = [...result.events, ...result.observations];
54
+ if (theatre.length) {
55
+ send([null, theatre.map((event) => ({ payload: undefined, ...event }))]);
55
56
  }
56
57
  updateStatus(result.status);
57
58
  schedule(result.state);
@@ -11,6 +11,7 @@ export interface DeviceSide {
11
11
  broker: boolean;
12
12
  publish(publications: readonly DevicePublication[]): Array<Record<string, unknown>> | null;
13
13
  fromBroker(msg: InputMessage): boolean;
14
+ subscribe(topic: string): void;
14
15
  }
15
16
  export declare function deviceSide(node: Node, broker: BrokerNode | null, prefix: string, subscriptions: string[], trace: TraceMetadata, handle: (msg: InputMessage, send: Send) => void, onConnected?: () => void): DeviceSide;
16
17
  export declare function deviceBroker(RED: {
@@ -29,18 +29,22 @@ onConnected) {
29
29
  return {
30
30
  broker: false,
31
31
  publish: (publications) => publications.length ? publications.map((publication) => ({ ...publication })) : null,
32
- fromBroker: () => false
32
+ fromBroker: () => false,
33
+ subscribe: () => { }
33
34
  };
34
35
  }
35
36
  const link = (0, mqtt_broker_link_1.brokerLink)(broker, node.id, (error) => node.error(error));
36
- for (const topic of subscriptions) {
37
+ const subscribe = (topic) => {
37
38
  link.subscribe(topic, (message) => handle({ topic: message.topic, payload: message.payload, retain: message.retain }, node.send.bind(node)));
38
- }
39
+ };
40
+ for (const topic of subscriptions)
41
+ subscribe(topic);
39
42
  if (onConnected)
40
43
  link.onConnected(onConnected);
41
44
  node.on("close", (removed, done) => link.close(removed, done));
42
45
  return {
43
46
  broker: true,
47
+ subscribe,
44
48
  publish(publications) {
45
49
  for (const { topic, payload, retain } of publications)
46
50
  link.publish(topic, text(payload), { retain: retain === true });
@@ -68,7 +68,9 @@ const registerDisplayModeController = (RED) => {
68
68
  return;
69
69
  }
70
70
  if (command.device === "projector" && command.operation === "query_power" && !projectorPowerMeterHost) {
71
- node.send([null, null, { payload: "query", display_command: command }]);
71
+ // power: {kind: "read"} too, so a power meter node (such as a
72
+ // zigbee2mqtt power node) can be wired straight to it.
73
+ node.send([null, null, { payload: "query", display_command: command, power: { kind: "read" } }]);
72
74
  return;
73
75
  }
74
76
  const result = await transport.execute(command);
@@ -77,7 +79,7 @@ const registerDisplayModeController = (RED) => {
77
79
  }
78
80
  function process(msg, send) {
79
81
  const result = (0, adapter_1.runReducer)(node, { area: (0, adapter_1.optionalArea)(config), component: "display-mode-controller" }, (saved, now) => (0, display_mode_controller_1.transitionDisplay)(saved, msg, controllerConfig, now));
80
- const outputs = [...result.events, ...result.targetStates];
82
+ const outputs = [...result.events, ...result.targetStates, ...result.observations];
81
83
  if (outputs.length) {
82
84
  send([null, outputs.map((event) => ({ payload: undefined, ...event })), null]);
83
85
  }
@@ -89,6 +91,13 @@ const registerDisplayModeController = (RED) => {
89
91
  return result;
90
92
  }
91
93
  (0, adapter_1.onInput)(node, (msg, send) => {
94
+ // A power meter node's reading (msg.power) is its projector's power.
95
+ const power = (0, adapter_1.objectField)(msg, "power");
96
+ if (power?.kind === "observed" && !(0, adapter_1.objectField)(msg, "display")) {
97
+ process({ display: { kind: "observed", device: "projector", watts: power.watts,
98
+ ...(typeof power.observedAt === "string" ? { observedAt: power.observedAt } : {}) } }, send);
99
+ return;
100
+ }
92
101
  process({
93
102
  display: (0, adapter_1.objectField)(msg, "display")
94
103
  }, send);
@@ -0,0 +1,2 @@
1
+ import type { NodeInitializer } from "node-red";
2
+ export declare function esphomeSensorNode(type: string, model: string): NodeInitializer;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.esphomeSensorNode = esphomeSensorNode;
4
+ const esphome_sensor_1 = require("../lib/esphome-sensor");
5
+ const adapter_1 = require("./adapter");
6
+ const device_side_1 = require("./device-side");
7
+ // One node type per ESPHome device: its entity names belong to its
8
+ // product's firmware, so the model is the node's, not a setting. Each
9
+ // device's node registers this with its model (see ESPHOME_MODELS).
10
+ function esphomeSensorNode(type, model) {
11
+ return (RED) => {
12
+ function HomeEsphomeSensor(config) {
13
+ RED.nodes.createNode(this, config);
14
+ const node = this;
15
+ let device;
16
+ let broker;
17
+ try {
18
+ device = (0, esphome_sensor_1.normaliseEsphomeSensorConfig)({ device: config.device, model, discoveryPrefix: config.discoveryPrefix });
19
+ // Newer than the MQTT in and out way of wiring adapters: it needs its
20
+ // broker.
21
+ broker = (0, device_side_1.deviceBroker)(RED, config.broker);
22
+ if (!broker)
23
+ throw new Error("choose its MQTT broker");
24
+ }
25
+ catch (error) {
26
+ (0, adapter_1.invalidConfig)(node, error);
27
+ return;
28
+ }
29
+ const trace = { area: "", component: "esphome-sensor" };
30
+ node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
31
+ // Its discovery, its status and its preset's entities; then whatever its
32
+ // discovery names. ESPHome retains them, so on connect the broker hands
33
+ // over the device's description and current state, which passes as a
34
+ // baseline while the device is online.
35
+ const topics = (0, esphome_sensor_1.esphomeSensorTopics)(device);
36
+ const subscribed = new Set(topics.initial);
37
+ const side = (0, device_side_1.deviceSide)(node, broker, device.device, topics.initial, trace, (msg, send) => handle(msg, send));
38
+ function handle(msg, send) {
39
+ const result = (0, adapter_1.runReducer)(node, trace, (saved) => (0, esphome_sensor_1.transitionEsphomeSensor)(saved, msg, device));
40
+ for (const topic of result.topics) {
41
+ if (subscribed.has(topic))
42
+ continue;
43
+ subscribed.add(topic);
44
+ side.subscribe(topic);
45
+ }
46
+ // Output 1: motion and presence, for occupancy fusion. Output 2: the
47
+ // light level, for the motion lighting policy.
48
+ const outputs = [
49
+ result.occupancy.length ? result.occupancy.map((reading) => ({ ...reading })) : null,
50
+ result.light.length ? result.light.map((reading) => ({ ...reading })) : null
51
+ ];
52
+ if (outputs.some((output) => output !== null))
53
+ send(outputs);
54
+ const state = result.state;
55
+ if (state.online === false) {
56
+ node.status({ fill: "grey", shape: "ring", text: "offline" });
57
+ }
58
+ else {
59
+ const occupied = state.motion === true || state.presence === true;
60
+ const known = state.motion !== null || state.presence !== null;
61
+ // And where its entities came from: its discovery, or its preset.
62
+ const source = result.roles.source === "discovered" ? "discovered" : result.roles.source === "preset" ? "preset" : "preset: discovery is another model";
63
+ const parts = [known ? (occupied ? "occupied" : "clear") : "", state.illuminance !== null ? `${state.illuminance} lx` : "", source].filter(Boolean);
64
+ node.status({ fill: occupied ? "green" : "grey", shape: known ? "dot" : "ring", text: parts.join(" · ") });
65
+ }
66
+ }
67
+ (0, adapter_1.onInput)(node, (msg, send) => {
68
+ // Its device's messages come from the broker: an MQTT in node wired in
69
+ // changes nothing.
70
+ if (!side.fromBroker(msg))
71
+ handle(msg, send);
72
+ });
73
+ }
74
+ RED.nodes.registerType(type, HomeEsphomeSensor);
75
+ };
76
+ }
77
+ //# sourceMappingURL=esphome-sensor.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: import("node-red").NodeInitializer<import("node-red").NodeAPISettingsWithData>;
2
+ export = _default;
@@ -0,0 +1,78 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-everything-presence-one", {
3
+ category: "home automation",
4
+ color: "#e2d96e",
5
+ defaults: {
6
+ name: {value: ""},
7
+ // Node-RED's MQTT broker node, through which it subscribes to the
8
+ // device's topics. The editor offers the first broker when the dialog is
9
+ // opened and saved.
10
+ broker: {value: "", type: "mqtt-broker", required: true},
11
+ // No default: it names the user's own device.
12
+ device: {value: "", required: true, validate: function (v) {
13
+ var device = String(v || "").trim().replace(/^\/+|\/+$/g, "");
14
+ return device !== "" && !/[+#]/.test(device);
15
+ }},
16
+ // Where the device's discovery is: ESPHome's default. A node saved
17
+ // before this setting loads without it (the editor applies no defaults
18
+ // to deployed flows); missing or empty means homeassistant, as the
19
+ // runtime reads it.
20
+ discoveryPrefix: {value: "homeassistant", validate: function (v) {
21
+ return !/[+#]/.test(String(v === undefined || v === null ? "" : v));
22
+ }}
23
+ },
24
+ inputs: 1,
25
+ outputs: 2,
26
+ outputLabels: ["motion and presence, to occupancy fusion", "light level, to the motion lighting policy"],
27
+ icon: "font-awesome/fa-eye",
28
+ label: function () { return this.name || this.device || "everything presence one"; },
29
+ paletteLabel: "everything presence one"
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="home-everything-presence-one">
34
+ <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
35
+ <div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
36
+ <div class="form-row"><label for="node-input-device">Device</label><input type="text" id="node-input-device" placeholder="its ESPHome name"></div>
37
+ <div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
38
+ <div class="form-tips">It subscribes to the device's entities and status itself: no MQTT in, change or function nodes.</div>
39
+ </script>
40
+
41
+ <script type="text/html" data-help-name="home-everything-presence-one">
42
+ <p>Connects an <b>Everything Presence One</b> (Everything Smart Technology's ESPHome presence sensor) to a room: its PIR,
43
+ its mmWave radar and its light sensor become the messages <b>home occupancy fusion</b> and the <b>home motion lighting
44
+ policy</b> take, over ESPHome's own MQTT messages: no function or change nodes, and never Home Assistant.</p>
45
+ <p>The device: <a href="https://docs.everythingsmart.io/docs/products/everything-presence-one-ep1" target="_blank">Everything Presence One</a> (Everything Smart Technology's documentation).</p>
46
+ <h3>Wiring</h3>
47
+ <ol>
48
+ <li>Output 1 (motion and presence) → occupancy fusion, with its presence sensor set to hold.</li>
49
+ <li>Output 2 (light level) → the motion lighting policy.</li>
50
+ </ol>
51
+ <p>Choose the <b>Broker</b> the device uses (MQTT on in its ESPHome configuration), and set <b>Device</b> to its ESPHome
52
+ name, the prefix of its MQTT topics (such as <code>everything-presence-one-1a2b3c</code>).</p>
53
+ <h3>What it reads</h3>
54
+ <ul>
55
+ <li><b>Motion</b>: <code>binary_sensor/pir</code>, the PIR: quick to see someone arrive.</li>
56
+ <li><b>Presence</b>: <code>binary_sensor/mmwave</code>, the radar: sees someone sitting still, so occupancy fusion
57
+ holds the room while they stay.</li>
58
+ <li><b>Light level</b>: <code>sensor/illuminance</code>, in lux.</li>
59
+ <li>Not its own <code>occupancy</code> entity: that combines the two on the device, and occupancy fusion does that
60
+ combining here.</li>
61
+ </ul>
62
+ <h3>How it finds its entities</h3>
63
+ <p>From the device's own MQTT discovery first: each entity it describes, by device class (motion; occupancy or
64
+ presence; illuminance), with its state topic, skipping those it marks disabled by default, so a firmware that renames an entity still works. The device's model
65
+ in its discovery must be this one. Without discovery (turn it on with <code>mqtt: discovery: true</code> in the
66
+ device's ESPHome configuration and flash it again), or with another model's, it uses the entity names below. Its
67
+ status ends with <i>discovered</i> or <i>preset</i>.</p>
68
+ <h3>Readings</h3>
69
+ <ul>
70
+ <li>Output 1: <code>{source: "motion" | "presence", payload: true | false}</code>, from ON and OFF only.</li>
71
+ <li>Output 2: <code>{source: "illuminance", payload: &lt;lux&gt;}</code>, from a number only.</li>
72
+ <li>Anything else (such as <code>nan</code>) is ignored with a trace, and only a change is sent.</li>
73
+ <li>As Node-RED starts, ESPHome's retained states are the device's current ones while its status is online. They
74
+ are sent with <code>msg.baseline = true</code>: an occupied room switches nothing on, and an empty one starts its
75
+ vacancy, so its lights go off when the motion policy's delay runs out. A retained state from a device that isn't
76
+ online is ignored.</li>
77
+ </ul>
78
+ </script>
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const esphome_sensor_1 = require("./esphome-sensor");
3
+ module.exports = (0, esphome_sensor_1.esphomeSensorNode)("home-everything-presence-one", "everything-presence-one");
4
+ //# sourceMappingURL=everything-presence-one.js.map
@@ -123,6 +123,9 @@
123
123
  <script type="text/html" data-help-name="home-occupancy-fusion">
124
124
  <p>Combines normalised <code>motion</code> and optional <code>presence</code> events into <code>msg.source = "occupancy"</code>.</p>
125
125
  <p>PIR establishes occupancy. Presence can hold an established occupancy but cannot establish one by itself.</p>
126
+ <p>With <code>msg.baseline = true</code>, a motion or presence message is the sensor's state as Node-RED starts (such
127
+ as an ESPHome sensor's retained state): on makes the area occupied without sending anything, so no light is switched
128
+ on; off is read as usual, so an empty room starts the motion policy's vacancy countdown.</p>
126
129
  <h3>Publishing</h3>
127
130
  <p>Off unless switched on. Both are named after the <b>Area</b>, which is needed then; topics use it in lowercase,
128
131
  with spaces and other characters as <code>_</code>.</p>
@@ -80,7 +80,8 @@ const registerOccupancyFusion = (RED) => {
80
80
  }
81
81
  const input = {
82
82
  source: String(msg.source ?? ""),
83
- payload: msg.payload
83
+ payload: msg.payload,
84
+ baseline: msg.baseline === true
84
85
  };
85
86
  const result = (0, adapter_1.runReducer)(node, { area: fusionConfig.area, component: "occupancy-fusion" }, (saved) => (0, occupancy_fusion_1.transitionOccupancy)(saved, input, fusionConfig));
86
87
  for (const output of result.outputs) {
@@ -72,6 +72,17 @@
72
72
  }},
73
73
  lights: {value: "[]", required: true, validate: validLights},
74
74
  safetyHours: {value: 4, required: true, validate: function (v) { var n = Number(v); return String(v).trim() !== "" && isFinite(n) && n >= 0; }},
75
+ // Optional: a power meter's reading (msg.power) below this many watts,
76
+ // for endBelowSeconds, ends the scene. Empty: none. A scene saved
77
+ // before these settings loads without them, which is valid.
78
+ endBelowWatts: {value: "", validate: function (v) {
79
+ if (v === undefined || v === null || String(v).trim() === "") return true;
80
+ var n = Number(v); return isFinite(n) && n > 0;
81
+ }},
82
+ endBelowSeconds: {value: 60, validate: function (v) {
83
+ if (v === undefined || v === null || String(v).trim() === "") return true;
84
+ var n = Number(v); return isFinite(n) && n >= 0;
85
+ }},
75
86
  area: {value: "", validate: function (v) { return !needsArea(this) || /[a-z0-9]/i.test(String(v || "")); }},
76
87
  // Off until switched on.
77
88
  // Publish: off, state or discovery. null means "not set": a node saved
@@ -129,6 +140,10 @@
129
140
  <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name" placeholder="Bath, for example"></div>
130
141
  <div class="form-row"><label for="node-input-lights">Lights</label><input type="text" id="node-input-lights" placeholder='[{"area":"gym","target":"main","state":"OFF"}]'></div>
131
142
  <div class="form-row"><label for="node-input-safetyHours">Safety timer (hours)</label><input type="number" id="node-input-safetyHours" min="0" step="0.25"> <span>(0: off)</span></div>
143
+ <div class="form-row"><label for="node-input-endBelowWatts">End below (W)</label><input type="number" id="node-input-endBelowWatts" min="0" step="1" placeholder="none"> <span>for</span>
144
+ <input type="number" id="node-input-endBelowSeconds" min="0" step="1" style="width:70px"> <span>s</span></div>
145
+ <div class="form-tips">Wire a power meter node (such as a zigbee2mqtt power node on a device's plug) to the scene: power
146
+ below this, held that long, ends the scene "by power".</div>
132
147
  <div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area"></div>
133
148
  <div class="form-row">
134
149
  <label for="node-input-homeAssistant">Publish</label>
@@ -162,9 +177,11 @@
162
177
  <dl class="message-properties">
163
178
  <dt>scene <span class="property-type">object</span></dt>
164
179
  <dd><code>{kind: "start"}</code> turns it on (on again: a fresh safety timer, its lights left as they are);
165
- <code>{kind: "end", by}</code> ends it, with <code>by</code> (optional) shown as what ended it. An end
166
- trigger, such as a trainer's power falling, is a flow that sends this end when its condition is met.
167
- <code>{kind: "startup"}</code> announces its switch again.</dd>
180
+ <code>{kind: "end", by}</code> ends it, with <code>by</code> (optional) shown as what ended it, for any
181
+ end trigger a flow decides. <code>{kind: "startup"}</code> announces its switch again.</dd>
182
+ <dt>power <span class="property-type">object</span></dt>
183
+ <dd><code>{kind: "observed", watts}</code> from a power meter node: with <b>End below</b> set, power below it,
184
+ held for its seconds, ends the scene <i>by power</i>.</dd>
168
185
  <dt>payload <span class="property-type">string</span></dt>
169
186
  <dd><code>ON</code> or <code>OFF</code> on its set topic, from Home Assistant: a start, or an end by
170
187
  <code>home-assistant</code>.</dd>
@@ -205,6 +222,10 @@
205
222
  <code>[{"area": "gym", "target": "main", "state": "OFF"}, {"area": "gym", "target": "tv", "state": "ON"}]</code>.</dd>
206
223
  <dt>Safety timer</dt><dd>Hours until it ends itself, so a forgotten scene doesn't hold the room: 4 by
207
224
  default; 0 turns it off.</dd>
225
+ <dt>End below</dt><dd>Optional: watts, and for how many seconds (60 by default). Once the device has been
226
+ used since the scene started (a power reading, <code>msg.power</code>, at or above it), a reading below it,
227
+ held that long, ends the scene <i>by power</i>; one at or above it starts the wait again. Before the device is
228
+ used, its standby draw is ignored. Empty: no power end.</dd>
208
229
  <dt>Area, Publish</dt><dd><i>Don't publish</i> unless chosen. <i>MQTT state</i>: its state and set topic, plain
209
230
  MQTT; <i>MQTT state and Home Assistant discovery</i>: also a switch entity for the scene
210
231
  that shows whether it is on and turns it on and off, on <code>home/&lt;area&gt;/scene/&lt;name&gt;/…</code>.</dd>
@@ -24,7 +24,8 @@ const registerScene = (RED) => {
24
24
  const name = (0, settings_1.textSetting)(config.name, "name");
25
25
  if (!(0, topic_names_1.areaId)(name))
26
26
  throw new Error("name must contain a letter or digit");
27
- scene = (0, scene_1.normaliseSceneConfig)({ owner: "scene:" + name, lights: config.lights, safetyHours: config.safetyHours });
27
+ scene = (0, scene_1.normaliseSceneConfig)({ owner: "scene:" + name, lights: config.lights, safetyHours: config.safetyHours,
28
+ endBelowWatts: config.endBelowWatts, endBelowSeconds: config.endBelowSeconds });
28
29
  area = (0, adapter_1.optionalArea)(config);
29
30
  const publish = (0, home_assistant_setting_1.publishingChoice)(config, { publishState: false, discovery: false });
30
31
  if (publish.needsArea)
@@ -74,13 +75,19 @@ const registerScene = (RED) => {
74
75
  lifecycle.publish(send, (0, scene_publishing_1.sceneStateOutputs)(publishing, result.state.active));
75
76
  node.status(result.status);
76
77
  clearTimeout(timer);
77
- const at = (0, scene_1.sceneTickAt)(result.state, Date.now());
78
+ const at = (0, scene_1.sceneTickAt)(result.state, Date.now(), scene);
78
79
  timer = at === null ? undefined : setTimeout((0, adapter_1.guarded)(node, () => process({ kind: "tick" }, node.send.bind(node))), Math.max(0, at - Date.now()));
79
80
  }
80
81
  // A scene on when the flows stopped is still on: renew its pause and its
81
82
  // timer, or end it if its time ran out meanwhile.
82
83
  (0, adapter_1.whenFlowsStarted)(RED, node, () => process({ kind: "startup" }, node.send.bind(node)));
83
84
  function handle(msg, send) {
85
+ // A power meter's reading, for its End below.
86
+ const power = (0, adapter_1.objectField)(msg, "power");
87
+ if (power?.kind === "observed" && !(0, adapter_1.objectField)(msg, "scene")) {
88
+ process({ kind: "power", watts: power.watts }, send);
89
+ return;
90
+ }
84
91
  const event = (0, adapter_1.objectField)(msg, "scene");
85
92
  if (event) {
86
93
  if (event.kind === "startup")
@@ -72,6 +72,7 @@
72
72
  <script type="text/html" data-help-name="home-shelly-cover">
73
73
  <p>Connects a Shelly Gen2 or later device in cover mode to a <b>home cover controller</b>, over the device's own
74
74
  MQTT API: no function nodes, no Home Assistant and no HTTP.</p>
75
+ <p>The devices: <a href="https://shelly-api-docs.shelly.cloud/gen2/" target="_blank">Shelly's Gen2+ device documentation</a>.</p>
75
76
  <h3>Wiring</h3>
76
77
  <p>With a <b>Broker</b>, it subscribes to <code>&lt;prefix&gt;/#</code> and publishes on its device's topics itself: leave out the MQTT
77
78
  in and MQTT out nodes below (still wired, they change nothing). Its first output then sends nothing. It reads its cover on each connect, as a Status node's startup did through the cover controller. A node saved
@@ -86,6 +86,7 @@
86
86
  <script type="text/html" data-help-name="home-shelly-switch">
87
87
  <p>Connects one switch channel of a Shelly Gen2 or later relay, over the device's own MQTT API, used the way the
88
88
  device is set up: no function nodes, no Home Assistant and no HTTP.</p>
89
+ <p>The devices: <a href="https://shelly-api-docs.shelly.cloud/gen2/" target="_blank">Shelly's Gen2+ device documentation</a>.</p>
89
90
  <h3>Wiring</h3>
90
91
  <p>With a <b>Broker</b>, it subscribes to <code>&lt;prefix&gt;/#</code> and publishes on its device's topics itself: leave out the MQTT
91
92
  in and MQTT out nodes below (still wired, they change nothing). Its first output then sends nothing. A node saved
@@ -48,8 +48,9 @@ const registerSourceCapabilityController = (RED) => {
48
48
  null
49
49
  ]);
50
50
  }
51
- if (result.events.length) {
52
- send([null, result.events.map((event) => ({ payload: undefined, ...event }))]);
51
+ const theatre = [...result.events, ...result.observations];
52
+ if (theatre.length) {
53
+ send([null, theatre.map((event) => ({ payload: undefined, ...event }))]);
53
54
  }
54
55
  updateStatus(result.status);
55
56
  schedule(result.state);
@@ -27,6 +27,8 @@
27
27
 
28
28
  <script type="text/html" data-help-name="home-theatre-activity-controller">
29
29
  <p>Owns latest-request-wins whole-theatre activity state and aggregates generation-scoped target evidence.</p>
30
- <p>Input <code>msg.theatre</code> accepts activity intent, target-state, startup, refresh, recovery and tick events. Messages without <code>msg.theatre</code>, such as a target controller's own events on the same wire, are ignored. Output 1 emits semantic <code>msg.theatreCommand</code> messages for target owners. Output 2 emits activity events and a complete state snapshot. Device transports remain separate.</p>
31
- <p>Startup without persisted intent probes physical state. One fresh profile match is adopted without commands. With no evidence, or more than one match, the activity is unknown and nothing is commanded until the next request, so a redeploy or restart never switches a running activity off. Manual overrides are held without corrective commands and adopted only when the physical state uniquely matches a profile.</p>
30
+ <p>Input <code>msg.theatre</code> accepts activity intent, target-state, target-observation, startup, refresh, recovery and tick events. Messages without <code>msg.theatre</code>, such as a target controller's own events on the same wire, are ignored. Output 1 emits semantic <code>msg.theatreCommand</code> messages for target owners. Output 2 emits activity events and a complete state snapshot. Device transports remain separate.</p>
31
+ <p>Startup without persisted intent probes physical state: the display, AVR, source and backlighting controllers answer
32
+ with <code>msg.theatre = {kind: "target_observation", target, observedAt, values}</code>, what their devices show, on the
33
+ wires that carry their target states. One fresh profile match is adopted without commands. With no evidence, or more than one match, the activity is unknown and nothing is commanded until the next request, so a redeploy or restart never switches a running activity off. Manual overrides are held without corrective commands and adopted only when the physical state uniquely matches a profile.</p>
32
34
  </script>
@@ -0,0 +1,3 @@
1
+ import type { NodeInitializer } from "node-red";
2
+ declare const registerWled: NodeInitializer;
3
+ export = registerWled;
@@ -0,0 +1,56 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-wled", {
3
+ category: "home automation",
4
+ color: "#e2d96e",
5
+ defaults: {
6
+ name: {value: ""},
7
+ // Node-RED's MQTT broker node, through which it subscribes to WLED's
8
+ // topics and publishes its commands. The editor offers the first broker
9
+ // when the dialog is opened and saved.
10
+ broker: {value: "", type: "mqtt-broker", required: true},
11
+ // No default: it names the user's own device.
12
+ deviceTopic: {value: "", required: true, validate: function (v) {
13
+ var topic = String(v || "").trim().replace(/^\/+|\/+$/g, "");
14
+ return topic !== "" && !/[+#]/.test(topic);
15
+ }}
16
+ },
17
+ inputs: 1,
18
+ outputs: 1,
19
+ outputLabels: ["to the backlighting controller"],
20
+ icon: "font-awesome/fa-lightbulb-o",
21
+ label: function () { return this.name || this.deviceTopic || "wled"; },
22
+ paletteLabel: "wled"
23
+ });
24
+ </script>
25
+
26
+ <script type="text/html" data-template-name="home-wled">
27
+ <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
28
+ <div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
29
+ <div class="form-row"><label for="node-input-deviceTopic">Device topic</label><input type="text" id="node-input-deviceTopic" placeholder="WLED's Device Topic, as in its Sync settings"></div>
30
+ <div class="form-tips">It subscribes to the device topic's <code>/g</code> and <code>/status</code> and publishes WLED's
31
+ <code>ON</code> and <code>OFF</code> itself: no MQTT in or out nodes.</div>
32
+ </script>
33
+
34
+ <script type="text/html" data-help-name="home-wled">
35
+ <p>Connects a WLED light strip to a <b>home backlighting controller</b>, over WLED's own MQTT messages: no function
36
+ nodes, and never Home Assistant.</p>
37
+ <p>The device: <a href="https://kno.wled.ge/" target="_blank">WLED</a>.</p>
38
+ <h3>Wiring</h3>
39
+ <ol>
40
+ <li>The backlighting controller's first output (its device commands) → this node.</li>
41
+ <li>This node's output → the backlighting controller.</li>
42
+ </ol>
43
+ <p>Choose the <b>Broker</b> WLED uses, and set <b>Device topic</b> to WLED's own (Config → Sync Interfaces → MQTT; WLED's
44
+ default is <code>wled/</code> and its MAC address). It subscribes to <code>&lt;device topic&gt;/g</code> (brightness) and
45
+ <code>&lt;device topic&gt;/status</code> (online or offline), and publishes <code>ON</code> or <code>OFF</code> on the
46
+ device topic.</p>
47
+ <h3>Readings</h3>
48
+ <p>Each brightness WLED reports becomes <code>msg.backlighting = {kind: "observed", generation, power, observedAt}</code>
49
+ for the command in hand: brightness 0 is off, anything else on. WLED reports every change, from any source, and
50
+ doesn't say who made it: the backlighting controller judges a reading it didn't ask for as a manual change.
51
+ An <code>observe</code> is answered from the last report while WLED is online; with none since Node-RED started
52
+ there is nothing to answer until WLED next changes: WLED publishes only when it changes, and can't be asked over
53
+ MQTT (seen on the firmware we tested).</p>
54
+ <p>A <code>set_power</code> is answered with <code>command_result</code> ok once published, or not ok with reason
55
+ <code>unavailable</code> while WLED is offline.</p>
56
+ </script>