@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,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
@@ -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
@@ -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 automation",
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;
@@ -0,0 +1,69 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-z2m-sensor", {
3
+ category: "home automation",
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
+ // What the device's "occupancy" is: a PIR's motion, or on some mmWave
21
+ // sensors, presence.
22
+ occupancyIs: {value: "motion", required: true, validate: function (v) { return v === "motion" || v === "presence"; }}
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.friendlyName || "zigbee2mqtt sensor"; },
29
+ paletteLabel: "zigbee2mqtt sensor"
30
+ });
31
+ </script>
32
+
33
+ <script type="text/html" data-template-name="home-z2m-sensor">
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-baseTopic">Base topic</label><input type="text" id="node-input-baseTopic"></div>
37
+ <div class="form-row"><label for="node-input-friendlyName">Friendly name</label><input type="text" id="node-input-friendlyName" placeholder="the device's name in Zigbee2MQTT"></div>
38
+ <div class="form-row"><label for="node-input-occupancyIs">Occupancy is</label><select id="node-input-occupancyIs">
39
+ <option value="motion">motion (a PIR sensor)</option>
40
+ <option value="presence">presence (an mmWave sensor that reports it as occupancy)</option>
41
+ </select></div>
42
+ <div class="form-tips">It subscribes to the device's topic and its availability itself: no MQTT in or change nodes.</div>
43
+ </script>
44
+
45
+ <script type="text/html" data-help-name="home-z2m-sensor">
46
+ <p>Connects a Zigbee2MQTT motion, presence or light sensor to a room: its reports become the messages <b>home occupancy
47
+ fusion</b> and the <b>home motion lighting policy</b> take, over Zigbee2MQTT's MQTT messages: no function or change
48
+ nodes, and never Home Assistant.</p>
49
+ <p>The devices: <a href="https://www.zigbee2mqtt.io/supported-devices/" target="_blank">Zigbee2MQTT's supported devices</a>.</p>
50
+ <h3>Wiring</h3>
51
+ <ol>
52
+ <li>Output 1 (motion and presence) → occupancy fusion.</li>
53
+ <li>Output 2 (light level) → the motion lighting policy.</li>
54
+ </ol>
55
+ <p>Choose the <b>Broker</b> Zigbee2MQTT uses, and set the <b>Friendly name</b> (and the <b>Base topic</b> if you changed
56
+ Zigbee2MQTT's). It subscribes to <code>&lt;base&gt;/&lt;friendly name&gt;</code> and its <code>/availability</code>.</p>
57
+ <h3>Readings</h3>
58
+ <ul>
59
+ <li><code>occupancy</code> → <code>{source: "motion", payload: true | false}</code> on output 1, or <code>"presence"</code>
60
+ with <b>Occupancy is</b> set to presence; <code>presence</code> → <code>{source: "presence", payload}</code>.</li>
61
+ <li><code>illuminance_lux</code>, or else <code>illuminance</code>, → <code>{source: "illuminance", payload: &lt;lux&gt;}</code>
62
+ on output 2.</li>
63
+ <li>Only a value that changed is sent, so a battery or temperature report sends nothing.</li>
64
+ <li>A retained occupancy or presence (with retain set for the device in Zigbee2MQTT) is never acted on: after a
65
+ restart it is an old reading. The next report the sensor sends is passed on.</li>
66
+ <li>Availability shows on the status (<i>offline</i>); nothing is sent for it. Battery sensors can't be asked for a
67
+ reading, so after a restart the room learns the sensor's state on its next change.</li>
68
+ </ul>
69
+ </script>
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ const z2m_sensor_1 = require("../lib/z2m-sensor");
3
+ const adapter_1 = require("./adapter");
4
+ const device_side_1 = require("./device-side");
5
+ const registerZ2mSensor = (RED) => {
6
+ function HomeZ2mSensor(config) {
7
+ RED.nodes.createNode(this, config);
8
+ const node = this;
9
+ let device;
10
+ let broker;
11
+ try {
12
+ device = (0, z2m_sensor_1.normaliseZ2mSensorConfig)(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-sensor" };
24
+ node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
25
+ // Exactly its own topics: a friendly name can contain "/". Battery
26
+ // sensors can't be asked for a reading, so there is nothing to read on
27
+ // connect: the room learns the sensor's state on its next change.
28
+ const topics = (0, z2m_sensor_1.z2mSensorTopics)(device);
29
+ const side = (0, device_side_1.deviceSide)(node, broker, topics.device, [topics.device, topics.availability], trace, (msg, send) => handle(msg, send));
30
+ function handle(msg, send) {
31
+ const result = (0, adapter_1.runReducer)(node, trace, (saved) => (0, z2m_sensor_1.transitionZ2mSensor)(saved, msg, device));
32
+ // Output 1: motion and presence, for occupancy fusion. Output 2: the
33
+ // light level, for the motion lighting policy.
34
+ const outputs = [
35
+ result.occupancy.length ? result.occupancy.map((reading) => ({ ...reading })) : null,
36
+ result.light.length ? result.light.map((reading) => ({ ...reading })) : null
37
+ ];
38
+ if (outputs.some((output) => output !== null))
39
+ send(outputs);
40
+ const state = result.state;
41
+ if (state.online === false) {
42
+ node.status({ fill: "grey", shape: "ring", text: "offline" });
43
+ }
44
+ else {
45
+ const occupied = state.motion === true || state.presence === true;
46
+ const known = state.motion !== null || state.presence !== null;
47
+ const parts = [known ? (occupied ? "occupied" : "clear") : "", state.illuminance !== null ? `${state.illuminance} lx` : ""].filter(Boolean);
48
+ if (parts.length)
49
+ node.status({ fill: occupied ? "green" : "grey", shape: "dot", text: parts.join(" · ") });
50
+ }
51
+ }
52
+ (0, adapter_1.onInput)(node, (msg, send) => {
53
+ // Its device's messages come from the broker: an MQTT in node wired in
54
+ // changes nothing.
55
+ if (!side.fromBroker(msg))
56
+ handle(msg, send);
57
+ });
58
+ }
59
+ RED.nodes.registerType("home-z2m-sensor", HomeZ2mSensor);
60
+ };
61
+ module.exports = registerZ2mSensor;
62
+ //# sourceMappingURL=z2m-sensor.js.map
@@ -3,7 +3,7 @@
3
3
  "id": "example-scene-comment",
4
4
  "type": "comment",
5
5
  "name": "Scene example",
6
- "info": "Needs: No devices: Debug nodes stand in for your room lighting controller and motion lighting policy.\n\nOne scene, \"Exercise mode\": while it is on, it holds the room's main light off and its tv socket on, and pauses motion lighting. It ends by request, by its safety timer (4 hours), or when the trainer's power falls below 20 W for this flow's end trigger.\n\nWire output 1 to your room lighting controller, whose Targets JSON names main and tv (mark the socket \"onOffOnly\": true), and set each light's area in the scene's Lights to the room's Area (a room acts only on a scene's lights for its own Area). Wire output 2 to your motion lighting policy. To start and stop it from Home Assistant, give it an area and set Publish to MQTT state and Home Assistant discovery: it reads home/<area>/scene/exercise_mode/set from the broker. Replace the \"trainer power\" inject with your power reading: the switch and change nodes are the end trigger, so the condition is yours to set.\n\nWhen it ends, the room gives each light back what it was before the scene, and motion lighting resumes.\n\nBefore deploying, open the \"your MQTT broker\" config node (any node's Broker setting) and set your broker's host: every node here that talks MQTT subscribes and publishes through it, with no MQTT in, MQTT out or status nodes.",
6
+ "info": "Needs: No devices: Debug nodes stand in for your room lighting controller and motion lighting policy.\n\nOne scene, \"Exercise mode\": while it is on, it holds the room's main light off and its tv socket on, and pauses motion lighting. It ends by request, by its safety timer (4 hours), or when a device's power, from a power meter on its plug, has been used and then stays below 20 W for a minute (its End below).\n\nWire output 1 to your room lighting controller, whose Targets JSON names main and tv (mark the socket \"onOffOnly\": true), and set each light's area in the scene's Lights to the room's Area (a room acts only on a scene's lights for its own Area). Wire output 2 to your motion lighting policy. To start and stop it from Home Assistant, give it an area and set Publish to MQTT state and Home Assistant discovery: it reads home/<area>/scene/exercise_mode/set from the broker. Replace the \"a device's power\" inject with a power meter node on the device's plug (such as a zigbee2mqtt power node), wired to the scene; set End below for your device, or clear it for no power end.\n\nWhen it ends, the room gives each light back what it was before the scene, and motion lighting resumes.\n\nBefore deploying, open the \"your MQTT broker\" config node (any node's Broker setting) and set your broker's host: every node here that talks MQTT subscribes and publishes through it, with no MQTT in, MQTT out or status nodes.",
7
7
  "x": 150,
8
8
  "y": 40,
9
9
  "wires": []
@@ -59,12 +59,12 @@
59
59
  {
60
60
  "id": "example-scene-power",
61
61
  "type": "inject",
62
- "name": "trainer power",
62
+ "name": "a device's power: 5 W",
63
63
  "props": [
64
64
  {
65
- "p": "payload",
66
- "v": "5",
67
- "vt": "num"
65
+ "p": "power",
66
+ "v": "{\"kind\":\"observed\",\"watts\":5}",
67
+ "vt": "json"
68
68
  }
69
69
  ],
70
70
  "repeat": "",
@@ -74,56 +74,6 @@
74
74
  "topic": "",
75
75
  "x": 140,
76
76
  "y": 240,
77
- "wires": [
78
- [
79
- "example-scene-below"
80
- ]
81
- ]
82
- },
83
- {
84
- "id": "example-scene-below",
85
- "type": "switch",
86
- "name": "below 20 W",
87
- "property": "payload",
88
- "propertyType": "msg",
89
- "rules": [
90
- {
91
- "t": "lt",
92
- "v": "20",
93
- "vt": "num"
94
- }
95
- ],
96
- "checkall": "true",
97
- "repair": false,
98
- "outputs": 1,
99
- "x": 330,
100
- "y": 240,
101
- "wires": [
102
- [
103
- "example-scene-to-end"
104
- ]
105
- ]
106
- },
107
- {
108
- "id": "example-scene-to-end",
109
- "type": "change",
110
- "name": "end: trainer off",
111
- "rules": [
112
- {
113
- "t": "set",
114
- "p": "scene",
115
- "pt": "msg",
116
- "to": "{\"kind\":\"end\",\"by\":\"trainer off\"}",
117
- "tot": "json"
118
- }
119
- ],
120
- "action": "",
121
- "property": "",
122
- "from": "",
123
- "to": "",
124
- "reg": false,
125
- "x": 520,
126
- "y": 240,
127
77
  "wires": [
128
78
  [
129
79
  "example-scene-scene"
@@ -151,7 +101,9 @@
151
101
  []
152
102
  ],
153
103
  "broker": "example-mqtt-broker",
154
- "homeAssistant": "off"
104
+ "homeAssistant": "off",
105
+ "endBelowWatts": 20,
106
+ "endBelowSeconds": 60
155
107
  },
156
108
  {
157
109
  "id": "example-scene-rooms",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avantics/node-red-home-automation",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "Deterministic home automation components for Node-RED",
5
5
  "keywords": [
6
6
  "node-red",
@@ -67,7 +67,12 @@
67
67
  "home-house-schedule-mqtt": "dist/nodes/house-schedule-mqtt.js",
68
68
  "home-shelly-cover": "dist/nodes/shelly-cover.js",
69
69
  "home-shelly-switch": "dist/nodes/shelly-switch.js",
70
- "home-z2m-cover": "dist/nodes/z2m-cover.js"
70
+ "home-z2m-cover": "dist/nodes/z2m-cover.js",
71
+ "home-wled": "dist/nodes/wled.js",
72
+ "home-z2m-sensor": "dist/nodes/z2m-sensor.js",
73
+ "home-everything-presence-one": "dist/nodes/everything-presence-one.js",
74
+ "home-apollo-r-pro-1": "dist/nodes/apollo-r-pro-1.js",
75
+ "home-z2m-power": "dist/nodes/z2m-power.js"
71
76
  }
72
77
  },
73
78
  "devDependencies": {