@avantics/node-red-home-automation 4.0.3 → 6.0.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 (116) hide show
  1. package/README.md +447 -64
  2. package/contract-examples/room-lighting.mjs +39 -27
  3. package/contract-examples/switch-gestures.mjs +1 -1
  4. package/contract-examples/volume-ownership.mjs +6 -5
  5. package/dist/lib/activity-lighting-controller.d.ts +9 -2
  6. package/dist/lib/activity-lighting-controller.js +107 -19
  7. package/dist/lib/adopted-request.d.ts +17 -0
  8. package/dist/lib/adopted-request.js +61 -7
  9. package/dist/lib/avr-controller.d.ts +9 -3
  10. package/dist/lib/avr-controller.js +71 -24
  11. package/dist/lib/avr-publishing.d.ts +3 -3
  12. package/dist/lib/avr-publishing.js +11 -5
  13. package/dist/lib/backlighting-controller.d.ts +2 -0
  14. package/dist/lib/backlighting-controller.js +27 -7
  15. package/dist/lib/circadian-policy.d.ts +47 -0
  16. package/dist/lib/circadian-policy.js +111 -0
  17. package/dist/lib/circadian-publishing.d.ts +33 -0
  18. package/dist/lib/circadian-publishing.js +154 -0
  19. package/dist/lib/circadian-schedule.d.ts +4 -0
  20. package/dist/lib/circadian-schedule.js +12 -0
  21. package/dist/lib/command-echo.d.ts +8 -1
  22. package/dist/lib/command-echo.js +37 -6
  23. package/dist/lib/cover-controller.js +4 -0
  24. package/dist/lib/cover-publishing.js +1 -1
  25. package/dist/lib/denon-protocol.d.ts +5 -1
  26. package/dist/lib/denon-protocol.js +27 -11
  27. package/dist/lib/display-mode-controller.d.ts +12 -5
  28. package/dist/lib/display-mode-controller.js +181 -87
  29. package/dist/lib/enable-input.d.ts +3 -0
  30. package/dist/lib/enable-input.js +18 -0
  31. package/dist/lib/house-schedule-publishing.js +1 -1
  32. package/dist/lib/house-schedule.js +2 -2
  33. package/dist/lib/light-contract.d.ts +53 -0
  34. package/dist/lib/light-contract.js +11 -0
  35. package/dist/lib/light-styling.d.ts +2 -2
  36. package/dist/lib/light-styling.js +5 -4
  37. package/dist/lib/motion-policy.d.ts +0 -1
  38. package/dist/lib/motion-policy.js +9 -8
  39. package/dist/lib/motion-publishing.js +3 -2
  40. package/dist/lib/mqtt-message.d.ts +6 -0
  41. package/dist/lib/mqtt-message.js +21 -0
  42. package/dist/lib/occupancy-publishing.js +1 -1
  43. package/dist/lib/power-reading.d.ts +5 -0
  44. package/dist/lib/power-reading.js +13 -0
  45. package/dist/lib/room-controller.d.ts +39 -29
  46. package/dist/lib/room-controller.js +314 -192
  47. package/dist/lib/room-lighting-discovery.d.ts +0 -14
  48. package/dist/lib/room-lighting-discovery.js +20 -126
  49. package/dist/lib/room-publishing.d.ts +10 -12
  50. package/dist/lib/room-publishing.js +65 -125
  51. package/dist/lib/shelly-cover.d.ts +44 -0
  52. package/dist/lib/shelly-cover.js +153 -0
  53. package/dist/lib/shelly-gen2.d.ts +25 -0
  54. package/dist/lib/shelly-gen2.js +58 -0
  55. package/dist/lib/shelly-switch.d.ts +95 -0
  56. package/dist/lib/shelly-switch.js +237 -0
  57. package/dist/lib/source-capability-controller.d.ts +2 -0
  58. package/dist/lib/source-capability-controller.js +27 -6
  59. package/dist/lib/switch-policy.d.ts +1 -1
  60. package/dist/lib/switch-policy.js +1 -1
  61. package/dist/lib/theatre-requests.d.ts +29 -0
  62. package/dist/lib/theatre-requests.js +89 -0
  63. package/dist/lib/theatre-state-contract.d.ts +5 -22
  64. package/dist/lib/theatre-state-contract.js +30 -77
  65. package/dist/lib/toggle-power.d.ts +41 -0
  66. package/dist/lib/toggle-power.js +74 -0
  67. package/dist/lib/topic-names.d.ts +1 -0
  68. package/dist/lib/topic-names.js +7 -0
  69. package/dist/lib/{display-transport.d.ts → transports/display-transport.d.ts} +1 -1
  70. package/dist/lib/{display-transport.js → transports/display-transport.js} +32 -7
  71. package/dist/lib/z2m-cover.d.ts +49 -0
  72. package/dist/lib/z2m-cover.js +120 -0
  73. package/dist/lib/z2m-light-adapter.d.ts +62 -0
  74. package/dist/lib/z2m-light-adapter.js +195 -0
  75. package/dist/lib/z2m-light.d.ts +8 -0
  76. package/dist/lib/z2m-light.js +61 -3
  77. package/dist/nodes/activity-lighting-controller.html +20 -3
  78. package/dist/nodes/activity-lighting-controller.js +21 -0
  79. package/dist/nodes/avr-controller.html +25 -6
  80. package/dist/nodes/avr-controller.js +16 -6
  81. package/dist/nodes/circadian-policy.d.ts +3 -0
  82. package/dist/nodes/circadian-policy.html +140 -0
  83. package/dist/nodes/circadian-policy.js +162 -0
  84. package/dist/nodes/cover-controller.html +4 -3
  85. package/dist/nodes/display-mode-controller.html +58 -11
  86. package/dist/nodes/display-mode-controller.js +19 -6
  87. package/dist/nodes/house-schedule.html +3 -3
  88. package/dist/nodes/motion-policy.html +5 -2
  89. package/dist/nodes/motion-policy.js +3 -0
  90. package/dist/nodes/refused-enable.d.ts +7 -0
  91. package/dist/nodes/refused-enable.js +24 -0
  92. package/dist/nodes/room-controller.html +215 -82
  93. package/dist/nodes/room-controller.js +71 -83
  94. package/dist/nodes/shelly-cover.d.ts +3 -0
  95. package/dist/nodes/shelly-cover.html +65 -0
  96. package/dist/nodes/shelly-cover.js +34 -0
  97. package/dist/nodes/shelly-switch.d.ts +3 -0
  98. package/dist/nodes/shelly-switch.html +82 -0
  99. package/dist/nodes/shelly-switch.js +48 -0
  100. package/dist/nodes/theatre-state-contract.html +4 -3
  101. package/dist/nodes/z2m-cover.d.ts +3 -0
  102. package/dist/nodes/z2m-cover.html +68 -0
  103. package/dist/nodes/z2m-cover.js +41 -0
  104. package/dist/nodes/z2m-light.d.ts +3 -0
  105. package/dist/nodes/z2m-light.html +72 -0
  106. package/dist/nodes/z2m-light.js +50 -0
  107. package/examples/Cover control.json +24 -56
  108. package/examples/Home theatre activity.json +54 -9
  109. package/examples/Home theatre equipment.json +4 -4
  110. package/examples/House schedule.json +106 -24
  111. package/examples/Room lighting.json +54 -11
  112. package/examples/Shelly cover.json +252 -0
  113. package/examples/Shelly switch.json +197 -0
  114. package/package.json +13 -4
  115. package/dist/lib/room-schedule.d.ts +0 -8
  116. package/dist/lib/room-schedule.js +0 -41
