@avantics/node-red-home-automation 6.2.0 → 6.4.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 (79) hide show
  1. package/README.md +93 -12
  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/ha-discovery.js +3 -2
  13. package/dist/lib/occupancy-fusion.d.ts +1 -0
  14. package/dist/lib/occupancy-fusion.js +15 -2
  15. package/dist/lib/scene.d.ts +9 -1
  16. package/dist/lib/scene.js +61 -8
  17. package/dist/lib/source-capability-controller.d.ts +4 -1
  18. package/dist/lib/source-capability-controller.js +49 -2
  19. package/dist/lib/target-observation.d.ts +14 -0
  20. package/dist/lib/target-observation.js +22 -0
  21. package/dist/lib/theatre-activity-controller.d.ts +5 -0
  22. package/dist/lib/theatre-activity-controller.js +87 -12
  23. package/dist/lib/theatre-state.d.ts +2 -0
  24. package/dist/lib/theatre-state.js +10 -1
  25. package/dist/lib/wled.d.ts +48 -0
  26. package/dist/lib/wled.js +105 -0
  27. package/dist/lib/z2m-power.d.ts +38 -0
  28. package/dist/lib/z2m-power.js +83 -0
  29. package/dist/lib/z2m-sensor.d.ts +37 -0
  30. package/dist/lib/z2m-sensor.js +88 -0
  31. package/dist/nodes/activity-lighting-controller.html +2 -1
  32. package/dist/nodes/apollo-r-pro-1.d.ts +2 -0
  33. package/dist/nodes/apollo-r-pro-1.html +80 -0
  34. package/dist/nodes/apollo-r-pro-1.js +4 -0
  35. package/dist/nodes/avr-controller.html +2 -1
  36. package/dist/nodes/avr-controller.js +1 -1
  37. package/dist/nodes/backlighting-controller.html +2 -1
  38. package/dist/nodes/backlighting-controller.js +3 -2
  39. package/dist/nodes/circadian-policy.html +2 -1
  40. package/dist/nodes/cover-controller.html +2 -1
  41. package/dist/nodes/cover-group.html +2 -1
  42. package/dist/nodes/device-side.d.ts +1 -0
  43. package/dist/nodes/device-side.js +7 -3
  44. package/dist/nodes/display-mode-controller.html +2 -1
  45. package/dist/nodes/display-mode-controller.js +11 -2
  46. package/dist/nodes/esphome-sensor.d.ts +2 -0
  47. package/dist/nodes/esphome-sensor.js +77 -0
  48. package/dist/nodes/everything-presence-one.d.ts +2 -0
  49. package/dist/nodes/everything-presence-one.html +78 -0
  50. package/dist/nodes/everything-presence-one.js +4 -0
  51. package/dist/nodes/house-schedule-mqtt.html +2 -1
  52. package/dist/nodes/motion-policy.html +6 -4
  53. package/dist/nodes/motion-policy.js +10 -1
  54. package/dist/nodes/occupancy-fusion.html +5 -1
  55. package/dist/nodes/occupancy-fusion.js +2 -1
  56. package/dist/nodes/room-controller.html +2 -1
  57. package/dist/nodes/scene.html +25 -4
  58. package/dist/nodes/scene.js +9 -2
  59. package/dist/nodes/shelly-cover.html +2 -1
  60. package/dist/nodes/shelly-switch.html +2 -1
  61. package/dist/nodes/source-capability-controller.html +2 -1
  62. package/dist/nodes/source-capability-controller.js +3 -2
  63. package/dist/nodes/switch-policy.html +2 -1
  64. package/dist/nodes/theatre-activity-controller.html +6 -3
  65. package/dist/nodes/theatre-state-contract.html +2 -1
  66. package/dist/nodes/wled.d.ts +3 -0
  67. package/dist/nodes/wled.html +56 -0
  68. package/dist/nodes/wled.js +53 -0
  69. package/dist/nodes/z2m-cover.html +2 -1
  70. package/dist/nodes/z2m-light.html +4 -2
  71. package/dist/nodes/z2m-light.js +17 -0
  72. package/dist/nodes/z2m-power.d.ts +3 -0
  73. package/dist/nodes/z2m-power.html +58 -0
  74. package/dist/nodes/z2m-power.js +53 -0
  75. package/dist/nodes/z2m-sensor.d.ts +3 -0
  76. package/dist/nodes/z2m-sensor.html +69 -0
  77. package/dist/nodes/z2m-sensor.js +62 -0
  78. package/examples/Scene.json +8 -56
  79. package/package.json +31 -16
