@avantics/node-red-home-automation 5.0.0 → 6.1.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.
- package/README.md +413 -77
- package/contract-examples/room-lighting.mjs +39 -27
- package/dist/lib/activity-lighting-controller.d.ts +7 -2
- package/dist/lib/activity-lighting-controller.js +75 -16
- package/dist/lib/avr-controller.d.ts +2 -2
- package/dist/lib/avr-controller.js +21 -26
- package/dist/lib/circadian-policy.d.ts +47 -0
- package/dist/lib/circadian-policy.js +111 -0
- package/dist/lib/circadian-publishing.d.ts +33 -0
- package/dist/lib/circadian-publishing.js +154 -0
- package/dist/lib/circadian-schedule.d.ts +4 -0
- package/dist/lib/circadian-schedule.js +12 -0
- package/dist/lib/command-echo.d.ts +8 -1
- package/dist/lib/command-echo.js +37 -6
- package/dist/lib/cover-controller.js +4 -0
- package/dist/lib/denon-protocol.js +3 -2
- package/dist/lib/enable-input.d.ts +3 -0
- package/dist/lib/enable-input.js +18 -0
- package/dist/lib/house-schedule.js +2 -2
- package/dist/lib/light-contract.d.ts +53 -0
- package/dist/lib/light-contract.js +11 -0
- package/dist/lib/motion-policy.d.ts +0 -1
- package/dist/lib/motion-policy.js +9 -8
- package/dist/lib/motion-publishing.js +2 -1
- package/dist/lib/mqtt-message.d.ts +6 -0
- package/dist/lib/mqtt-message.js +21 -0
- package/dist/lib/room-controller.d.ts +41 -27
- package/dist/lib/room-controller.js +422 -213
- package/dist/lib/room-holds.d.ts +34 -0
- package/dist/lib/room-holds.js +66 -0
- package/dist/lib/room-lighting-discovery.d.ts +0 -14
- package/dist/lib/room-lighting-discovery.js +19 -125
- package/dist/lib/room-publishing.d.ts +7 -12
- package/dist/lib/room-publishing.js +65 -125
- package/dist/lib/shelly-cover.d.ts +2 -4
- package/dist/lib/shelly-cover.js +30 -70
- package/dist/lib/shelly-gen2.d.ts +25 -0
- package/dist/lib/shelly-gen2.js +58 -0
- package/dist/lib/shelly-switch.d.ts +95 -0
- package/dist/lib/shelly-switch.js +237 -0
- package/dist/lib/theatre-state-contract.js +12 -4
- package/dist/lib/z2m-cover.d.ts +49 -0
- package/dist/lib/z2m-cover.js +120 -0
- package/dist/lib/z2m-light-adapter.d.ts +62 -0
- package/dist/lib/z2m-light-adapter.js +195 -0
- package/dist/lib/z2m-light.d.ts +2 -2
- package/dist/lib/z2m-light.js +11 -14
- package/dist/nodes/activity-lighting-controller.html +15 -6
- package/dist/nodes/activity-lighting-controller.js +21 -0
- package/dist/nodes/adapter.d.ts +5 -1
- package/dist/nodes/adapter.js +35 -2
- package/dist/nodes/avr-controller.html +20 -18
- package/dist/nodes/avr-controller.js +5 -5
- package/dist/nodes/circadian-policy.d.ts +3 -0
- package/dist/nodes/circadian-policy.html +145 -0
- package/dist/nodes/circadian-policy.js +162 -0
- package/dist/nodes/cover-controller.html +9 -3
- package/dist/nodes/cover-controller.js +1 -1
- package/dist/nodes/display-mode-controller.html +14 -17
- package/dist/nodes/display-mode-controller.js +4 -1
- package/dist/nodes/house-schedule-mqtt.html +5 -0
- package/dist/nodes/house-schedule-mqtt.js +1 -1
- package/dist/nodes/house-schedule.html +3 -3
- package/dist/nodes/motion-policy.html +10 -2
- package/dist/nodes/motion-policy.js +4 -1
- package/dist/nodes/occupancy-fusion.html +5 -0
- package/dist/nodes/occupancy-fusion.js +1 -1
- package/dist/nodes/refused-enable.d.ts +7 -0
- package/dist/nodes/refused-enable.js +24 -0
- package/dist/nodes/room-controller.html +232 -85
- package/dist/nodes/room-controller.js +71 -97
- package/dist/nodes/shelly-switch.d.ts +3 -0
- package/dist/nodes/shelly-switch.html +87 -0
- package/dist/nodes/shelly-switch.js +48 -0
- package/dist/nodes/theatre-state-contract.html +9 -3
- package/dist/nodes/theatre-state-contract.js +1 -1
- package/dist/nodes/z2m-cover.d.ts +3 -0
- package/dist/nodes/z2m-cover.html +68 -0
- package/dist/nodes/z2m-cover.js +41 -0
- package/dist/nodes/z2m-light.d.ts +3 -0
- package/dist/nodes/z2m-light.html +76 -0
- package/dist/nodes/z2m-light.js +51 -0
- package/examples/Cover control.json +28 -71
- package/examples/Home theatre activity.json +53 -19
- package/examples/House schedule.json +106 -24
- package/examples/Room lighting.json +57 -25
- package/examples/Shelly cover.json +5 -16
- package/examples/Shelly switch.json +197 -0
- package/package.json +12 -4
- package/dist/lib/room-schedule.d.ts +0 -8
- 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
|
|
@@ -122,7 +125,7 @@ const registerMotionPolicy = (RED) => {
|
|
|
122
125
|
// else is an input as sent, with a pause's owner.
|
|
123
126
|
const inbound = (0, motion_publishing_1.motionInbound)(msg, publishing);
|
|
124
127
|
process(inbound?.input ?? { source: String(msg.source ?? ""), payload: msg.payload, owner: typeof msg.owner === "string" ? msg.owner : undefined }, send, inbound);
|
|
125
|
-
});
|
|
128
|
+
}, { message: { source: "startup" }, trace: { area: policyConfig.area, component: "motion-policy" } });
|
|
126
129
|
node.on("close", (_removed, done) => {
|
|
127
130
|
clearTimeout(offTimer);
|
|
128
131
|
done();
|
|
@@ -84,4 +84,9 @@
|
|
|
84
84
|
<li>Occupancy events, for the motion lighting policy.</li>
|
|
85
85
|
<li>MQTT publications, when publishing is on.</li>
|
|
86
86
|
</ol>
|
|
87
|
+
<h3>When MQTT out connects</h3>
|
|
88
|
+
<p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
|
|
89
|
+
"connected", this node takes it as its startup message (<code>msg.source = "startup"</code>) and announces itself again:
|
|
90
|
+
Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
|
|
91
|
+
start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
|
|
87
92
|
</script>
|
|
@@ -81,7 +81,7 @@ const registerOccupancyFusion = (RED) => {
|
|
|
81
81
|
lifecycle.publish(send, (0, occupancy_publishing_1.occupancyStateOutputs)(publishing, output.payload.occupied));
|
|
82
82
|
}
|
|
83
83
|
updateStatus(result.status);
|
|
84
|
-
});
|
|
84
|
+
}, { message: { source: "startup" }, trace: { area: fusionConfig.area, component: "occupancy-fusion" } });
|
|
85
85
|
}
|
|
86
86
|
RED.nodes.registerType("home-occupancy-fusion", HomeOccupancyFusion);
|
|
87
87
|
};
|
|
@@ -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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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:
|
|
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,117 @@
|
|
|
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-
|
|
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
|
|
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 the last
|
|
229
|
+
owner releases a light the room was running. 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>
|
|
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/<area>/lighting/<target>/control</code
|
|
113
|
-
<code>home/<area>/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
252
|
+
<code>home/<area>/lighting/<target>/control</code>, and a retained <code>online</code> on
|
|
253
|
+
<code>home/<area>/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>
|
|
126
|
-
<p
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
<b>
|
|
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>
|
|
143
|
-
<dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light.
|
|
144
|
-
|
|
145
|
-
<dt>manual</dt><dd>a person
|
|
146
|
-
|
|
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 on or off. Styles and
|
|
275
|
+
owner-less intents leave it alone until it is released.</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,
|
|
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
|
+
A person switching a held light off returns it to in-control; a person switching on a light an owner holds off
|
|
285
|
+
makes it manual. Either way it leaves every owner, and their later releases leave it alone.</p>
|
|
286
|
+
<p>Owners stack, per light. The first owner to take a light records what it was: its control state, whether it was
|
|
287
|
+
on, and the values it last reported. A newer owner goes on top and sets the light; the owner beneath keeps its
|
|
288
|
+
own request, and sending again updates it without changing the light. Releasing the owner on top hands the light
|
|
289
|
+
to the owner beneath, with what that owner last asked for; releasing an owner beneath just drops it. When the
|
|
290
|
+
last owner lets go, the light goes back to what was recorded: a light the room was running is the room's again,
|
|
291
|
+
on or off as it was, in the room's style as it is now; a light that was off goes off; a light a person had set
|
|
292
|
+
gets its values back and stays manual.</p>
|
|
153
293
|
<p>The control states are kept in the node's context. When the node starts with nothing saved (its first deploy,
|
|
154
294
|
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
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
(for example with the Home Assistant circadian switch), or let motion or a wall switch name it.</p>
|
|
295
|
+
by a person, so it leaves every light as it is: no style restyles a light until an intent or release names it,
|
|
296
|
+
someone switches it on with a bare ON, or circadian lighting is switched on. A light that is
|
|
297
|
+
on at that start and that nothing names keeps its start-time style; to bring it back into step, switch circadian
|
|
298
|
+
lighting on (for example with the Home Assistant circadian switch), or let motion or a wall switch name it.</p>
|
|
160
299
|
<h3>Inputs</h3>
|
|
161
300
|
<dl class="message-properties">
|
|
162
|
-
<dt>
|
|
163
|
-
<dd
|
|
164
|
-
<code>
|
|
165
|
-
|
|
166
|
-
<dt>
|
|
167
|
-
<dd
|
|
168
|
-
same conditions.</dd>
|
|
169
|
-
<dt>topic = home/<area>/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>
|
|
301
|
+
<dt>lighting.kind = "intent"</dt>
|
|
302
|
+
<dd><code>state</code> ON, OFF or TOGGLE for <code>targets</code> (default: all), with optional
|
|
303
|
+
<code>values</code> (<code>brightnessPct</code> 0-100, <code>colorTempKelvin</code>, <code>effect</code> and other
|
|
304
|
+
fields passed on as they are).</dd>
|
|
305
|
+
<dt>lighting.kind = "style"</dt>
|
|
306
|
+
<dd>how lights should look, usually from a circadian lighting policy (see Style).</dd>
|
|
173
307
|
<dt>lighting.owner <span class="property-type">string</span></dt>
|
|
174
|
-
<dd>on an <code>intent</code
|
|
308
|
+
<dd>on an <code>intent</code>, holds its targets on or off for this owner (overridden), on top of any other
|
|
309
|
+
owner's. With
|
|
175
310
|
<code>preserveManual: true</code>, manual lights are skipped.</dd>
|
|
176
311
|
<dt>lighting.kind = "release"</dt>
|
|
177
|
-
<dd>
|
|
178
|
-
|
|
312
|
+
<dd>lets go of overridden <code>targets</code> (default: all) for <code>owner</code>, or for every owner without
|
|
313
|
+
one. A light goes to the owner beneath, or with none left back to what it was before the first.</dd>
|
|
179
314
|
</dl>
|
|
180
315
|
<h3>Outputs</h3>
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
316
|
+
<ol class="node-ports">
|
|
317
|
+
<li>MQTT publications, for an MQTT out node: with <b>Publish state</b> on, on startup and whenever a target's
|
|
318
|
+
control state or availability changes, a retained message on <code>home/<area>/lighting/<target>/control</code>
|
|
319
|
+
with payload <code>{"state": "in-control" | "overridden" | "manual", "owner": string | null, "available"?: boolean}</code>
|
|
320
|
+
(<code>available</code> once its adapter has reported it), and the room's availability and discovery.</li>
|
|
321
|
+
<li>Light commands, <code>msg.light</code>, for the lights' adapters: <code>{kind: "command", target, state,
|
|
322
|
+
brightnessPct?, colorTempKelvin?, transitionSeconds?, extra?, restyle?, source, id}</code>, and
|
|
323
|
+
<code>{kind: "observe", target}</code> at its startup message.</li>
|
|
324
|
+
<li>Each light's reading, <code>msg.light</code>, passed on with <code>control</code> and <code>manual</code>, for
|
|
325
|
+
activity lighting.</li>
|
|
326
|
+
</ol>
|
|
327
|
+
<h3>When MQTT out connects</h3>
|
|
328
|
+
<p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
|
|
329
|
+
"connected", this node takes it as its startup message (<code>msg.lighting = {kind: "startup"}</code>) and announces itself again:
|
|
330
|
+
Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
|
|
331
|
+
start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
|
|
185
332
|
</script>
|