@@ -7,6 +7,7 @@ const topic_names_1 = require("../lib/topic-names");
7
7
  const adapter_1 = require("./adapter");
8
8
  const publishing_node_1 = require("../lib/publishing-node");
9
9
  const publishing_lifecycle_1 = require("./publishing-lifecycle");
10
+ const refused_enable_1 = require("./refused-enable");
10
11
  const registerMotionPolicy = (RED) => {
11
12
  function HomeMotionLightingPolicy(config) {
12
13
  RED.nodes.createNode(this, config);
@@ -100,8 +101,10 @@ const registerMotionPolicy = (RED) => {
100
101
  lifecycle.publish(send, (0, motion_publishing_1.motionStateOutputs)(publishing, result.state));
101
102
  }
102
103
  updateStatus(result.status);
104
+ showRefused(result.traces);
103
105
  return result;
104
106
  }
107
+ const showRefused = (0, refused_enable_1.refusedEnables)(node);
105
108
  // With a configured context store (see the README) the node's state
106
109
  // survives a redeploy or restart, but timers never do: a pending
107
110
  // off-timer is re-armed. Without one, it starts with nothing saved, and
@@ -0,0 +1,7 @@
1
+ import type { Node } from "node-red";
2
+ interface Trace {
3
+ reason: string | null;
4
+ details: unknown;
5
+ }
6
+ export declare function refusedEnables(node: Node, named?: (source: string) => string): (traces: Trace[]) => boolean;
7
+ export {};
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.refusedEnables = refusedEnables;
4
+ const enable_input_1 = require("../lib/enable-input");
5
+ // `named` gives the input's name as the warning says it, such as
6
+ // "circadian's enabled".
7
+ function refusedEnables(node, named = (source) => source) {
8
+ const warned = new Set();
9
+ // Shows the first refusal among these traces, if any; true when there was
10
+ // one, so the caller leaves the status as set.
11
+ return function show(traces) {
12
+ const refused = traces.find(({ reason }) => reason === enable_input_1.NOT_TRUE_OR_FALSE);
13
+ if (!refused)
14
+ return false;
15
+ const { source, payload } = refused.details;
16
+ if (!warned.has(source)) {
17
+ warned.add(source);
18
+ node.warn(`${named(source)} takes only true or false: ${payload} was refused, and nothing changed`);
19
+ }
20
+ node.status({ fill: "yellow", shape: "ring", text: `refused ${source} ${payload}: send true or false` });
21
+ return true;
22
+ };
23
+ }
24
+ //# sourceMappingURL=refused-enable.js.map
@@ -3,6 +3,82 @@
3
3
  // A setting is on unless it was explicitly switched off; null ("not set")
4
4
  // shows as ticked.
5
5
  function on(value) { return value !== false && value !== "false"; }
6
+ // Each old setting, and the circadian lighting policy field it goes into.
7
+ var MOVED = {
8
+ houseSchedule: "Schedule", wakeTime: "Wake time", bedTime: "Bed time",
9
+ maxBrightnessPct: "Daytime brightness %", maxColorTempKelvin: "Daytime kelvin",
10
+ sleepBrightnessPct: "Sleep brightness %", sleepColorTempKelvin: "Sleep kelvin",
11
+ refreshTransitionSeconds: "Restyle transition (s)", refreshSeconds: "Restyle interval (s)", initialSleep: "Start in sleep mode"
12
+ };
13
+ function given(value) { return value !== undefined && value !== null && value !== ""; }
14
+ function moved(value) { return !given(value); }
15
+ function parsedTargets(json) {
16
+ try { var targets = JSON.parse(json || "[]"); return Array.isArray(targets) ? targets : []; } catch (e) { return []; }
17
+ }
18
+ // A room saved before 6.0 named each light's Zigbee2MQTT topics. Each
19
+ // target with topics, and the zigbee2mqtt light that replaces them; null
20
+ // when they aren't <base>/<name> and <base>/<name>/set, to set up by hand.
21
+ function lightPlan(targets) {
22
+ return targets.filter(function (target) {
23
+ return target && (target.stateTopic !== undefined || target.commandTopic !== undefined);
24
+ }).map(function (target) {
25
+ var state = typeof target.stateTopic === "string" ? target.stateTopic : "";
26
+ var slash = state.indexOf("/");
27
+ var z2m = target.commandTopic === state + "/set" && slash > 0 && slash < state.length - 1
28
+ ? {baseTopic: state.slice(0, slash), friendlyName: state.slice(slash + 1)}
29
+ : null;
30
+ return {id: String(target.id), stateTopic: target.stateTopic, commandTopic: target.commandTopic, z2m: z2m};
31
+ });
32
+ }
33
+ // The targets as 6.0 has them: ids, and onOffOnly, for every light whose
34
+ // topics were Zigbee2MQTT's. A light whose topics weren't keeps them: the
35
+ // room stays refused, naming it, until its adapter is set up by hand and
36
+ // its topics removed, so it can't be lost silently.
37
+ function neutralTargets(targets) {
38
+ var flagged = lightPlan(targets).filter(function (entry) { return !entry.z2m; }).map(function (entry) { return entry.id; });
39
+ return targets.map(function (target) {
40
+ if (target && flagged.indexOf(String(target.id)) >= 0) return target;
41
+ return target && target.onOffOnly === true ? {id: target.id, onOffOnly: true} : {id: target && target.id};
42
+ });
43
+ }
44
+ // Adds a zigbee2mqtt light for each light the plan can, wired to the room
45
+ // (its light commands in, readings back) and to the MQTT out nodes the
46
+ // room publishes through, with an MQTT in node on each light's topics
47
+ // when their broker is known. One undo step.
48
+ function createLights(roomId, plan) {
49
+ var room = RED.nodes.node(roomId);
50
+ if (!room) return 0;
51
+ var outs = [];
52
+ RED.nodes.eachLink(function (link) {
53
+ if (link.source === room && link.sourcePort === 0 && link.target.type === "mqtt out") outs.push(link.target);
54
+ });
55
+ var broker = outs.length ? outs[0].broker : "";
56
+ var add = [];
57
+ plan.filter(function (entry) { return entry.z2m; }).forEach(function (entry, index) {
58
+ var lightId = RED.nodes.id();
59
+ var y = room.y + 80 * (index + 1);
60
+ add.push({id: lightId, type: "home-z2m-light", z: room.z, x: room.x + 260, y: y, name: "", target: entry.id,
61
+ baseTopic: entry.z2m.baseTopic, friendlyName: entry.z2m.friendlyName, group: false, wires: [[], []]});
62
+ if (broker) {
63
+ add.push({id: RED.nodes.id(), type: "mqtt in", z: room.z, x: room.x + 40, y: y, name: "", broker: broker,
64
+ topic: entry.z2m.baseTopic + "/" + entry.z2m.friendlyName + "/#", qos: "1", datatype: "auto-detect", nl: false,
65
+ rap: true, rh: 0, inputs: 0, wires: [[lightId]]});
66
+ }
67
+ });
68
+ if (!add.length) return 0;
69
+ var wasDirty = RED.nodes.dirty();
70
+ var imported = RED.nodes.import(add, {generateIds: false});
71
+ var links = imported.links.slice();
72
+ imported.nodes.filter(function (n) { return n.type === "home-z2m-light"; }).forEach(function (light) {
73
+ [{source: room, sourcePort: 1, target: light}, {source: light, sourcePort: 1, target: room}].concat(outs.map(function (out) {
74
+ return {source: light, sourcePort: 0, target: out};
75
+ })).forEach(function (link) { RED.nodes.addLink(link); links.push(link); });
76
+ });
77
+ RED.history.push({t: "add", nodes: imported.nodes.map(function (n) { return n.id; }), links: links, dirty: wasDirty});
78
+ RED.nodes.dirty(true);
79
+ RED.view.redraw(true);
80
+ return imported.nodes.filter(function (n) { return n.type === "home-z2m-light"; }).length;
81
+ }
6
82
  RED.nodes.registerType("home-room-lighting-controller", {
7
83
  category: "home automation",
8
84
  color: "#ffd27f",
@@ -27,23 +103,27 @@
27
103
  // before this setting, which keeps its area-named entities. New nodes
28
104
  // name them after the node (onadd), so renaming the area keeps them.
29
105
  idScheme: {value: null},
30
- // Where wake and bed times come from: null (not set) is this room.
31
- // The house schedule it follows; none: its own times. Node-RED's
32
- // editor offers an existing schedule first for a new room.
33
- houseSchedule: {value: "", type: "home-house-schedule", required: false},
34
106
  displayName: {value: ""},
35
107
  discoveryPrefix: {value: "homeassistant", required: true, validate: function (v) { var prefix = String(v || "").trim().replace(/^\/+|\/+$/g, ""); return Boolean(prefix) && !/[+#]/.test(prefix); }},
36
108
  targets: {value: "[]", required: true, validate: function (v) { try { JSON.parse(v); return true; } catch (e) { return false; } }},
37
- maxBrightnessPct: {value: 100, required: true, validate: RED.validators.number()},
38
- maxColorTempKelvin: {value: 6500, required: true, validate: RED.validators.number()},
39
- sleepBrightnessPct: {value: 1, required: true, validate: RED.validators.number()},
40
- sleepColorTempKelvin: {value: 2200, required: true, validate: RED.validators.number()},
41
109
  initialTransitionSeconds: {value: 1, required: true, validate: RED.validators.number()},
42
- refreshTransitionSeconds: {value: 60, required: true, validate: RED.validators.number()},
43
- refreshSeconds: {value: 60, required: true, validate: RED.validators.number()},
44
- initialSleep: {value: false},
45
- wakeTime: {value: "07:00", required: true, validate: function (v) { return /^([01]\d|2[0-3]):[0-5]\d$/.test(v); }},
46
- bedTime: {value: "23:00", required: true, validate: function (v) { return /^([01]\d|2[0-3]):[0-5]\d$/.test(v); }}
110
+ // The circadian settings of a room saved before 6.0, which moved to
111
+ // the circadian lighting policy. Kept here, with no form rows, so the
112
+ // editor carries them: without them, a deploy from the editor would
113
+ // make an unmigrated room valid and quietly unstyled. Each shows the
114
+ // room as invalid until the dialog is saved, which clears them.
115
+ maxBrightnessPct: {value: "", validate: moved},
116
+ maxColorTempKelvin: {value: "", validate: moved},
117
+ sleepBrightnessPct: {value: "", validate: moved},
118
+ sleepColorTempKelvin: {value: "", validate: moved},
119
+ refreshTransitionSeconds: {value: "", validate: moved},
120
+ refreshSeconds: {value: "", validate: moved},
121
+ initialSleep: {value: "", validate: moved},
122
+ wakeTime: {value: "", validate: moved},
123
+ bedTime: {value: "", validate: moved},
124
+ // The house schedule it followed, kept the same way (not as a
125
+ // config-node reference, as the room no longer uses one).
126
+ houseSchedule: {value: "", validate: moved}
47
127
  },
48
128
  onadd: function () {
49
129
  if (this.name !== "_DEFAULT_") return;
@@ -65,9 +145,48 @@
65
145
  }
66
146
  $("#node-input-publishState, #node-input-discovery").on("change", follow);
67
147
  follow();
148
+ // A room saved before 6.0: its circadian settings, to copy into a
149
+ // circadian lighting policy.
150
+ var old = Object.keys(MOVED).filter(function (key) { return given(node[key]); });
151
+ $("#room-moved-circadian").toggle(old.length > 0);
152
+ $("#room-moved-circadian-values").text(old.map(function (key) {
153
+ var value = node[key];
154
+ if (key === "houseSchedule") {
155
+ var schedule = RED.nodes.node(value);
156
+ value = schedule ? (schedule.name || schedule.id) : value + " (no longer in the flows)";
157
+ }
158
+ return MOVED[key] + " " + value;
159
+ }).join(", "));
160
+ // Its lights' topics, which move to a zigbee2mqtt light each.
161
+ var plan = lightPlan(parsedTargets(node.targets));
162
+ $("#room-moved-lights").toggle(plan.length > 0);
163
+ $("#room-moved-lights-list").empty();
164
+ plan.forEach(function (entry) {
165
+ $("<li>").text(entry.id + ": " + (entry.z2m
166
+ ? "zigbee2mqtt light, base topic " + entry.z2m.baseTopic + ", friendly name " + entry.z2m.friendlyName
167
+ : "topics " + entry.stateTopic + " and " + entry.commandTopic + " aren't Zigbee2MQTT's: set it up by hand on the neutral light contract")).appendTo("#room-moved-lights-list");
168
+ });
169
+ $("#room-create-lights").toggle(plan.some(function (entry) { return entry.z2m; })).off("click").on("click", function (event) {
170
+ event.preventDefault();
171
+ var made = createLights(node.id, plan);
172
+ $(this).prop("disabled", true).text(made + " zigbee2mqtt light node" + (made === 1 ? "" : "s") + " added");
173
+ });
174
+ },
175
+ // Saving the dialog migrates the room: its old circadian settings go.
176
+ oneditsave: function () {
177
+ var node = this;
178
+ Object.keys(MOVED).forEach(function (key) { node[key] = ""; });
179
+ // Its targets become ids: their topics are the lights' adapters' now.
180
+ var targets = parsedTargets($("#node-input-targets").val());
181
+ if (lightPlan(targets).length) $("#node-input-targets").val(JSON.stringify(neutralTargets(targets)));
68
182
  },
183
+ // For the editor's tests.
184
+ lightPlan: lightPlan,
185
+ neutralTargets: neutralTargets,
186
+ createLights: createLights,
69
187
  inputs: 1,
70
- outputs: 1,
188
+ outputs: 3,
189
+ outputLabels: ["MQTT publications (MQTT out)", "light commands (to each light's adapter)", "light readings (to activity lighting)"],
71
190
  icon: "font-awesome/fa-lightbulb-o",
72
191
  label: function () { return this.name || (this.area ? this.area + " " : "") + "lighting controller"; }
73
192
  });
@@ -75,6 +194,21 @@
75
194
  </script>
76
195
 
77
196
  <script type="text/html" data-template-name="home-room-lighting-controller">
197
+ <div class="form-tips" id="room-moved-circadian" style="display:none; margin-bottom:12px;">
198
+ <b>Circadian lighting moved to its own node in 6.0.</b> Add a <i>circadian lighting policy</i>, wire its first
199
+ output to this room, and set its fields to this room's settings from before: <span id="room-moved-circadian-values"></span>.
200
+ A room that should stay unstyled needs no policy. Saving this dialog then clears them here, and the room runs again.
201
+ </div>
202
+ <div class="form-tips" id="room-moved-lights" style="display:none; margin-bottom:12px;">
203
+ <b>Lights are reached through light adapters in 6.0.</b> Each light below needs a <i>zigbee2mqtt light</i> node:
204
+ <ul id="room-moved-lights-list"></ul>
205
+ <button type="button" class="red-ui-button" id="room-create-lights">Create Zigbee2MQTT light nodes</button>
206
+ It adds and wires one per light (and an MQTT in node on its topics when the room's MQTT out shows the broker).
207
+ Delete the old MQTT in nodes on the lights' state and command topics. Saving this dialog keeps only each
208
+ Zigbee2MQTT light's id in Targets JSON. A light whose topics aren't Zigbee2MQTT's keeps them, and the room stays
209
+ an invalid configuration naming it: set up its adapter by hand on the neutral light contract, then remove its
210
+ topics from Targets JSON.
211
+ </div>
78
212
  <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
79
213
  <div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area" placeholder="needed when publishing"></div>
80
214
  <div class="form-row"><label for="node-input-publishState">Publish state over MQTT</label><input type="checkbox" id="node-input-publishState" style="display:inline-block; width:auto;"></div>
@@ -82,104 +216,103 @@
82
216
  <div class="form-row"><label for="node-input-displayName">Display name</label><input type="text" id="node-input-displayName"></div>
83
217
  <div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
84
218
  <div class="form-row"><label for="node-input-targets">Targets JSON</label><input type="text" id="node-input-targets"></div>
85
- <div class="form-row"><label for="node-input-maxBrightnessPct">Daytime brightness %</label><input type="number" id="node-input-maxBrightnessPct"></div>
86
- <div class="form-row"><label for="node-input-maxColorTempKelvin">Daytime kelvin</label><input type="number" id="node-input-maxColorTempKelvin"></div>
87
- <div class="form-row"><label for="node-input-sleepBrightnessPct">Sleep brightness %</label><input type="number" id="node-input-sleepBrightnessPct"></div>
88
- <div class="form-row"><label for="node-input-sleepColorTempKelvin">Sleep kelvin</label><input type="number" id="node-input-sleepColorTempKelvin"></div>
89
- <div class="form-row"><label for="node-input-initialTransitionSeconds">Initial transition seconds</label><input type="number" id="node-input-initialTransitionSeconds"></div>
90
- <div class="form-row"><label for="node-input-refreshTransitionSeconds">Refresh transition seconds</label><input type="number" id="node-input-refreshTransitionSeconds"></div>
91
- <div class="form-row"><label for="node-input-refreshSeconds">Refresh interval seconds</label><input type="number" id="node-input-refreshSeconds"></div>
92
- <div class="form-row"><label for="node-input-houseSchedule">Schedule</label><input type="text" id="node-input-houseSchedule"></div>
93
- <div class="form-row"><label for="node-input-wakeTime">Wake time</label><input type="text" id="node-input-wakeTime" placeholder="07:00"></div>
94
- <div class="form-row"><label for="node-input-bedTime">Bed time</label><input type="text" id="node-input-bedTime" placeholder="23:00"></div>
95
- <div class="form-row"><label for="node-input-initialSleep">Initial sleep mode</label><input type="checkbox" id="node-input-initialSleep" style="display:inline-block; width:auto;"></div>
219
+ <div class="form-row"><label for="node-input-initialTransitionSeconds">Turn-on transition seconds</label><input type="number" id="node-input-initialTransitionSeconds"></div>
96
220
  </script>
97
221
 
98
222
  <script type="text/html" data-help-name="home-room-lighting-controller">
99
- <p>Owns room MQTT commands, adaptive colour and brightness, manual overrides, discovery and bounded tracing.</p>
223
+ <p>Owns a room's lights: it turns intents from policies (motion, wall switches, activities) into light commands,
224
+ keeps track of who controls each light, and styles the lights it controls with the style it is sent.</p>
225
+ <h3>Style</h3>
226
+ <p>Wire a <i>circadian lighting policy</i> into the room to style its lights over the day. The room keeps the
227
+ latest style it was sent and uses it when a light it controls comes on with no values given (a motion ON, a
228
+ wall-switch press), on each new style for lights that are on, after someone else's bare ON, and when an owner
229
+ releases a light. A style never switches a light on or off and never reaches a light that an owner holds or a
230
+ person set. With no style, or once a style has run out, the lights just go on and off. Any node may send a style:
231
+ <code>msg.lighting = {kind: "style", values: {brightnessPct, colorTempKelvin} | null, transitionSeconds, until}</code>.</p>
232
+ <p><b>From 5.x:</b> circadian lighting, sleep, the wake and bed times and the house schedule moved to the circadian
233
+ lighting policy in 6.0. A room saved before 6.0 is an invalid configuration until it is migrated: add a circadian
234
+ lighting policy wired to the room, with the room's old settings (the dialog lists them), then open and save the
235
+ room. Circadian, sleep and schedule messages sent to the room are ignored, with a warning.</p>
236
+ <h3>Lights and their adapters</h3>
237
+ <p>The room reaches each light through an adapter, such as a <i>zigbee2mqtt light</i> node per light: wire the
238
+ room's second output (its light commands, <code>msg.light</code>) into every adapter, and each adapter's readings
239
+ back into the room. The adapter tells the room's own commands from other people's, and the room acts on someone
240
+ else's: a command with values makes the light manual, and someone else's bare ON is restyled at most once every 5
241
+ seconds, so it never answers itself in a loop. At its startup message the room asks each light for a reading. A
242
+ light's availability, as its adapter reports it, is shown on its control state and in the status, and changes
243
+ nothing. For a light that isn't Zigbee2MQTT's, any flow that answers <code>msg.light</code> commands with
244
+ <code>msg.light</code> readings works in the adapter's place (see the README's neutral light contract).</p>
100
245
  <h3>Publishing</h3>
101
- <p>Wire its commands to MQTT out unchanged. It watches each light's command topic to tell its own commands from
102
- other people's, so a function that rewrites them on the way makes them look like someone else's. A bare ON or OFF
103
- that arrives within 5 seconds of one of its own commands with that power, before that command has come back on the
104
- topic, is taken as that command (traced as <code>mutated-own-command</code>), and it restyles a light after someone else's bare ON at most once every 5
105
- seconds, so it never answers itself in a loop.</p>
106
- <p>The room always commands its lights on each target's own command topic. Two settings add what it publishes
246
+ <p>Two settings add what it publishes
107
247
  for other systems to see; both are named after the <b>Area</b>, which is needed only when one of them is on. Topics
108
248
  and IDs use it in lowercase, with spaces and other characters (anything but letters, digits, <code>_</code> and
109
249
  <code>-</code>) as <code>_</code>: <i>Living Room</i> publishes under <code>home/living_room/…</code>.</p>
110
250
  <dl class="message-properties">
111
251
  <dt>Publish state over MQTT</dt><dd>each light's control state on
112
- <code>home/&lt;area&gt;/lighting/&lt;target&gt;/control</code> and the circadian state on
113
- <code>home/&lt;area&gt;/circadian/state</code>. It also publishes a retained <code>online</code> on
114
- <code>home/&lt;area&gt;/lighting/availability</code> once the flows start and <code>offline</code> as it stops, which the
115
- circadian switch in Home Assistant follows. These get through only when this node is
116
- deployed on its own, so set the MQTT broker node's Birth, Close and Will messages to the same (see the README).</dd>
117
- <dt>Home Assistant discovery</dt><dd>a circadian switch in Home Assistant, which reads that state and sends
118
- ON/OFF to <code>home/&lt;area&gt;/circadian/set</code>. To act on it, wire an MQTT in node subscribed to that
119
- topic into this node. It needs <b>Publish state</b>. Switching it off
120
- removes the switch from Home Assistant at the next start.</dd>
252
+ <code>home/&lt;area&gt;/lighting/&lt;target&gt;/control</code>, and a retained <code>online</code> on
253
+ <code>home/&lt;area&gt;/lighting/availability</code> once the flows start and <code>offline</code> as it stops.
254
+ These get through only when this node is deployed on its own, so set the MQTT broker node's Birth, Close and
255
+ Will messages to the same (see the README).</dd>
256
+ <dt>Home Assistant discovery</dt><dd>a control sensor for each light. It needs <b>Publish state</b>. The entities
257
+ are announced once the flows start, before <code>online</code>, and again at the startup message. Switching it
258
+ off removes them from Home Assistant at the next startup message. At every start the room also clears the
259
+ circadian, sleep, wake and bed entities it published before 6.0; the circadian lighting policy publishes its
260
+ own.</dd>
121
261
  <dt>Discovery prefix</dt><dd>the topic prefix Home Assistant listens on for discovery: <code>homeassistant</code>
122
262
  unless you changed it in Home Assistant's MQTT settings.</dd>
123
263
  </dl>
124
264
  <p>New nodes start with both off. A node saved before these settings existed keeps publishing both.</p>
125
- <h3>Circadian schedule</h3>
126
- <p><b>Schedule</b>: a house schedule the room follows, shared with other rooms. Following it, the room takes its
127
- wake and bed times from it whenever they change, has no wake and bed time entities of its own in Home Assistant
128
- (they are cleared), and ignores its own wake-time and bed-time set topics. With none, the room keeps its own
129
- <b>Wake time</b> and <b>Bed time</b>. If the schedule is missing when the room starts, as when it was deleted
130
- from the flows file, the room keeps its own times and its status says <i>schedule missing: own times</i>; deleting
131
- a schedule in the editor sets its rooms to none.</p>
132
- <p>Circadian levels follow <b>Wake time</b> and <b>Bed time</b> (24-hour <code>HH:MM</code>, default 07:00 and
133
- 23:00): they rise to the daytime level over the hour after waking, stay at the daytime brightness and colour
134
- through the day, wind down to the sleep settings over the three hours before bed, and stay at the sleep
135
- settings until you wake. A bed time after midnight, or a wake time later than the bed time, works. Sleep mode
136
- still overrides the schedule.</p>
137
- <p>Times are the Node-RED host's local time. Docker containers default to UTC: set the container's
138
- <code>TZ</code> if your host should follow a local timezone.</p>
265
+ <h3>Targets</h3>
266
+ <p>A JSON list of lights, each <code>{"id"}</code>: the name its adapter's <b>Target</b> and the policies use. Add <code>"onOffOnly": true</code>
267
+ for a light that only switches on and off: it is never sent brightness, colour or a transition, styles skip it,
268
+ and values an intent gives it are left out with a warning once per deploy. Who controls it works as for any light.
269
+ <b>Turn-on transition seconds</b> is the transition for a light switched on, styled or with an intent's values.</p>
139
270
  <h3>Control state</h3>
140
271
  <p>Each target has one control state:</p>
141
272
  <dl class="message-properties">
142
- <dt>in-control</dt><dd>circadian lighting may style and refresh the light. This is the default.</dd>
143
- <dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light. Refresh and circadian
144
- changes leave it alone until that owner releases it.</dd>
145
- <dt>manual</dt><dd>a person changed the light. Enabling circadian lighting returns manual lights to
146
- in-control.</dd>
273
+ <dt>in-control</dt><dd>the room styles the light with the style it is sent. This is the default.</dd>
274
+ <dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light. Styles leave it alone until
275
+ that owner releases it.</dd>
276
+ <dt>manual</dt><dd>a person set the light: an intent with <code>manual: true</code> (a wall switch's double
277
+ press), or someone else's command on the light with values, as its adapter reports it. An intent's values alone don't make a light
278
+ manual. Switching circadian lighting on returns manual lights to in-control.</dd>
147
279
  </dl>
148
280
  <p>An overridden light changes only for an intent with an <code>owner</code> (its own, or a newer owner who takes
149
- it over), a person (a <code>manual: true</code> intent, <code>person: true</code>, set by the wall-switch policies, an external command on the command topic, or a change
281
+ it over), a person (a <code>manual: true</code> intent, <code>person: true</code>, set by the wall-switch policies, someone else's command on the light, or a change
150
282
  seen at the light), or a release. Any other intent, including motion ON or OFF and owner-less values, leaves it
151
283
  alone and is traced as <code>ignored held-by</code>; other targets in the same intent are still handled.
152
284
  Switching a light off by its owner or a person returns it to in-control.</p>
153
285
  <p>The control states are kept in the node's context. When the node starts with nothing saved (its first deploy,
154
286
  or a redeploy or restart without a context store, see the README), it can't know which lights were held or set
155
- by a person, so it leaves every light as it is: no periodic refresh restyles a light until an intent or release
156
- names it, someone switches it on with a bare ON on its command topic, or circadian lighting is switched on. Sleep
157
- and schedule changes restyle only lights it has been told about since. A light that is on at that start and that
158
- nothing names can keep its start-time style all day; to bring it back into step, switch circadian lighting on
159
- (for example with the Home Assistant circadian switch), or let motion or a wall switch name it.</p>
287
+ by a person, so it leaves every light as it is: no style restyles a light until an intent or release names it,
288
+ someone switches it on with a bare ON, or circadian lighting is switched on. A light that is
289
+ on at that start and that nothing names keeps its start-time style; to bring it back into step, switch circadian
290
+ lighting on (for example with the Home Assistant circadian switch), or let motion or a wall switch name it.</p>
160
291
  <h3>Inputs</h3>
161
292
  <dl class="message-properties">
162
- <dt>topic = home/&lt;area&gt;/circadian/set</dt>
163
- <dd>payload <code>ON</code> or <code>OFF</code> (any case) switches circadian lighting on or off, as
164
- <code>lighting.kind = "circadian"</code> does. Read only while <b>Publish state</b> is on and the area is set.
165
- Retained messages and other payloads are ignored.</dd>
166
- <dt>topic = home/&lt;area&gt;/sleep/set</dt>
167
- <dd><code>ON</code> or <code>OFF</code> switches sleep, as <code>lighting.kind = "sleep"</code> does, under the
168
- same conditions.</dd>
169
- <dt>topic = home/&lt;area&gt;/wake-time/set or bed-time/set</dt>
170
- <dd>a time, <code>HH:MM</code> or <code>HH:MM:SS</code>, changes that time, as
171
- <code>lighting = {kind: "schedule", wakeTime, bedTime}</code> does. A time set this way lasts until the node is
172
- deployed with a different <b>Wake time</b> or <b>Bed time</b>, which then applies.</dd>
293
+ <dt>lighting.kind = "intent"</dt>
294
+ <dd><code>state</code> ON, OFF or TOGGLE for <code>targets</code> (default: all), with optional
295
+ <code>values</code> (<code>brightnessPct</code> 0-100, <code>colorTempKelvin</code>, <code>effect</code> and other
296
+ fields passed on as they are).</dd>
297
+ <dt>lighting.kind = "style"</dt>
298
+ <dd>how lights should look, usually from a circadian lighting policy (see Style).</dd>
173
299
  <dt>lighting.owner <span class="property-type">string</span></dt>
174
300
  <dd>on an <code>intent</code> that switches targets on, marks them overridden by this owner. With
175
301
  <code>preserveManual: true</code>, manual lights are skipped.</dd>
176
302
  <dt>lighting.kind = "release"</dt>
177
303
  <dd>returns overridden <code>targets</code> (default: all) to in-control. With <code>owner</code>, only lights
178
- held by that owner are released. Released lights that are on are restyled as a refresh would.</dd>
304
+ held by that owner are released. Released lights that are on are restyled over the style's transition.</dd>
179
305
  </dl>
180
306
  <h3>Outputs</h3>
181
- <p>With <b>Publish state</b> on, on startup and whenever a target's control state changes, a retained message is
182
- sent with topic
183
- <code>home/&lt;area&gt;/lighting/&lt;target&gt;/control</code> and payload
184
- <code>{"state": "in-control" | "overridden" | "manual", "owner": string | null}</code>.</p>
307
+ <ol class="node-ports">
308
+ <li>MQTT publications, for an MQTT out node: with <b>Publish state</b> on, on startup and whenever a target's
309
+ control state or availability changes, a retained message on <code>home/&lt;area&gt;/lighting/&lt;target&gt;/control</code>
310
+ with payload <code>{"state": "in-control" | "overridden" | "manual", "owner": string | null, "available"?: boolean}</code>
311
+ (<code>available</code> once its adapter has reported it), and the room's availability and discovery.</li>
312
+ <li>Light commands, <code>msg.light</code>, for the lights' adapters: <code>{kind: "command", target, state,
313
+ brightnessPct?, colorTempKelvin?, transitionSeconds?, extra?, restyle?, source, id}</code>, and
314
+ <code>{kind: "observe", target}</code> at its startup message.</li>
315
+ <li>Each light's reading, <code>msg.light</code>, passed on with <code>control</code> and <code>manual</code>, for
316
+ activity lighting.</li>
317
+ </ol>
185
318
  </script>