@avantics/node-red-home-automation 6.0.0 → 6.2.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 +276 -48
- package/dist/lib/cover-publishing.js +20 -6
- package/dist/lib/home-assistant-setting.d.ts +23 -0
- package/dist/lib/home-assistant-setting.js +39 -0
- package/dist/lib/motion-policy.d.ts +1 -0
- package/dist/lib/motion-policy.js +21 -1
- package/dist/lib/room-controller.d.ts +4 -0
- package/dist/lib/room-controller.js +122 -14
- package/dist/lib/room-holds.d.ts +34 -0
- package/dist/lib/room-holds.js +66 -0
- package/dist/lib/room-publishing.d.ts +1 -0
- package/dist/lib/room-publishing.js +11 -0
- package/dist/lib/scene-publishing.d.ts +30 -0
- package/dist/lib/scene-publishing.js +63 -0
- package/dist/lib/scene.d.ts +61 -0
- package/dist/lib/scene.js +170 -0
- package/dist/lib/shelly-cover.js +5 -0
- package/dist/lib/shelly-relay-light.d.ts +24 -0
- package/dist/lib/shelly-relay-light.js +93 -0
- package/dist/lib/shelly-switch.d.ts +8 -0
- package/dist/lib/shelly-switch.js +37 -8
- package/dist/lib/theatre-activity-controller.js +4 -0
- package/dist/lib/theatre-metrics.js +6 -4
- package/dist/lib/theatre-slo.js +3 -0
- package/dist/lib/theatre-state-contract.d.ts +4 -2
- package/dist/lib/theatre-state-contract.js +51 -8
- package/dist/lib/theatre-state.js +3 -0
- package/dist/nodes/activity-lighting-controller.html +1 -1
- package/dist/nodes/adapter.d.ts +5 -1
- package/dist/nodes/adapter.js +35 -2
- package/dist/nodes/avr-controller.html +86 -20
- package/dist/nodes/avr-controller.js +23 -11
- package/dist/nodes/circadian-policy.html +88 -19
- package/dist/nodes/circadian-policy.js +30 -11
- package/dist/nodes/cover-controller.html +91 -24
- package/dist/nodes/cover-controller.js +25 -12
- package/dist/nodes/device-side.d.ts +20 -0
- package/dist/nodes/device-side.js +72 -0
- package/dist/nodes/home-assistant-discovery.d.ts +26 -0
- package/dist/nodes/home-assistant-discovery.js +64 -0
- package/dist/nodes/house-schedule-mqtt.html +74 -4
- package/dist/nodes/house-schedule-mqtt.js +22 -8
- package/dist/nodes/motion-policy.html +91 -21
- package/dist/nodes/motion-policy.js +44 -11
- package/dist/nodes/mqtt-broker-link.d.ts +41 -0
- package/dist/nodes/mqtt-broker-link.js +91 -0
- package/dist/nodes/occupancy-fusion.html +87 -19
- package/dist/nodes/occupancy-fusion.js +23 -11
- package/dist/nodes/publishing-side.d.ts +20 -0
- package/dist/nodes/publishing-side.js +66 -0
- package/dist/nodes/room-controller.html +128 -43
- package/dist/nodes/room-controller.js +63 -16
- package/dist/nodes/scene.d.ts +3 -0
- package/dist/nodes/scene.html +226 -0
- package/dist/nodes/scene.js +121 -0
- package/dist/nodes/shelly-cover.html +46 -2
- package/dist/nodes/shelly-cover.js +19 -4
- package/dist/nodes/shelly-switch.html +80 -6
- package/dist/nodes/shelly-switch.js +32 -7
- package/dist/nodes/theatre-state-contract.html +76 -8
- package/dist/nodes/theatre-state-contract.js +33 -14
- package/dist/nodes/z2m-cover.html +46 -2
- package/dist/nodes/z2m-cover.js +21 -4
- package/dist/nodes/z2m-light.html +50 -2
- package/dist/nodes/z2m-light.js +26 -6
- package/examples/Cover control.json +38 -102
- package/examples/Cover pair.json +36 -3
- package/examples/Home theatre activity.json +46 -102
- package/examples/Home theatre equipment.json +34 -2
- package/examples/House schedule.json +58 -80
- package/examples/Room lighting.json +45 -55
- package/examples/Scene.json +215 -0
- package/examples/Shelly cover.json +36 -116
- package/examples/Shelly switch.json +52 -148
- package/package.json +2 -1
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
(function () {
|
|
3
3
|
function on(value) { return value === true || value === "true"; }
|
|
4
|
+
// Its Publish choice (off, state or discovery), from the open dialog or
|
|
5
|
+
// its saved settings: a node saved before the choice reads its two old
|
|
6
|
+
// settings (lib/home-assistant-setting.ts).
|
|
7
|
+
function publishChoice(node) {
|
|
8
|
+
function on(value) { return value === true || value === "true"; }
|
|
9
|
+
var select = $("#node-input-homeAssistant");
|
|
10
|
+
if (select.length) return select.val();
|
|
11
|
+
if (node.homeAssistant === "off" || node.homeAssistant === "state" || node.homeAssistant === "discovery") return node.homeAssistant;
|
|
12
|
+
return !on(node.publishState) ? "off" : on(node.discovery) ? "discovery" : "state";
|
|
13
|
+
}
|
|
14
|
+
// Whether it publishes through its output, as before 6.2: a node saved
|
|
15
|
+
// before the Publish choice that published, or one opened and saved since
|
|
16
|
+
// without a broker (publishesThroughOutput). It needs no broker until one
|
|
17
|
+
// is chosen; from saved values only, not the open dialog.
|
|
18
|
+
function throughOutput(node) {
|
|
19
|
+
if (node.publishesThroughOutput === true) return true;
|
|
20
|
+
return (node.homeAssistant === null || node.homeAssistant === undefined) && (node.publishState === true || node.publishState === "true");
|
|
21
|
+
}
|
|
22
|
+
// Its area is needed while it publishes, and for a node saved before the
|
|
23
|
+
// choice whenever either old setting was on, as the runtime checks.
|
|
24
|
+
function needsArea(node) {
|
|
25
|
+
function on(value) { return value === true || value === "true"; }
|
|
26
|
+
var saved = !$("#node-input-homeAssistant").length && (node.homeAssistant === null || node.homeAssistant === undefined);
|
|
27
|
+
return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
|
|
28
|
+
}
|
|
4
29
|
RED.nodes.registerType("home-occupancy-fusion", {
|
|
5
30
|
category: "home automation",
|
|
6
31
|
color: "#c7e9c0",
|
|
@@ -10,14 +35,25 @@
|
|
|
10
35
|
name: {value: "_DEFAULT_"},
|
|
11
36
|
// Required only when the node publishes, and then with a letter or
|
|
12
37
|
// digit, from which its topics and IDs are made.
|
|
13
|
-
area: {value: "", validate: function (v) {
|
|
14
|
-
var publishing = $("#node-input-publishState").length ? $("#node-input-publishState").prop("checked") : on(this.publishState);
|
|
15
|
-
return !publishing || /[a-z0-9]/i.test(String(v || ""));
|
|
16
|
-
}},
|
|
38
|
+
area: {value: "", validate: function (v) { return !needsArea(this) || /[a-z0-9]/i.test(String(v || "")); }},
|
|
17
39
|
presenceMode: {value: "none", required: true},
|
|
18
40
|
// Occupancy published nothing before these settings, so both start off.
|
|
41
|
+
// Publish: off, state or discovery. null means "not set": a node saved
|
|
42
|
+
// before this setting, read from the two below, kept with no rows.
|
|
43
|
+
homeAssistant: {value: null},
|
|
44
|
+
// Node-RED's MQTT broker node, through which it publishes and reads its set
|
|
45
|
+
// topics itself. Needed unless Publish is "Don't publish". The editor offers
|
|
46
|
+
// the first broker when the dialog is opened and saved, not when the node
|
|
47
|
+
// is dropped.
|
|
48
|
+
broker: {value: "", type: "mqtt-broker", required: false, validate: function (v) {
|
|
49
|
+
return publishChoice(this) === "off" || (Boolean(v) && v !== "_ADD_") || throughOutput(this) ? true : "choose a broker, or set Publish to Don't publish";
|
|
50
|
+
}},
|
|
19
51
|
publishState: {value: false},
|
|
20
52
|
discovery: {value: false},
|
|
53
|
+
// true for a node that publishes through its output, as before 6.2, and
|
|
54
|
+
// was opened and saved without a broker: it stays valid until a broker is
|
|
55
|
+
// chosen. No form row.
|
|
56
|
+
publishesThroughOutput: {value: false},
|
|
21
57
|
discoveryPrefix: {value: "homeassistant", required: true, validate: function (v) { var prefix = String(v || "").trim().replace(/^\/+|\/+$/g, ""); return Boolean(prefix) && !/[+#]/.test(prefix); }},
|
|
22
58
|
// How Home Assistant IDs are named; occupancy has no older entities,
|
|
23
59
|
// so not set also means "node".
|
|
@@ -28,18 +64,26 @@
|
|
|
28
64
|
this.name = "";
|
|
29
65
|
this.idScheme = "node";
|
|
30
66
|
},
|
|
67
|
+
oneditsave: function () {
|
|
68
|
+
// Through its output until a broker is chosen (read before the
|
|
69
|
+
// dialog's values are applied).
|
|
70
|
+
var broker = $("#node-input-broker").val();
|
|
71
|
+
this.publishesThroughOutput = throughOutput(this) && (!broker || broker === "_ADD_");
|
|
72
|
+
},
|
|
31
73
|
oneditprepare: function () {
|
|
32
|
-
$("#node-input-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
function
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
$("#node-input-
|
|
39
|
-
$("
|
|
74
|
+
$("#node-input-homeAssistant").val(publishChoice(this));
|
|
75
|
+
// The broker only while it publishes, the prefix only with discovery.
|
|
76
|
+
var outputBefore = throughOutput(this);
|
|
77
|
+
function publishRows() {
|
|
78
|
+
var broker = $("#node-input-broker").val();
|
|
79
|
+
$(".publish-through-output").toggle($("#node-input-homeAssistant").val() !== "off" && outputBefore && (!broker || broker === "_ADD_"));
|
|
80
|
+
var choice = $("#node-input-homeAssistant").val();
|
|
81
|
+
$(".publish-broker").toggle(choice !== "off");
|
|
82
|
+
$(".publish-discovery").toggle(choice === "discovery");
|
|
83
|
+
$("#node-input-area, #node-input-broker").trigger("change");
|
|
40
84
|
}
|
|
41
|
-
$("#node-input-
|
|
42
|
-
|
|
85
|
+
$("#node-input-homeAssistant, #node-input-broker").on("change", publishRows);
|
|
86
|
+
publishRows();
|
|
43
87
|
},
|
|
44
88
|
inputs: 1,
|
|
45
89
|
outputs: 2,
|
|
@@ -60,9 +104,20 @@
|
|
|
60
104
|
<option value="hold">Hold occupancy (PIR + mmWave)</option>
|
|
61
105
|
</select>
|
|
62
106
|
</div>
|
|
63
|
-
<div class="form-row"
|
|
64
|
-
|
|
65
|
-
|
|
107
|
+
<div class="form-row">
|
|
108
|
+
<label for="node-input-homeAssistant">Publish</label>
|
|
109
|
+
<select id="node-input-homeAssistant">
|
|
110
|
+
<option value="off">Don't publish</option>
|
|
111
|
+
<option value="state">MQTT state</option>
|
|
112
|
+
<option value="discovery">MQTT state and Home Assistant discovery</option>
|
|
113
|
+
</select>
|
|
114
|
+
</div>
|
|
115
|
+
<div class="form-row publish-broker"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
|
|
116
|
+
<div class="form-tips publish-broker">With a broker, it publishes and reads its set topics itself: an MQTT out on its
|
|
117
|
+
publication output, an MQTT in on its set topics, and a Status node are no longer needed and can be deleted.</div>
|
|
118
|
+
<div class="form-tips publish-through-output">This node publishes through its output, as before 6.2, and keeps
|
|
119
|
+
working that way. Choose a Broker to let it publish itself.</div>
|
|
120
|
+
<div class="form-row publish-discovery"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
66
121
|
</script>
|
|
67
122
|
|
|
68
123
|
<script type="text/html" data-help-name="home-occupancy-fusion">
|
|
@@ -72,10 +127,10 @@
|
|
|
72
127
|
<p>Off unless switched on. Both are named after the <b>Area</b>, which is needed then; topics use it in lowercase,
|
|
73
128
|
with spaces and other characters as <code>_</code>.</p>
|
|
74
129
|
<dl class="message-properties">
|
|
75
|
-
<dt>Publish state
|
|
130
|
+
<dt>Publish: MQTT state</dt><dd>the occupancy, retained <code>ON</code> or <code>OFF</code>, on
|
|
76
131
|
<code>home/<area>/occupancy/state</code> whenever it changes, and <code>online</code> or
|
|
77
132
|
<code>offline</code> on <code>home/<area>/occupancy/availability</code>.</dd>
|
|
78
|
-
<dt>Home Assistant discovery</dt><dd>an occupancy binary sensor reading that state. It
|
|
133
|
+
<dt>Publish: MQTT state and Home Assistant discovery</dt><dd>an occupancy binary sensor reading that state. It includes the MQTT state, which it reads.</dd>
|
|
79
134
|
</dl>
|
|
80
135
|
<p>These go on the second output; wire it to an MQTT out node. The node announces itself once the flows have
|
|
81
136
|
started, and again when it receives <code>msg.source = "startup"</code>.</p>
|
|
@@ -84,4 +139,17 @@
|
|
|
84
139
|
<li>Occupancy events, for the motion lighting policy.</li>
|
|
85
140
|
<li>MQTT publications, when publishing is on.</li>
|
|
86
141
|
</ol>
|
|
142
|
+
<h3>Broker</h3>
|
|
143
|
+
<p>Choose Node-RED's <b>MQTT broker</b> node, and it publishes itself: it announces everything each time the
|
|
144
|
+
broker connects, reconnects included, and each time Home Assistant comes back (<code>online</code> on
|
|
145
|
+
<code><prefix>/status</code>), so its entities come back by themselves.
|
|
146
|
+
Each connect also runs its startup message, as a Status node's "connected" did without a broker. Its publication output then sends
|
|
147
|
+
nothing, and an MQTT out on it and a Status node are no longer needed: still wired, they change nothing.
|
|
148
|
+
Opening and saving the node offers the first broker in your flows. A node saved before 6.2 that publishes keeps
|
|
149
|
+
publishing on its output, as below, and needs no broker until you choose one.</p>
|
|
150
|
+
<h3>When MQTT out connects</h3>
|
|
151
|
+
<p>Without a broker, wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
|
|
152
|
+
"connected", this node takes it as its startup message (<code>msg.source = "startup"</code>) and announces itself again:
|
|
153
|
+
Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
|
|
154
|
+
start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
|
|
87
155
|
</script>
|
|
@@ -6,13 +6,15 @@ const settings_1 = require("../lib/settings");
|
|
|
6
6
|
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
|
-
const
|
|
9
|
+
const publishing_side_1 = require("./publishing-side");
|
|
10
|
+
const home_assistant_setting_1 = require("../lib/home-assistant-setting");
|
|
10
11
|
const registerOccupancyFusion = (RED) => {
|
|
11
12
|
function HomeOccupancyFusion(config) {
|
|
12
13
|
RED.nodes.createNode(this, config);
|
|
13
14
|
const node = this;
|
|
14
15
|
let fusionConfig;
|
|
15
16
|
let publishing;
|
|
17
|
+
let broker;
|
|
16
18
|
try {
|
|
17
19
|
// The editor offers "none" (PIR only) and "hold" (PIR plus presence).
|
|
18
20
|
const presence = (0, settings_1.textSetting)(config.presenceMode, "presence sensor", "none");
|
|
@@ -22,14 +24,14 @@ const registerOccupancyFusion = (RED) => {
|
|
|
22
24
|
fusionConfig = { area, presenceMode: presence === "hold" ? "hold" : "ignore" };
|
|
23
25
|
// Off unless switched on, as occupancy published nothing before; there
|
|
24
26
|
// are no older entities to keep, so not set names them after the node.
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
if (publishState || discovery)
|
|
27
|
+
const publish = (0, home_assistant_setting_1.publishingChoice)(config, { publishState: false, discovery: false });
|
|
28
|
+
if (publish.needsArea)
|
|
28
29
|
(0, topic_names_1.publishingArea)(area, true);
|
|
30
|
+
broker = (0, publishing_side_1.brokerSetting)(RED, config.broker, publish.publishState);
|
|
29
31
|
publishing = {
|
|
30
32
|
area,
|
|
31
|
-
publishState,
|
|
32
|
-
discovery,
|
|
33
|
+
publishState: publish.publishState,
|
|
34
|
+
discovery: publish.discovery,
|
|
33
35
|
discoveryPrefix: (0, ha_discovery_1.discoveryPrefixSetting)(config.discoveryPrefix),
|
|
34
36
|
nodeId: node.id,
|
|
35
37
|
idScheme: (0, settings_1.optionalChoiceSetting)(config.idScheme, "ID scheme", ha_discovery_1.ID_SCHEMES) ?? "node"
|
|
@@ -58,15 +60,20 @@ const registerOccupancyFusion = (RED) => {
|
|
|
58
60
|
// events the motion policy reads on the first. Available, and clear of
|
|
59
61
|
// what it no longer publishes, as soon as it runs; offline as it stops;
|
|
60
62
|
// nothing left behind when deleted.
|
|
61
|
-
const
|
|
63
|
+
const trace = { area: fusionConfig.area, component: "occupancy-fusion" };
|
|
64
|
+
// No set topics: it only publishes.
|
|
65
|
+
const lifecycle = (0, publishing_side_1.publishingSide)(RED, node, broker, {
|
|
62
66
|
retainedTopics: () => (0, occupancy_publishing_1.occupancyRetainedTopics)(publishing),
|
|
63
67
|
possible: { owner: publishing, topics: () => (0, publishing_node_1.publishesState)(publishing) ? (0, occupancy_publishing_1.occupancyRetainedTopics)({ ...publishing, publishState: true, discovery: true }) : [] },
|
|
64
68
|
starting: () => (0, occupancy_publishing_1.occupancyStartingOutputs)(publishing, occupied()),
|
|
65
69
|
stopping: () => (0, occupancy_publishing_1.occupancyStoppingOutputs)(publishing),
|
|
66
70
|
output: 1,
|
|
67
|
-
outputs: 2
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
outputs: 2,
|
|
72
|
+
startupMessage: { source: "startup" },
|
|
73
|
+
statusTopic: publishing.discovery ? publishing.discoveryPrefix + "/status" : null,
|
|
74
|
+
setTopics: []
|
|
75
|
+
}, trace, (msg, send) => handle(msg, send));
|
|
76
|
+
function handle(msg, send) {
|
|
70
77
|
if (msg.source === "startup") {
|
|
71
78
|
lifecycle.startup(send, (0, occupancy_publishing_1.occupancyStartingOutputs)(publishing, occupied()));
|
|
72
79
|
return;
|
|
@@ -81,7 +88,12 @@ const registerOccupancyFusion = (RED) => {
|
|
|
81
88
|
lifecycle.publish(send, (0, occupancy_publishing_1.occupancyStateOutputs)(publishing, output.payload.occupied));
|
|
82
89
|
}
|
|
83
90
|
updateStatus(result.status);
|
|
84
|
-
}
|
|
91
|
+
}
|
|
92
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
93
|
+
// With a broker, a Status node still wired in changes nothing.
|
|
94
|
+
if (!lifecycle.fromBroker(msg))
|
|
95
|
+
handle(msg, send);
|
|
96
|
+
}, lifecycle.startupOption({ source: "startup" }));
|
|
85
97
|
}
|
|
86
98
|
RED.nodes.registerType("home-occupancy-fusion", HomeOccupancyFusion);
|
|
87
99
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Node, NodeAPI } from "node-red";
|
|
2
|
+
import { type TraceMetadata } from "../lib/bounded-trace";
|
|
3
|
+
import { type InputMessage, type Send } from "./adapter";
|
|
4
|
+
import { type BrokerNode } from "./mqtt-broker-link";
|
|
5
|
+
import { type PublishingLifecycle, type PublishingNode } from "./publishing-lifecycle";
|
|
6
|
+
export interface PublishingSideParts extends PublishingNode {
|
|
7
|
+
statusTopic: string | null;
|
|
8
|
+
setTopics: string[];
|
|
9
|
+
startupMessage: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface PublishingSide extends PublishingLifecycle {
|
|
12
|
+
broker: boolean;
|
|
13
|
+
fromBroker(msg: InputMessage): boolean;
|
|
14
|
+
startupOption(message: Record<string, unknown>): {
|
|
15
|
+
message: Record<string, unknown>;
|
|
16
|
+
trace: TraceMetadata;
|
|
17
|
+
} | undefined;
|
|
18
|
+
}
|
|
19
|
+
export declare function brokerSetting(RED: NodeAPI, value: unknown, publishing: boolean): BrokerNode | null;
|
|
20
|
+
export declare function publishingSide(RED: NodeAPI, node: Node, broker: BrokerNode | null, parts: PublishingSideParts, trace: TraceMetadata, handle: (msg: InputMessage, send: Send) => void): PublishingSide;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.brokerSetting = brokerSetting;
|
|
4
|
+
exports.publishingSide = publishingSide;
|
|
5
|
+
const bounded_trace_1 = require("../lib/bounded-trace");
|
|
6
|
+
const adapter_1 = require("./adapter");
|
|
7
|
+
const home_assistant_discovery_1 = require("./home-assistant-discovery");
|
|
8
|
+
const mqtt_broker_link_1 = require("./mqtt-broker-link");
|
|
9
|
+
const publishing_lifecycle_1 = require("./publishing-lifecycle");
|
|
10
|
+
// The Broker setting: the mqtt-broker node, or null without one (as before
|
|
11
|
+
// 6.2). Only read while the node publishes.
|
|
12
|
+
function brokerSetting(RED, value, publishing) {
|
|
13
|
+
const id = typeof value === "string" ? value.trim() : "";
|
|
14
|
+
if (!publishing || !id)
|
|
15
|
+
return null;
|
|
16
|
+
const broker = RED.nodes.getNode(id);
|
|
17
|
+
if (!broker)
|
|
18
|
+
throw new Error("its MQTT broker node isn't in the flows: choose one, or set Publish to Don't publish");
|
|
19
|
+
return broker;
|
|
20
|
+
}
|
|
21
|
+
function publishingSide(RED, node, broker, parts, trace,
|
|
22
|
+
// The node's own input handling: a message on one of its set topics from
|
|
23
|
+
// the broker, as if from an MQTT in node, and its startup message on each
|
|
24
|
+
// connect.
|
|
25
|
+
handle) {
|
|
26
|
+
if (!broker) {
|
|
27
|
+
const lifecycle = (0, publishing_lifecycle_1.publishingLifecycle)(RED, node, parts);
|
|
28
|
+
return {
|
|
29
|
+
...lifecycle,
|
|
30
|
+
broker: false,
|
|
31
|
+
fromBroker: () => false,
|
|
32
|
+
startupOption: (message) => ({ message, trace })
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const homeAssistant = (0, home_assistant_discovery_1.homeAssistantDiscovery)(RED, node, (0, mqtt_broker_link_1.brokerLink)(broker, node.id, (error) => node.error(error)), {
|
|
36
|
+
retainedTopics: parts.retainedTopics,
|
|
37
|
+
possible: parts.possible,
|
|
38
|
+
announcement: parts.starting,
|
|
39
|
+
stopping: parts.stopping,
|
|
40
|
+
statusTopic: parts.statusTopic,
|
|
41
|
+
setTopics: parts.setTopics,
|
|
42
|
+
onSet: (message) => handle({ topic: message.topic, payload: message.payload, retain: false }, node.send.bind(node)),
|
|
43
|
+
onConnected: () => handle(structuredClone(parts.startupMessage), node.send.bind(node))
|
|
44
|
+
}, trace);
|
|
45
|
+
return {
|
|
46
|
+
broker: true,
|
|
47
|
+
startup(_send, announce = []) {
|
|
48
|
+
homeAssistant.publish(announce);
|
|
49
|
+
},
|
|
50
|
+
publish(_send, publications) {
|
|
51
|
+
homeAssistant.publish(publications);
|
|
52
|
+
},
|
|
53
|
+
fromBroker(msg) {
|
|
54
|
+
const status = (0, adapter_1.objectField)(msg, "status");
|
|
55
|
+
const statusNode = Boolean(status && status.source && typeof status.source === "object");
|
|
56
|
+
const setTopic = typeof msg.topic === "string" && parts.setTopics.includes(msg.topic);
|
|
57
|
+
if (!statusNode && !setTopic)
|
|
58
|
+
return false;
|
|
59
|
+
(0, bounded_trace_1.appendTrace)(node.context(), trace, [{ event: "input", outcome: "ignored", reason: "has-broker",
|
|
60
|
+
details: statusNode ? { status: String(status.text ?? "") } : { topic: msg.topic } }]);
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
startupOption: () => undefined
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=publishing-side.js.map
|
|
@@ -3,6 +3,24 @@
|
|
|
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
|
+
// Its Home Assistant choice, from the open dialog or its saved settings: a
|
|
7
|
+
// room saved before the choice reads its two old settings, where not set
|
|
8
|
+
// means on (lib/home-assistant-setting.ts).
|
|
9
|
+
function choiceOf(node) {
|
|
10
|
+
var select = $("#node-input-homeAssistant");
|
|
11
|
+
if (select.length) return select.val();
|
|
12
|
+
if (node.homeAssistant === "off" || node.homeAssistant === "state" || node.homeAssistant === "discovery") return node.homeAssistant;
|
|
13
|
+
return !on(node.publishState) ? "off" : on(node.discovery) ? "discovery" : "state";
|
|
14
|
+
}
|
|
15
|
+
// Whether it publishes through its output, as before 6.2: a room saved
|
|
16
|
+
// before the Publish choice that published, or one opened and saved since
|
|
17
|
+
// without a broker (publishesThroughOutput). It needs no broker until
|
|
18
|
+
// one is chosen; from saved values only, not the open dialog.
|
|
19
|
+
function throughOutput(node) {
|
|
20
|
+
if (node.publishesThroughOutput === true) return true;
|
|
21
|
+
var saved = node.homeAssistant === null || node.homeAssistant === undefined;
|
|
22
|
+
return saved && on(node.publishState);
|
|
23
|
+
}
|
|
6
24
|
// Each old setting, and the circadian lighting policy field it goes into.
|
|
7
25
|
var MOVED = {
|
|
8
26
|
houseSchedule: "Schedule", wakeTime: "Wake time", bedTime: "Bed time",
|
|
@@ -89,16 +107,31 @@
|
|
|
89
107
|
// Required only when the room publishes something named after it, and
|
|
90
108
|
// then with a letter or digit, from which its topics and IDs are made.
|
|
91
109
|
area: {value: "", validate: function (v) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
// A room saved before the choice needed one whenever either old
|
|
111
|
+
// setting was on, as the runtime still checks.
|
|
112
|
+
var legacy = !$("#node-input-homeAssistant").length && (this.homeAssistant === null || this.homeAssistant === undefined) &&
|
|
113
|
+
(on(this.publishState) || on(this.discovery));
|
|
114
|
+
return (choiceOf(this) === "off" && !legacy) || /[a-z0-9]/i.test(String(v || ""));
|
|
96
115
|
}},
|
|
97
|
-
// null means "not set":
|
|
98
|
-
//
|
|
99
|
-
|
|
116
|
+
// off, state or discovery. null means "not set": a room saved before
|
|
117
|
+
// this setting, read from the two below. New nodes start off (onadd).
|
|
118
|
+
homeAssistant: {value: null},
|
|
119
|
+
// Node-RED's MQTT broker node, through which it publishes itself.
|
|
120
|
+
// Needed unless Publish is "Don't publish". The editor offers the first
|
|
121
|
+
// broker when the dialog is opened and saved, not when the node is
|
|
122
|
+
// dropped.
|
|
123
|
+
broker: {value: "", type: "mqtt-broker", required: false, validate: function (v) {
|
|
124
|
+
return choiceOf(this) === "off" || (Boolean(v) && v !== "_ADD_") || throughOutput(this) ? true : "choose a broker, or set Publish to Don't publish";
|
|
125
|
+
}},
|
|
126
|
+
// The two settings the choice replaced, kept with no form rows so the
|
|
127
|
+
// editor carries a saved room's: null means "not set", which kept
|
|
128
|
+
// publishing (on) before the choice.
|
|
100
129
|
publishState: {value: null},
|
|
101
130
|
discovery: {value: null},
|
|
131
|
+
// true for a room that publishes through its output, as before 6.2,
|
|
132
|
+
// and was opened and saved without a broker: it stays valid until a
|
|
133
|
+
// broker is chosen. No form row.
|
|
134
|
+
publishesThroughOutput: {value: false},
|
|
102
135
|
// How Home Assistant IDs are named. null means "not set": a node saved
|
|
103
136
|
// before this setting, which keeps its area-named entities. New nodes
|
|
104
137
|
// name them after the node (onadd), so renaming the area keeps them.
|
|
@@ -129,21 +162,26 @@
|
|
|
129
162
|
if (this.name !== "_DEFAULT_") return;
|
|
130
163
|
this.name = "";
|
|
131
164
|
this.idScheme = "node";
|
|
165
|
+
this.homeAssistant = "off";
|
|
132
166
|
this.publishState = false;
|
|
133
167
|
this.discovery = false;
|
|
134
168
|
},
|
|
135
169
|
oneditprepare: function () {
|
|
136
170
|
var node = this;
|
|
137
|
-
$("#node-input-
|
|
138
|
-
|
|
139
|
-
//
|
|
171
|
+
$("#node-input-homeAssistant").val(choiceOf(node));
|
|
172
|
+
// The broker only for publishing, the prefix only for discovery; for a
|
|
173
|
+
// room that publishes through its output, that it does until given a
|
|
174
|
+
// broker.
|
|
175
|
+
var outputBefore = throughOutput(node);
|
|
140
176
|
function follow() {
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
$("
|
|
144
|
-
$("
|
|
177
|
+
var choice = $("#node-input-homeAssistant").val();
|
|
178
|
+
var broker = $("#node-input-broker").val();
|
|
179
|
+
$(".room-broker").toggle(choice !== "off");
|
|
180
|
+
$(".room-through-output").toggle(choice !== "off" && outputBefore && (!broker || broker === "_ADD_"));
|
|
181
|
+
$(".room-discovery").toggle(choice === "discovery");
|
|
182
|
+
$("#node-input-area, #node-input-broker").trigger("change");
|
|
145
183
|
}
|
|
146
|
-
$("#node-input-
|
|
184
|
+
$("#node-input-homeAssistant, #node-input-broker").on("change", follow);
|
|
147
185
|
follow();
|
|
148
186
|
// A room saved before 6.0: its circadian settings, to copy into a
|
|
149
187
|
// circadian lighting policy.
|
|
@@ -175,6 +213,14 @@
|
|
|
175
213
|
// Saving the dialog migrates the room: its old circadian settings go.
|
|
176
214
|
oneditsave: function () {
|
|
177
215
|
var node = this;
|
|
216
|
+
// The two settings it replaced, kept in step.
|
|
217
|
+
var choice = $("#node-input-homeAssistant").val();
|
|
218
|
+
// Through its output until a broker is chosen (read before the
|
|
219
|
+
// dialog's values are applied).
|
|
220
|
+
var broker = $("#node-input-broker").val();
|
|
221
|
+
node.publishesThroughOutput = throughOutput(node) && (!broker || broker === "_ADD_");
|
|
222
|
+
node.publishState = choice !== "off";
|
|
223
|
+
node.discovery = choice === "discovery";
|
|
178
224
|
Object.keys(MOVED).forEach(function (key) { node[key] = ""; });
|
|
179
225
|
// Its targets become ids: their topics are the lights' adapters' now.
|
|
180
226
|
var targets = parsedTargets($("#node-input-targets").val());
|
|
@@ -211,10 +257,21 @@
|
|
|
211
257
|
</div>
|
|
212
258
|
<div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
|
|
213
259
|
<div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area" placeholder="needed when publishing"></div>
|
|
214
|
-
<div class="form-row"
|
|
215
|
-
|
|
260
|
+
<div class="form-row">
|
|
261
|
+
<label for="node-input-homeAssistant">Publish</label>
|
|
262
|
+
<select id="node-input-homeAssistant">
|
|
263
|
+
<option value="off">Don't publish</option>
|
|
264
|
+
<option value="state">MQTT state</option>
|
|
265
|
+
<option value="discovery">MQTT state and Home Assistant discovery</option>
|
|
266
|
+
</select>
|
|
267
|
+
</div>
|
|
268
|
+
<div class="form-row room-broker"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
|
|
269
|
+
<div class="form-tips room-broker">With a broker, the room publishes itself: an MQTT out on its first output, and a
|
|
270
|
+
Status node, are no longer needed and can be deleted.</div>
|
|
271
|
+
<div class="form-tips room-through-output">This room publishes through its first output, as before 6.2, and keeps
|
|
272
|
+
working that way. Choose a Broker to let it publish itself.</div>
|
|
216
273
|
<div class="form-row"><label for="node-input-displayName">Display name</label><input type="text" id="node-input-displayName"></div>
|
|
217
|
-
<div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
274
|
+
<div class="form-row room-discovery"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
218
275
|
<div class="form-row"><label for="node-input-targets">Targets JSON</label><input type="text" id="node-input-targets"></div>
|
|
219
276
|
<div class="form-row"><label for="node-input-initialTransitionSeconds">Turn-on transition seconds</label><input type="number" id="node-input-initialTransitionSeconds"></div>
|
|
220
277
|
</script>
|
|
@@ -225,8 +282,8 @@
|
|
|
225
282
|
<h3>Style</h3>
|
|
226
283
|
<p>Wire a <i>circadian lighting policy</i> into the room to style its lights over the day. The room keeps the
|
|
227
284
|
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
|
|
229
|
-
releases a light. A style never switches a light on or off and never reaches a light that an owner holds or a
|
|
285
|
+
wall-switch press), on each new style for lights that are on, after someone else's bare ON, and when the last
|
|
286
|
+
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
287
|
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
288
|
<code>msg.lighting = {kind: "style", values: {brightnessPct, colorTempKelvin} | null, transitionSeconds, until}</code>.</p>
|
|
232
289
|
<p><b>From 5.x:</b> circadian lighting, sleep, the wake and bed times and the house schedule moved to the circadian
|
|
@@ -243,25 +300,34 @@
|
|
|
243
300
|
nothing. For a light that isn't Zigbee2MQTT's, any flow that answers <code>msg.light</code> commands with
|
|
244
301
|
<code>msg.light</code> readings works in the adapter's place (see the README's neutral light contract).</p>
|
|
245
302
|
<h3>Publishing</h3>
|
|
246
|
-
<p>
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
<code
|
|
303
|
+
<p><b>Publish</b> adds what it publishes for other systems to see, named after the <b>Area</b>, which is
|
|
304
|
+
needed unless it is <i>Don't publish</i>. Topics and IDs use it in lowercase, with spaces and other characters (anything but
|
|
305
|
+
letters, digits, <code>_</code> and <code>-</code>) as <code>_</code>: <i>Living Room</i> publishes under
|
|
306
|
+
<code>home/living_room/…</code>.</p>
|
|
250
307
|
<dl class="message-properties">
|
|
251
|
-
<dt>Publish state
|
|
252
|
-
<code>home/<area>/lighting/<target>/control</code>, and
|
|
253
|
-
<code>home/<area>/lighting/availability</code>
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
308
|
+
<dt>Publish</dt><dd><i>Don't publish</i>; <i>MQTT state</i>, plain MQTT for any system to read: each light's control state on
|
|
309
|
+
<code>home/<area>/lighting/<target>/control</code>, and the room's availability on
|
|
310
|
+
<code>home/<area>/lighting/availability</code>; <i>MQTT state and Home Assistant discovery</i>: that, and
|
|
311
|
+
a control sensor for each light announced to Home Assistant, which reads that state. At every start the room also clears the circadian, sleep, wake and bed entities it published before 6.0.
|
|
312
|
+
A room saved before this setting reads its two old ones (Publish state over MQTT, Home Assistant discovery):
|
|
313
|
+
off/off is Don't publish, on/off MQTT state, on/on MQTT state and Home Assistant discovery, and not set at all
|
|
314
|
+
keeps publishing both.</dd>
|
|
315
|
+
<dt>Broker</dt><dd>Node-RED's MQTT broker node. With one, the room publishes itself: each time the broker connects,
|
|
316
|
+
reconnects included, and each time Home Assistant comes back (<code>online</code> on
|
|
317
|
+
<code><prefix>/status</code>), it clears what it no longer publishes and announces its entities,
|
|
318
|
+
availability and every light's control state, so they come back by themselves. Each connect also runs its
|
|
319
|
+
startup, as a Status node's "connected" did without a broker: each light is asked for a reading. <code>offline</code> as it stops;
|
|
320
|
+
deleted, everything it published is cleared. An MQTT out on output 1 and a Status node are then no longer needed:
|
|
321
|
+
output 1 sends nothing, and a Status node still wired in is ignored. Needed for a new room unless Publish is <i>Don't publish</i>;
|
|
322
|
+
opening and saving the room offers the first broker in your flows. A room saved before 6.2 that publishes keeps
|
|
323
|
+
publishing through output 1 and needs no broker until you choose one. Without one, the room publishes through output 1 as
|
|
324
|
+
before: once the flows start and at its startup message, which a Status node watching your MQTT out sends each
|
|
325
|
+
time it connects, with <code>offline</code> getting through only when this node is deployed on its own, so set
|
|
326
|
+
the MQTT broker node's Birth, Close and Will messages to the same (see the README).</dd>
|
|
261
327
|
<dt>Discovery prefix</dt><dd>the topic prefix Home Assistant listens on for discovery: <code>homeassistant</code>
|
|
262
|
-
unless you changed it in Home Assistant's MQTT settings.</dd>
|
|
328
|
+
unless you changed it in Home Assistant's MQTT settings. Shown with Home Assistant discovery.</dd>
|
|
263
329
|
</dl>
|
|
264
|
-
<p>New nodes start with
|
|
330
|
+
<p>New nodes start with <i>Don't publish</i>.</p>
|
|
265
331
|
<h3>Targets</h3>
|
|
266
332
|
<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
333
|
for a light that only switches on and off: it is never sent brightness, colour or a transition, styles skip it,
|
|
@@ -271,8 +337,8 @@
|
|
|
271
337
|
<p>Each target has one control state:</p>
|
|
272
338
|
<dl class="message-properties">
|
|
273
339
|
<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
|
|
275
|
-
|
|
340
|
+
<dt>overridden</dt><dd>another owner, such as an activity or a scene, holds the light on or off. Styles and
|
|
341
|
+
owner-less intents leave it alone until it is released.</dd>
|
|
276
342
|
<dt>manual</dt><dd>a person set the light: an intent with <code>manual: true</code> (a wall switch's double
|
|
277
343
|
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
344
|
manual. Switching circadian lighting on returns manual lights to in-control.</dd>
|
|
@@ -281,7 +347,15 @@
|
|
|
281
347
|
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
|
|
282
348
|
seen at the light), or a release. Any other intent, including motion ON or OFF and owner-less values, leaves it
|
|
283
349
|
alone and is traced as <code>ignored held-by</code>; other targets in the same intent are still handled.
|
|
284
|
-
|
|
350
|
+
A person switching a held light off returns it to in-control; a person switching on a light an owner holds off
|
|
351
|
+
makes it manual. Either way it leaves every owner, and their later releases leave it alone.</p>
|
|
352
|
+
<p>Owners stack, per light. The first owner to take a light records what it was: its control state, whether it was
|
|
353
|
+
on, and the values it last reported. A newer owner goes on top and sets the light; the owner beneath keeps its
|
|
354
|
+
own request, and sending again updates it without changing the light. Releasing the owner on top hands the light
|
|
355
|
+
to the owner beneath, with what that owner last asked for; releasing an owner beneath just drops it. When the
|
|
356
|
+
last owner lets go, the light goes back to what was recorded: a light the room was running is the room's again,
|
|
357
|
+
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
|
|
358
|
+
gets its values back and stays manual.</p>
|
|
285
359
|
<p>The control states are kept in the node's context. When the node starts with nothing saved (its first deploy,
|
|
286
360
|
or a redeploy or restart without a context store, see the README), it can't know which lights were held or set
|
|
287
361
|
by a person, so it leaves every light as it is: no style restyles a light until an intent or release names it,
|
|
@@ -297,15 +371,21 @@
|
|
|
297
371
|
<dt>lighting.kind = "style"</dt>
|
|
298
372
|
<dd>how lights should look, usually from a circadian lighting policy (see Style).</dd>
|
|
299
373
|
<dt>lighting.owner <span class="property-type">string</span></dt>
|
|
300
|
-
<dd>on an <code>intent</code
|
|
374
|
+
<dd>on an <code>intent</code>, holds its targets on or off for this owner (overridden), on top of any other
|
|
375
|
+
owner's. With
|
|
301
376
|
<code>preserveManual: true</code>, manual lights are skipped.</dd>
|
|
377
|
+
<dt>lighting.area <span class="property-type">string</span></dt>
|
|
378
|
+
<dd>on an <code>intent</code> or <code>release</code>, the room it is for: this room acts on it only when it
|
|
379
|
+
matches its <b>Area</b> (compared as in topics), so a scene wired to several rooms reaches only its own
|
|
380
|
+
lights. Without it, any room it reaches acts on it.</dd>
|
|
302
381
|
<dt>lighting.kind = "release"</dt>
|
|
303
|
-
<dd>
|
|
304
|
-
|
|
382
|
+
<dd>lets go of overridden <code>targets</code> (default: all) for <code>owner</code>, or for every owner without
|
|
383
|
+
one. A light goes to the owner beneath, or with none left back to what it was before the first.</dd>
|
|
305
384
|
</dl>
|
|
306
385
|
<h3>Outputs</h3>
|
|
307
386
|
<ol class="node-ports">
|
|
308
|
-
<li>MQTT publications, for an MQTT out node
|
|
387
|
+
<li>MQTT publications, for an MQTT out node, when it has no <b>Broker</b> (with one, it publishes itself and this
|
|
388
|
+
output sends nothing): unless <b>Publish</b> is <i>Don't publish</i>, on startup and whenever a target's
|
|
309
389
|
control state or availability changes, a retained message on <code>home/<area>/lighting/<target>/control</code>
|
|
310
390
|
with payload <code>{"state": "in-control" | "overridden" | "manual", "owner": string | null, "available"?: boolean}</code>
|
|
311
391
|
(<code>available</code> once its adapter has reported it), and the room's availability and discovery.</li>
|
|
@@ -315,4 +395,9 @@
|
|
|
315
395
|
<li>Each light's reading, <code>msg.light</code>, passed on with <code>control</code> and <code>manual</code>, for
|
|
316
396
|
activity lighting.</li>
|
|
317
397
|
</ol>
|
|
398
|
+
<h3>When MQTT out connects</h3>
|
|
399
|
+
<p>Wire a <b>Status node</b> whose scope is your MQTT out node into this node. Each time MQTT out shows
|
|
400
|
+
"connected", this node takes it as its startup message (<code>msg.lighting = {kind: "startup"}</code>) and announces itself again:
|
|
401
|
+
Node-RED's MQTT broker node drops what it is given before it connects, so what the node sends as the flows
|
|
402
|
+
start is lost on a first start, a full deploy or a restart. Any other status message is ignored.</p>
|
|
318
403
|
</script>
|