@@ -27,7 +27,8 @@
27
27
  return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
28
28
  }
29
29
  RED.nodes.registerType("home-occupancy-fusion", {
30
- category: "home automation",
30
+ category: "home lighting",
31
+ paletteLabel: "occupancy",
31
32
  color: "#c7e9c0",
32
33
  defaults: {
33
34
  // A marker only a node new from the palette has, as core nodes do: import
@@ -123,6 +124,9 @@
123
124
  <script type="text/html" data-help-name="home-occupancy-fusion">
124
125
  <p>Combines normalised <code>motion</code> and optional <code>presence</code> events into <code>msg.source = "occupancy"</code>.</p>
125
126
  <p>PIR establishes occupancy. Presence can hold an established occupancy but cannot establish one by itself.</p>
127
+ <p>With <code>msg.baseline = true</code>, a motion or presence message is the sensor's state as Node-RED starts (such
128
+ as an ESPHome sensor's retained state): on makes the area occupied without sending anything, so no light is switched
129
+ on; off is read as usual, so an empty room starts the motion policy's vacancy countdown.</p>
126
130
  <h3>Publishing</h3>
127
131
  <p>Off unless switched on. Both are named after the <b>Area</b>, which is needed then; topics use it in lowercase,
128
132
  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) {
@@ -98,7 +98,8 @@
98
98
  return imported.nodes.filter(function (n) { return n.type === "home-z2m-light"; }).length;
99
99
  }
100
100
  RED.nodes.registerType("home-room-lighting-controller", {
101
- category: "home automation",
101
+ category: "home lighting",
102
+ paletteLabel: "room lighting",
102
103
  color: "#ffd27f",
103
104
  defaults: {
104
105
  // A marker only a node new from the palette has, as core nodes do: import
@@ -54,7 +54,7 @@
54
54
  return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
55
55
  }
56
56
  RED.nodes.registerType("home-scene", {
57
- category: "home automation",
57
+ category: "home lighting",
58
58
  color: "#e2d96e",
59
59
  defaults: {
60
60
  // No default: it names the scene to its rooms, motion policies and
@@ -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")
@@ -1,6 +1,6 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-shelly-cover", {
3
- category: "home automation",
3
+ category: "home devices",
4
4
  color: "#e2d96e",
5
5
  defaults: {
6
6
  // A marker only a node new from the palette has, as core nodes do: import
@@ -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
@@ -1,6 +1,6 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-shelly-switch", {
3
- category: "home automation",
3
+ category: "home devices",
4
4
  color: "#e2d96e",
5
5
  defaults: {
6
6
  // A marker only a node new from the palette has, as core nodes do: import
@@ -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
@@ -1,6 +1,7 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-source-capability-controller", {
3
- category: "home automation",
3
+ category: "home theatre",
4
+ paletteLabel: "source",
4
5
  color: "#c7d9f1",
5
6
  defaults: {
6
7
  name: {value: ""},
@@ -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);
@@ -1,6 +1,7 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-switch-lighting-policy", {
3
- category: "home automation",
3
+ category: "home lighting",
4
+ paletteLabel: "switch policy",
4
5
  color: "#d8bfd8",
5
6
  defaults: {
6
7
  name: {value: ""},
@@ -1,6 +1,7 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-theatre-activity-controller", {
3
- category: "home automation",
3
+ category: "home theatre",
4
+ paletteLabel: "theatre activity",
4
5
  color: "#d9c7f1",
5
6
  defaults: {
6
7
  name: {value: ""},
@@ -27,6 +28,8 @@
27
28
 
28
29
  <script type="text/html" data-help-name="home-theatre-activity-controller">
29
30
  <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>
31
+ <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>
32
+ <p>Startup without persisted intent probes physical state: the display, AVR, source and backlighting controllers answer
33
+ with <code>msg.theatre = {kind: "target_observation", target, observedAt, values}</code>, what their devices show, on the
34
+ 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
35
  </script>
@@ -21,7 +21,8 @@
21
21
  return node.homeAssistant === null || node.homeAssistant === undefined;
22
22
  }
23
23
  RED.nodes.registerType("home-theatre-state-contract", {
24
- category: "home automation",
24
+ category: "home theatre",
25
+ paletteLabel: "theatre contract",
25
26
  color: "#d9c7f1",
26
27
  defaults: {
27
28
  // A marker only a node new from the palette has, as core nodes do: import
@@ -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 devices",
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>
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ const wled_1 = require("../lib/wled");
3
+ const adapter_1 = require("./adapter");
4
+ const device_side_1 = require("./device-side");
5
+ const registerWled = (RED) => {
6
+ function HomeWled(config) {
7
+ RED.nodes.createNode(this, config);
8
+ const node = this;
9
+ let device;
10
+ let broker;
11
+ try {
12
+ device = (0, wled_1.normaliseWledConfig)(config);
13
+ // Newer than the MQTT in and out way of wiring adapters: it needs its
14
+ // broker.
15
+ broker = (0, device_side_1.deviceBroker)(RED, config.broker);
16
+ if (!broker)
17
+ throw new Error("choose its MQTT broker");
18
+ }
19
+ catch (error) {
20
+ (0, adapter_1.invalidConfig)(node, error);
21
+ return;
22
+ }
23
+ const trace = { area: "", component: "wled" };
24
+ node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
25
+ // Exactly its own topics: its brightness and its availability. Its
26
+ // device topic is where its commands go.
27
+ const topics = (0, wled_1.wledTopics)(device);
28
+ const side = (0, device_side_1.deviceSide)(node, broker, topics.device, [topics.brightness, topics.status], trace, (msg, send) => handle(msg, send));
29
+ function handle(msg, send) {
30
+ const result = (0, adapter_1.runReducer)(node, trace, (saved, now) => (0, wled_1.transitionWled)(saved, msg, device, now));
31
+ // Its commands to WLED through the broker; readings for the
32
+ // backlighting controller on its output.
33
+ side.publish(result.publications);
34
+ // One output: its messages together on it, as [[...]].
35
+ if (result.readings.length)
36
+ send([result.readings.map((reading) => ({ payload: undefined, ...reading }))]);
37
+ const state = result.state;
38
+ if (state.online === false)
39
+ node.status({ fill: "grey", shape: "ring", text: "offline" });
40
+ else if (state.power)
41
+ node.status({ fill: state.power === "on" ? "green" : "grey", shape: "dot", text: state.power });
42
+ }
43
+ (0, adapter_1.onInput)(node, (msg, send) => {
44
+ // WLED's messages come from the broker: an MQTT in node wired in
45
+ // changes nothing.
46
+ if (!side.fromBroker(msg))
47
+ handle(msg, send);
48
+ });
49
+ }
50
+ RED.nodes.registerType("home-wled", HomeWled);
51
+ };
52
+ module.exports = registerWled;
53
+ //# sourceMappingURL=wled.js.map
@@ -1,6 +1,6 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-z2m-cover", {
3
- category: "home automation",
3
+ category: "home devices",
4
4
  color: "#e2d96e",
5
5
  defaults: {
6
6
  // A marker only a node new from the palette has, as core nodes do: import
@@ -73,6 +73,7 @@
73
73
  <script type="text/html" data-help-name="home-z2m-cover">
74
74
  <p>Connects a Zigbee2MQTT cover (a blind, shutter or curtain motor) to a <b>home cover controller</b>, over
75
75
  Zigbee2MQTT's MQTT messages: no function nodes, and never Home Assistant.</p>
76
+ <p>The devices: <a href="https://www.zigbee2mqtt.io/supported-devices/" target="_blank">Zigbee2MQTT's supported devices</a>.</p>
76
77
  <h3>Wiring</h3>
77
78
  <p>With a <b>Broker</b>, it subscribes to <code>&lt;base&gt;/&lt;friendly name&gt;</code> and its <code>/availability</code> (exactly these: a friendly name can contain <code>/</code>) and publishes on its device's topics itself: leave out the MQTT
78
79
  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
@@ -1,6 +1,6 @@
1
1
  <script type="text/javascript">
2
2
  RED.nodes.registerType("home-z2m-light", {
3
- category: "home automation",
3
+ category: "home devices",
4
4
  color: "#e2d96e",
5
5
  defaults: {
6
6
  // A marker only a node new from the palette has, as core nodes do: import
@@ -78,6 +78,7 @@
78
78
  <script type="text/html" data-help-name="home-z2m-light">
79
79
  <p>Connects one Zigbee2MQTT light, or a Zigbee2MQTT group of lights, to a <b>room lighting controller</b>, over
80
80
  Zigbee2MQTT's MQTT messages: no function nodes, and never Home Assistant. Use one per light in the room's targets.</p>
81
+ <p>The devices: <a href="https://www.zigbee2mqtt.io/supported-devices/" target="_blank">Zigbee2MQTT's supported devices</a>.</p>
81
82
  <h3>Wiring</h3>
82
83
  <p>With a <b>Broker</b>, it subscribes to <code>&lt;base&gt;/&lt;friendly name&gt;</code>, its <code>/set</code> and its <code>/availability</code> (exactly these: a friendly name can contain <code>/</code>) and publishes on its device's topics itself: leave out the MQTT
83
84
  in and MQTT out nodes below (still wired, they change nothing). Its first output then sends nothing. It reads its light on each connect (not a group, which Zigbee2MQTT can't be asked), as a Status node's startup did through the room. A node saved
@@ -108,7 +109,8 @@
108
109
  <p>Switch on the group's <b>retain</b> in Zigbee2MQTT: <code>retain: true</code> under the group in Zigbee2MQTT's
109
110
  <code>configuration.yaml</code> (it is off by default). Zigbee2MQTT doesn't retain a group's state by default, so after a restart the
110
111
  room has no reading for the group until it changes, and an activity that holds it waits on it. With retain, the broker
111
- gives this node the group's last state as soon as its MQTT in node subscribes.</p>
112
+ gives this node the group's last state as soon as it (or its MQTT in node) subscribes. A group that has had no state 30 seconds
113
+ after it started shows <i>group · no state yet: set retain: true for it in Zigbee2MQTT</i> on its status.</p>
112
114
  <h3>Settings</h3>
113
115
  <dl class="message-properties">
114
116
  <dt>Target</dt><dd>The light's id in the room controller's Targets JSON.</dd>
@@ -2,6 +2,9 @@
2
2
  const z2m_light_adapter_1 = require("../lib/z2m-light-adapter");
3
3
  const adapter_1 = require("./adapter");
4
4
  const device_side_1 = require("./device-side");
5
+ // How long a group waits for its state before its status says why it may
6
+ // have none.
7
+ const GROUP_HINT_MS = 30_000;
5
8
  const registerZ2mLight = (RED) => {
6
9
  function HomeZ2mLight(config) {
7
10
  RED.nodes.createNode(this, config);
@@ -18,6 +21,18 @@ const registerZ2mLight = (RED) => {
18
21
  }
19
22
  const trace = { area: "", component: "z2m-light" };
20
23
  node.status({ fill: "grey", shape: "ring", text: light.group ? "group · waiting for its state" : "waiting for the device" });
24
+ // A group can't be asked for its state, so after a restart it has none
25
+ // until it changes, unless Zigbee2MQTT retains it: say so if nothing
26
+ // has come by then.
27
+ let reported = false;
28
+ const hint = light.group ? setTimeout((0, adapter_1.guarded)(node, () => {
29
+ if (!reported)
30
+ node.status({ fill: "yellow", shape: "ring", text: "group · no state yet: set retain: true for it in Zigbee2MQTT" });
31
+ }), GROUP_HINT_MS) : undefined;
32
+ node.on("close", (_removed, done) => {
33
+ clearTimeout(hint);
34
+ done();
35
+ });
21
36
  // With a broker, it reads its device on each connect, reconnects
22
37
  // included, through its own observe: after a restart nothing reported it
23
38
  // while it was away, and the controller acts on the reading as on one it
@@ -45,6 +60,8 @@ const registerZ2mLight = (RED) => {
45
60
  ];
46
61
  if (outputs.some((output) => output !== null))
47
62
  send(outputs);
63
+ if (result.readings.some((reading) => reading.kind === "observed"))
64
+ reported = true;
48
65
  const state = result.state;
49
66
  if (state.online === false) {
50
67
  node.status({ fill: "grey", shape: "ring", text: "offline" });
@@ -0,0 +1,3 @@
1
+ import type { NodeInitializer } from "node-red";
2
+ declare const registerZ2mPower: NodeInitializer;
3
+ export = registerZ2mPower;
@@ -0,0 +1,58 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-z2m-power", {
3
+ category: "home devices",
4
+ color: "#e2d96e",
5
+ defaults: {
6
+ name: {value: ""},
7
+ // Node-RED's MQTT broker node, through which it subscribes to its
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
+ baseTopic: {value: "zigbee2mqtt", required: true, validate: function (v) {
12
+ var base = String(v || "").trim().replace(/^\/+|\/+$/g, "");
13
+ return base !== "" && !/[+#]/.test(base);
14
+ }},
15
+ // No default: it names the user's own device.
16
+ friendlyName: {value: "", required: true, validate: function (v) {
17
+ var name = String(v || "").trim().replace(/^\/+|\/+$/g, "");
18
+ return name !== "" && !/[+#]/.test(name);
19
+ }}
20
+ },
21
+ inputs: 1,
22
+ outputs: 1,
23
+ outputLabels: ["power readings (msg.power), to a display controller or a scene"],
24
+ icon: "font-awesome/fa-bolt",
25
+ label: function () { return this.name || this.friendlyName || "zigbee2mqtt power"; },
26
+ paletteLabel: "zigbee2mqtt power"
27
+ });
28
+ </script>
29
+
30
+ <script type="text/html" data-template-name="home-z2m-power">
31
+ <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
32
+ <div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
33
+ <div class="form-row"><label for="node-input-baseTopic">Base topic</label><input type="text" id="node-input-baseTopic"></div>
34
+ <div class="form-row"><label for="node-input-friendlyName">Friendly name</label><input type="text" id="node-input-friendlyName" placeholder="the plug's name in Zigbee2MQTT"></div>
35
+ <div class="form-tips">It subscribes to the plug's topic and its availability itself: no MQTT in or change nodes.</div>
36
+ </script>
37
+
38
+ <script type="text/html" data-help-name="home-z2m-power">
39
+ <p>Reads a Zigbee2MQTT plug or meter's power, for whatever judges it: a <b>home display mode controller</b> (its
40
+ projector's power) or a <b>home scene</b> (its <b>End below</b>). Over Zigbee2MQTT's MQTT messages: no function or
41
+ change nodes, and never Home Assistant.</p>
42
+ <p>The devices: <a href="https://www.zigbee2mqtt.io/supported-devices/" target="_blank">Zigbee2MQTT's supported devices</a>.</p>
43
+ <h3>Wiring</h3>
44
+ <ol>
45
+ <li>Its output → a display controller's input (as its projector's power) or a scene's input (for End below).</li>
46
+ <li>Optional: a display controller's third output (its reading requests) → this node.</li>
47
+ </ol>
48
+ <p>Choose the <b>Broker</b> Zigbee2MQTT uses, and set the <b>Friendly name</b> (and the <b>Base topic</b> if you changed
49
+ Zigbee2MQTT's). It subscribes to <code>&lt;base&gt;/&lt;friendly name&gt;</code> and its <code>/availability</code>.</p>
50
+ <h3>Readings</h3>
51
+ <ul>
52
+ <li>Output: <code>msg.power = {kind: "observed", watts, observedAt}</code> (and <code>msg.payload</code> the watts),
53
+ from the plug's <code>power</code> only, and only when it changes. A retained (old) report is never passed on.</li>
54
+ <li>Input: <code>msg.power = {kind: "read"}</code> asks the plug for its power (<code>/get</code>), as it also does
55
+ each time the broker connects. Plugs that don't answer report on their next change.</li>
56
+ <li>Availability shows on the status (<i>offline</i>); nothing is sent for it.</li>
57
+ </ul>
58
+ </script>
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ const z2m_power_1 = require("../lib/z2m-power");
3
+ const adapter_1 = require("./adapter");
4
+ const device_side_1 = require("./device-side");
5
+ const registerZ2mPower = (RED) => {
6
+ function HomeZ2mPower(config) {
7
+ RED.nodes.createNode(this, config);
8
+ const node = this;
9
+ let device;
10
+ let broker;
11
+ try {
12
+ device = (0, z2m_power_1.normaliseZ2mPowerConfig)(config);
13
+ // Newer than the MQTT in and out way of wiring adapters: it needs its
14
+ // broker.
15
+ broker = (0, device_side_1.deviceBroker)(RED, config.broker);
16
+ if (!broker)
17
+ throw new Error("choose its MQTT broker");
18
+ }
19
+ catch (error) {
20
+ (0, adapter_1.invalidConfig)(node, error);
21
+ return;
22
+ }
23
+ const trace = { area: "", component: "z2m-power" };
24
+ node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
25
+ // Exactly its own topics: a friendly name can contain "/". On each
26
+ // connect it asks the plug for its power, which plugs that support
27
+ // /get answer; the rest report on their next change.
28
+ const topics = (0, z2m_power_1.z2mPowerTopics)(device);
29
+ const side = (0, device_side_1.deviceSide)(node, broker, topics.device, [topics.device, topics.availability], trace, (msg, send) => handle(msg, send), () => handle({ power: { kind: "read" } }, node.send.bind(node)));
30
+ function handle(msg, send) {
31
+ const result = (0, adapter_1.runReducer)(node, trace, (saved, now) => (0, z2m_power_1.transitionZ2mPower)(saved, msg, device, now));
32
+ // Its read requests to the plug through the broker; its readings, as
33
+ // msg.power, on its output.
34
+ side.publish(result.publications);
35
+ if (result.readings.length)
36
+ send([result.readings.map((reading) => ({ payload: reading.power.watts, ...reading }))]);
37
+ const state = result.state;
38
+ if (state.online === false)
39
+ node.status({ fill: "grey", shape: "ring", text: "offline" });
40
+ else if (state.watts !== null)
41
+ node.status({ fill: state.watts > 0 ? "green" : "grey", shape: "dot", text: `${state.watts} W` });
42
+ }
43
+ (0, adapter_1.onInput)(node, (msg, send) => {
44
+ // Its device's messages come from the broker: an MQTT in node wired in
45
+ // changes nothing.
46
+ if (!side.fromBroker(msg))
47
+ handle(msg, send);
48
+ });
49
+ }
50
+ RED.nodes.registerType("home-z2m-power", HomeZ2mPower);
51
+ };
52
+ module.exports = registerZ2mPower;
53
+ //# sourceMappingURL=z2m-power.js.map
@@ -0,0 +1,3 @@
1
+ import type { NodeInitializer } from "node-red";
2
+ declare const registerZ2mSensor: NodeInitializer;
3
+ export = registerZ2mSensor;