@avantics/node-red-home-automation 6.2.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -12
- package/dist/lib/activity-lighting-controller.d.ts +1 -0
- package/dist/lib/activity-lighting-controller.js +37 -10
- package/dist/lib/avr-controller.d.ts +3 -0
- package/dist/lib/avr-controller.js +24 -2
- package/dist/lib/backlighting-controller.d.ts +5 -2
- package/dist/lib/backlighting-controller.js +27 -2
- package/dist/lib/display-mode-controller.d.ts +3 -0
- package/dist/lib/display-mode-controller.js +43 -16
- package/dist/lib/esphome-sensor.d.ts +73 -0
- package/dist/lib/esphome-sensor.js +261 -0
- package/dist/lib/ha-discovery.js +3 -2
- package/dist/lib/occupancy-fusion.d.ts +1 -0
- package/dist/lib/occupancy-fusion.js +15 -2
- package/dist/lib/scene.d.ts +9 -1
- package/dist/lib/scene.js +61 -8
- package/dist/lib/source-capability-controller.d.ts +4 -1
- package/dist/lib/source-capability-controller.js +49 -2
- package/dist/lib/target-observation.d.ts +14 -0
- package/dist/lib/target-observation.js +22 -0
- package/dist/lib/theatre-activity-controller.d.ts +5 -0
- package/dist/lib/theatre-activity-controller.js +87 -12
- package/dist/lib/theatre-state.d.ts +2 -0
- package/dist/lib/theatre-state.js +10 -1
- package/dist/lib/wled.d.ts +48 -0
- package/dist/lib/wled.js +105 -0
- package/dist/lib/z2m-power.d.ts +38 -0
- package/dist/lib/z2m-power.js +83 -0
- package/dist/lib/z2m-sensor.d.ts +37 -0
- package/dist/lib/z2m-sensor.js +88 -0
- package/dist/nodes/activity-lighting-controller.html +2 -1
- package/dist/nodes/apollo-r-pro-1.d.ts +2 -0
- package/dist/nodes/apollo-r-pro-1.html +80 -0
- package/dist/nodes/apollo-r-pro-1.js +4 -0
- package/dist/nodes/avr-controller.html +2 -1
- package/dist/nodes/avr-controller.js +1 -1
- package/dist/nodes/backlighting-controller.html +2 -1
- package/dist/nodes/backlighting-controller.js +3 -2
- package/dist/nodes/circadian-policy.html +2 -1
- package/dist/nodes/cover-controller.html +2 -1
- package/dist/nodes/cover-group.html +2 -1
- package/dist/nodes/device-side.d.ts +1 -0
- package/dist/nodes/device-side.js +7 -3
- package/dist/nodes/display-mode-controller.html +2 -1
- package/dist/nodes/display-mode-controller.js +11 -2
- package/dist/nodes/esphome-sensor.d.ts +2 -0
- package/dist/nodes/esphome-sensor.js +77 -0
- package/dist/nodes/everything-presence-one.d.ts +2 -0
- package/dist/nodes/everything-presence-one.html +78 -0
- package/dist/nodes/everything-presence-one.js +4 -0
- package/dist/nodes/house-schedule-mqtt.html +2 -1
- package/dist/nodes/motion-policy.html +6 -4
- package/dist/nodes/motion-policy.js +10 -1
- package/dist/nodes/occupancy-fusion.html +5 -1
- package/dist/nodes/occupancy-fusion.js +2 -1
- package/dist/nodes/room-controller.html +2 -1
- package/dist/nodes/scene.html +25 -4
- package/dist/nodes/scene.js +9 -2
- package/dist/nodes/shelly-cover.html +2 -1
- package/dist/nodes/shelly-switch.html +2 -1
- package/dist/nodes/source-capability-controller.html +2 -1
- package/dist/nodes/source-capability-controller.js +3 -2
- package/dist/nodes/switch-policy.html +2 -1
- package/dist/nodes/theatre-activity-controller.html +6 -3
- package/dist/nodes/theatre-state-contract.html +2 -1
- package/dist/nodes/wled.d.ts +3 -0
- package/dist/nodes/wled.html +56 -0
- package/dist/nodes/wled.js +53 -0
- package/dist/nodes/z2m-cover.html +2 -1
- package/dist/nodes/z2m-light.html +4 -2
- package/dist/nodes/z2m-light.js +17 -0
- package/dist/nodes/z2m-power.d.ts +3 -0
- package/dist/nodes/z2m-power.html +58 -0
- package/dist/nodes/z2m-power.js +53 -0
- package/dist/nodes/z2m-sensor.d.ts +3 -0
- package/dist/nodes/z2m-sensor.html +69 -0
- package/dist/nodes/z2m-sensor.js +62 -0
- package/examples/Scene.json +8 -56
- package/package.json +31 -16
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
+
export type OccupancyKind = "motion" | "presence";
|
|
3
|
+
export interface Z2mSensorConfig {
|
|
4
|
+
baseTopic: string;
|
|
5
|
+
friendlyName: string;
|
|
6
|
+
occupancyIs: OccupancyKind;
|
|
7
|
+
}
|
|
8
|
+
export interface Z2mSensorState {
|
|
9
|
+
motion: boolean | null;
|
|
10
|
+
presence: boolean | null;
|
|
11
|
+
illuminance: number | null;
|
|
12
|
+
online: boolean | null;
|
|
13
|
+
}
|
|
14
|
+
export interface Z2mSensorMessage {
|
|
15
|
+
topic?: unknown;
|
|
16
|
+
payload?: unknown;
|
|
17
|
+
retain?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface SensorReading {
|
|
20
|
+
source: "motion" | "presence" | "illuminance";
|
|
21
|
+
payload: boolean | number;
|
|
22
|
+
}
|
|
23
|
+
export declare function normaliseZ2mSensorConfig(config: {
|
|
24
|
+
baseTopic?: unknown;
|
|
25
|
+
friendlyName?: unknown;
|
|
26
|
+
occupancyIs?: unknown;
|
|
27
|
+
}): Z2mSensorConfig;
|
|
28
|
+
export declare function z2mSensorTopics(config: Z2mSensorConfig): {
|
|
29
|
+
device: string;
|
|
30
|
+
availability: string;
|
|
31
|
+
};
|
|
32
|
+
export declare function transitionZ2mSensor(saved: Partial<Z2mSensorState> | undefined, msg: Z2mSensorMessage, config: Z2mSensorConfig): {
|
|
33
|
+
state: Z2mSensorState;
|
|
34
|
+
occupancy: SensorReading[];
|
|
35
|
+
light: SensorReading[];
|
|
36
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
37
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normaliseZ2mSensorConfig = normaliseZ2mSensorConfig;
|
|
4
|
+
exports.z2mSensorTopics = z2mSensorTopics;
|
|
5
|
+
exports.transitionZ2mSensor = transitionZ2mSensor;
|
|
6
|
+
const mqtt_message_1 = require("./mqtt-message");
|
|
7
|
+
function normaliseZ2mSensorConfig(config) {
|
|
8
|
+
const baseTopic = String(config.baseTopic ?? "").trim().replace(/^\/+|\/+$/g, "") || "zigbee2mqtt";
|
|
9
|
+
// The user's own device's: no default.
|
|
10
|
+
const friendlyName = String(config.friendlyName ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
11
|
+
if (!friendlyName)
|
|
12
|
+
throw new Error("the device's friendly name is required");
|
|
13
|
+
if (/[+#]/.test(baseTopic) || /[+#]/.test(friendlyName))
|
|
14
|
+
throw new Error("the base topic and friendly name can't contain + or #");
|
|
15
|
+
const occupancyIs = config.occupancyIs === undefined || config.occupancyIs === null || config.occupancyIs === "" ? "motion" : config.occupancyIs;
|
|
16
|
+
if (occupancyIs !== "motion" && occupancyIs !== "presence")
|
|
17
|
+
throw new Error("occupancy is must be motion or presence");
|
|
18
|
+
return { baseTopic, friendlyName, occupancyIs };
|
|
19
|
+
}
|
|
20
|
+
function z2mSensorTopics(config) {
|
|
21
|
+
const device = `${config.baseTopic}/${config.friendlyName}`;
|
|
22
|
+
return { device, availability: `${device}/availability` };
|
|
23
|
+
}
|
|
24
|
+
function transitionZ2mSensor(saved, msg, config) {
|
|
25
|
+
const state = {
|
|
26
|
+
motion: typeof saved?.motion === "boolean" ? saved.motion : null,
|
|
27
|
+
presence: typeof saved?.presence === "boolean" ? saved.presence : null,
|
|
28
|
+
illuminance: typeof saved?.illuminance === "number" ? saved.illuminance : null,
|
|
29
|
+
online: typeof saved?.online === "boolean" ? saved.online : null
|
|
30
|
+
};
|
|
31
|
+
const topics = z2mSensorTopics(config);
|
|
32
|
+
const occupancy = [];
|
|
33
|
+
const light = [];
|
|
34
|
+
const traces = [];
|
|
35
|
+
const trace = (event, outcome, reason = null, details = {}) => {
|
|
36
|
+
traces.push({ event, outcome, reason, details });
|
|
37
|
+
};
|
|
38
|
+
if (msg.topic === topics.device) {
|
|
39
|
+
const report = (0, mqtt_message_1.parsedPayload)(msg.payload);
|
|
40
|
+
if (!(0, mqtt_message_1.isObject)(report))
|
|
41
|
+
throw new Error(`${topics.device} must carry the device's state object`);
|
|
42
|
+
const retained = msg.retain === true;
|
|
43
|
+
// Each occupancy field, as the room's source for it.
|
|
44
|
+
const fields = [];
|
|
45
|
+
if (Object.hasOwn(report, "occupancy"))
|
|
46
|
+
fields.push([config.occupancyIs, report.occupancy]);
|
|
47
|
+
if (Object.hasOwn(report, "presence"))
|
|
48
|
+
fields.push(["presence", report.presence]);
|
|
49
|
+
for (const [source, value] of fields) {
|
|
50
|
+
if (typeof value !== "boolean")
|
|
51
|
+
continue;
|
|
52
|
+
if (retained) {
|
|
53
|
+
// A retained state is an old one: never acted on, and not kept
|
|
54
|
+
// either, so the next live report is passed on whatever it says.
|
|
55
|
+
trace(source, "ignored", "retained", { value });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (state[source] === value)
|
|
59
|
+
continue;
|
|
60
|
+
state[source] = value;
|
|
61
|
+
occupancy.push({ source, payload: value });
|
|
62
|
+
trace(source, "changed", null, { value });
|
|
63
|
+
}
|
|
64
|
+
// Lux: illuminance_lux where a device sends it beside a raw illuminance.
|
|
65
|
+
const lux = typeof report.illuminance_lux === "number" ? report.illuminance_lux
|
|
66
|
+
: typeof report.illuminance === "number" ? report.illuminance : null;
|
|
67
|
+
if (lux !== null && Number.isFinite(lux) && lux !== state.illuminance) {
|
|
68
|
+
state.illuminance = lux;
|
|
69
|
+
light.push({ source: "illuminance", payload: lux });
|
|
70
|
+
trace("illuminance", "changed", null, { lux });
|
|
71
|
+
}
|
|
72
|
+
state.online = true;
|
|
73
|
+
}
|
|
74
|
+
else if (msg.topic === topics.availability) {
|
|
75
|
+
// {"state": "online"}, or the plain "online" of older setups.
|
|
76
|
+
const received = (0, mqtt_message_1.parsedPayload)(msg.payload);
|
|
77
|
+
const value = (0, mqtt_message_1.isObject)(received) ? received.state : received;
|
|
78
|
+
if (value !== "online" && value !== "offline")
|
|
79
|
+
throw new Error(`${topics.availability} must say online or offline`);
|
|
80
|
+
state.online = value === "online";
|
|
81
|
+
trace("availability", value);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
trace("message", "ignored", "other-topic", { topic: typeof msg.topic === "string" ? msg.topic : null });
|
|
85
|
+
}
|
|
86
|
+
return { state, occupancy, light, traces };
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=z2m-sensor.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType("home-apollo-r-pro-1", {
|
|
3
|
+
category: "home devices",
|
|
4
|
+
color: "#e2d96e",
|
|
5
|
+
defaults: {
|
|
6
|
+
name: {value: ""},
|
|
7
|
+
// Node-RED's MQTT broker node, through which it subscribes to the
|
|
8
|
+
// device's topics. The editor offers the first broker when the dialog is
|
|
9
|
+
// opened and saved.
|
|
10
|
+
broker: {value: "", type: "mqtt-broker", required: true},
|
|
11
|
+
// No default: it names the user's own device.
|
|
12
|
+
device: {value: "", required: true, validate: function (v) {
|
|
13
|
+
var device = String(v || "").trim().replace(/^\/+|\/+$/g, "");
|
|
14
|
+
return device !== "" && !/[+#]/.test(device);
|
|
15
|
+
}},
|
|
16
|
+
// Where the device's discovery is: ESPHome's default. A node saved
|
|
17
|
+
// before this setting loads without it (the editor applies no defaults
|
|
18
|
+
// to deployed flows); missing or empty means homeassistant, as the
|
|
19
|
+
// runtime reads it.
|
|
20
|
+
discoveryPrefix: {value: "homeassistant", validate: function (v) {
|
|
21
|
+
return !/[+#]/.test(String(v === undefined || v === null ? "" : v));
|
|
22
|
+
}}
|
|
23
|
+
},
|
|
24
|
+
inputs: 1,
|
|
25
|
+
outputs: 2,
|
|
26
|
+
outputLabels: ["motion and presence, to occupancy fusion", "light level, to the motion lighting policy"],
|
|
27
|
+
icon: "font-awesome/fa-eye",
|
|
28
|
+
label: function () { return this.name || this.device || "apollo r pro-1"; },
|
|
29
|
+
paletteLabel: "apollo r pro-1"
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script type="text/html" data-template-name="home-apollo-r-pro-1">
|
|
34
|
+
<div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
|
|
35
|
+
<div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
|
|
36
|
+
<div class="form-row"><label for="node-input-device">Device</label><input type="text" id="node-input-device" placeholder="its ESPHome name"></div>
|
|
37
|
+
<div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
38
|
+
<div class="form-tips">It subscribes to the device's entities and status itself: no MQTT in, change or function nodes.</div>
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script type="text/html" data-help-name="home-apollo-r-pro-1">
|
|
42
|
+
<p>Connects an <b>Apollo R PRO-1</b> (Apollo Automation's ESPHome presence sensor) to a room: its two radars and its
|
|
43
|
+
light sensor become the messages <b>home occupancy fusion</b> and the <b>home motion lighting policy</b> take, over
|
|
44
|
+
ESPHome's own MQTT messages: no function or change nodes, and never Home Assistant.</p>
|
|
45
|
+
<p>The device: <a href="https://wiki.apolloautomation.com/products/rpro1/introduction/" target="_blank">Apollo R PRO-1</a> (Apollo Automation's documentation).</p>
|
|
46
|
+
<h3>Wiring</h3>
|
|
47
|
+
<ol>
|
|
48
|
+
<li>Output 1 (motion and presence) → occupancy fusion, with its presence sensor set to hold.</li>
|
|
49
|
+
<li>Output 2 (light level) → the motion lighting policy.</li>
|
|
50
|
+
</ol>
|
|
51
|
+
<p>Choose the <b>Broker</b> the device uses (MQTT on in its ESPHome configuration), and set <b>Device</b> to its ESPHome
|
|
52
|
+
name, the prefix of its MQTT topics (such as <code>apollo-r-pro-1-1a2b3c</code>).</p>
|
|
53
|
+
<h3>What it reads</h3>
|
|
54
|
+
<p>It has two radars, an LD2450 and an LD2412, and no PIR. Each role counts as on when any radar that has reported
|
|
55
|
+
says so, and off when every one that has reported says off. Apollo's firmware has named the LD2450's entities
|
|
56
|
+
without a prefix on earlier releases and with <code>ld2450_</code> on current ones; the node reads both.</p>
|
|
57
|
+
<ul>
|
|
58
|
+
<li><b>Motion</b>: <code>binary_sensor/moving_target</code> (or <code>ld2450_moving_target</code>) and
|
|
59
|
+
<code>binary_sensor/ld2412_moving_target</code>: a moving target.</li>
|
|
60
|
+
<li><b>Presence</b>: <code>binary_sensor/presence</code> (or <code>ld2450_presence</code>) and
|
|
61
|
+
<code>binary_sensor/ld2412_presence</code>: anyone there, still or moving.</li>
|
|
62
|
+
<li><b>Light level</b>: <code>sensor/ltr390_light</code>, the LTR390, in lux.</li>
|
|
63
|
+
</ul>
|
|
64
|
+
<h3>How it finds its entities</h3>
|
|
65
|
+
<p>From the device's own MQTT discovery first: each entity it describes, by device class (motion; occupancy or
|
|
66
|
+
presence; illuminance), with its state topic, skipping those it marks disabled by default, so a firmware that renames an entity still works. The device's model
|
|
67
|
+
in its discovery must be this one. Without discovery (turn it on with <code>mqtt: discovery: true</code> in the
|
|
68
|
+
device's ESPHome configuration and flash it again), or with another model's, it uses the entity names below. Its
|
|
69
|
+
status ends with <i>discovered</i> or <i>preset</i>.</p>
|
|
70
|
+
<h3>Readings</h3>
|
|
71
|
+
<ul>
|
|
72
|
+
<li>Output 1: <code>{source: "motion" | "presence", payload: true | false}</code>, from ON and OFF only.</li>
|
|
73
|
+
<li>Output 2: <code>{source: "illuminance", payload: <lux>}</code>, from a number only.</li>
|
|
74
|
+
<li>Anything else (such as <code>nan</code>) is ignored with a trace, and only a change is sent.</li>
|
|
75
|
+
<li>As Node-RED starts, ESPHome's retained states are the device's current ones while its status is online. They
|
|
76
|
+
are sent with <code>msg.baseline = true</code>: an occupied room switches nothing on, and an empty one starts its
|
|
77
|
+
vacancy, so its lights go off when the motion policy's delay runs out. A retained state from a device that isn't
|
|
78
|
+
online is ignored.</li>
|
|
79
|
+
</ul>
|
|
80
|
+
</script>
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
|
|
32
32
|
}
|
|
33
33
|
RED.nodes.registerType("home-avr-controller", {
|
|
34
|
-
category: "home
|
|
34
|
+
category: "home theatre",
|
|
35
|
+
paletteLabel: "receiver",
|
|
35
36
|
color: "#c7d9f1",
|
|
36
37
|
defaults: {
|
|
37
38
|
// A marker only a node new from the palette has, as core nodes do: import
|
|
@@ -108,7 +108,7 @@ const registerAvrController = (RED) => {
|
|
|
108
108
|
node.warn("volume requests with value in the receiver's own 0-98 were removed in 6.0 and are rejected: " +
|
|
109
109
|
"send valueDb (dB, where the receiver's 80 is 0 dB) instead");
|
|
110
110
|
}
|
|
111
|
-
const outputs = [...result.events, ...result.targetStates];
|
|
111
|
+
const outputs = [...result.events, ...result.targetStates, ...result.observations];
|
|
112
112
|
if (commands.length || outputs.length) {
|
|
113
113
|
send([
|
|
114
114
|
commands.length ? commands : null,
|
|
@@ -50,8 +50,9 @@ const registerBacklightingController = (RED) => {
|
|
|
50
50
|
null
|
|
51
51
|
]);
|
|
52
52
|
}
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
const theatre = [...result.events, ...result.observations];
|
|
54
|
+
if (theatre.length) {
|
|
55
|
+
send([null, theatre.map((event) => ({ payload: undefined, ...event }))]);
|
|
55
56
|
}
|
|
56
57
|
updateStatus(result.status);
|
|
57
58
|
schedule(result.state);
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
|
|
28
28
|
}
|
|
29
29
|
RED.nodes.registerType("home-circadian-lighting-policy", {
|
|
30
|
-
category: "home
|
|
30
|
+
category: "home lighting",
|
|
31
|
+
paletteLabel: "circadian policy",
|
|
31
32
|
color: "#ffd27f",
|
|
32
33
|
defaults: {
|
|
33
34
|
name: {value: ""},
|
|
@@ -26,7 +26,8 @@
|
|
|
26
26
|
return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
|
|
27
27
|
}
|
|
28
28
|
RED.nodes.registerType("home-cover-controller", {
|
|
29
|
-
category: "home
|
|
29
|
+
category: "home covers",
|
|
30
|
+
paletteLabel: "cover",
|
|
30
31
|
color: "#e2d96e",
|
|
31
32
|
defaults: {
|
|
32
33
|
// A marker only a node new from the palette has, as core nodes do: import
|
|
@@ -11,6 +11,7 @@ export interface DeviceSide {
|
|
|
11
11
|
broker: boolean;
|
|
12
12
|
publish(publications: readonly DevicePublication[]): Array<Record<string, unknown>> | null;
|
|
13
13
|
fromBroker(msg: InputMessage): boolean;
|
|
14
|
+
subscribe(topic: string): void;
|
|
14
15
|
}
|
|
15
16
|
export declare function deviceSide(node: Node, broker: BrokerNode | null, prefix: string, subscriptions: string[], trace: TraceMetadata, handle: (msg: InputMessage, send: Send) => void, onConnected?: () => void): DeviceSide;
|
|
16
17
|
export declare function deviceBroker(RED: {
|
|
@@ -29,18 +29,22 @@ onConnected) {
|
|
|
29
29
|
return {
|
|
30
30
|
broker: false,
|
|
31
31
|
publish: (publications) => publications.length ? publications.map((publication) => ({ ...publication })) : null,
|
|
32
|
-
fromBroker: () => false
|
|
32
|
+
fromBroker: () => false,
|
|
33
|
+
subscribe: () => { }
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
const link = (0, mqtt_broker_link_1.brokerLink)(broker, node.id, (error) => node.error(error));
|
|
36
|
-
|
|
37
|
+
const subscribe = (topic) => {
|
|
37
38
|
link.subscribe(topic, (message) => handle({ topic: message.topic, payload: message.payload, retain: message.retain }, node.send.bind(node)));
|
|
38
|
-
}
|
|
39
|
+
};
|
|
40
|
+
for (const topic of subscriptions)
|
|
41
|
+
subscribe(topic);
|
|
39
42
|
if (onConnected)
|
|
40
43
|
link.onConnected(onConnected);
|
|
41
44
|
node.on("close", (removed, done) => link.close(removed, done));
|
|
42
45
|
return {
|
|
43
46
|
broker: true,
|
|
47
|
+
subscribe,
|
|
44
48
|
publish(publications) {
|
|
45
49
|
for (const { topic, payload, retain } of publications)
|
|
46
50
|
link.publish(topic, text(payload), { retain: retain === true });
|
|
@@ -68,7 +68,9 @@ const registerDisplayModeController = (RED) => {
|
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
if (command.device === "projector" && command.operation === "query_power" && !projectorPowerMeterHost) {
|
|
71
|
-
|
|
71
|
+
// power: {kind: "read"} too, so a power meter node (such as a
|
|
72
|
+
// zigbee2mqtt power node) can be wired straight to it.
|
|
73
|
+
node.send([null, null, { payload: "query", display_command: command, power: { kind: "read" } }]);
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
76
|
const result = await transport.execute(command);
|
|
@@ -77,7 +79,7 @@ const registerDisplayModeController = (RED) => {
|
|
|
77
79
|
}
|
|
78
80
|
function process(msg, send) {
|
|
79
81
|
const result = (0, adapter_1.runReducer)(node, { area: (0, adapter_1.optionalArea)(config), component: "display-mode-controller" }, (saved, now) => (0, display_mode_controller_1.transitionDisplay)(saved, msg, controllerConfig, now));
|
|
80
|
-
const outputs = [...result.events, ...result.targetStates];
|
|
82
|
+
const outputs = [...result.events, ...result.targetStates, ...result.observations];
|
|
81
83
|
if (outputs.length) {
|
|
82
84
|
send([null, outputs.map((event) => ({ payload: undefined, ...event })), null]);
|
|
83
85
|
}
|
|
@@ -89,6 +91,13 @@ const registerDisplayModeController = (RED) => {
|
|
|
89
91
|
return result;
|
|
90
92
|
}
|
|
91
93
|
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
94
|
+
// A power meter node's reading (msg.power) is its projector's power.
|
|
95
|
+
const power = (0, adapter_1.objectField)(msg, "power");
|
|
96
|
+
if (power?.kind === "observed" && !(0, adapter_1.objectField)(msg, "display")) {
|
|
97
|
+
process({ display: { kind: "observed", device: "projector", watts: power.watts,
|
|
98
|
+
...(typeof power.observedAt === "string" ? { observedAt: power.observedAt } : {}) } }, send);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
92
101
|
process({
|
|
93
102
|
display: (0, adapter_1.objectField)(msg, "display")
|
|
94
103
|
}, send);
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.esphomeSensorNode = esphomeSensorNode;
|
|
4
|
+
const esphome_sensor_1 = require("../lib/esphome-sensor");
|
|
5
|
+
const adapter_1 = require("./adapter");
|
|
6
|
+
const device_side_1 = require("./device-side");
|
|
7
|
+
// One node type per ESPHome device: its entity names belong to its
|
|
8
|
+
// product's firmware, so the model is the node's, not a setting. Each
|
|
9
|
+
// device's node registers this with its model (see ESPHOME_MODELS).
|
|
10
|
+
function esphomeSensorNode(type, model) {
|
|
11
|
+
return (RED) => {
|
|
12
|
+
function HomeEsphomeSensor(config) {
|
|
13
|
+
RED.nodes.createNode(this, config);
|
|
14
|
+
const node = this;
|
|
15
|
+
let device;
|
|
16
|
+
let broker;
|
|
17
|
+
try {
|
|
18
|
+
device = (0, esphome_sensor_1.normaliseEsphomeSensorConfig)({ device: config.device, model, discoveryPrefix: config.discoveryPrefix });
|
|
19
|
+
// Newer than the MQTT in and out way of wiring adapters: it needs its
|
|
20
|
+
// broker.
|
|
21
|
+
broker = (0, device_side_1.deviceBroker)(RED, config.broker);
|
|
22
|
+
if (!broker)
|
|
23
|
+
throw new Error("choose its MQTT broker");
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const trace = { area: "", component: "esphome-sensor" };
|
|
30
|
+
node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
|
|
31
|
+
// Its discovery, its status and its preset's entities; then whatever its
|
|
32
|
+
// discovery names. ESPHome retains them, so on connect the broker hands
|
|
33
|
+
// over the device's description and current state, which passes as a
|
|
34
|
+
// baseline while the device is online.
|
|
35
|
+
const topics = (0, esphome_sensor_1.esphomeSensorTopics)(device);
|
|
36
|
+
const subscribed = new Set(topics.initial);
|
|
37
|
+
const side = (0, device_side_1.deviceSide)(node, broker, device.device, topics.initial, trace, (msg, send) => handle(msg, send));
|
|
38
|
+
function handle(msg, send) {
|
|
39
|
+
const result = (0, adapter_1.runReducer)(node, trace, (saved) => (0, esphome_sensor_1.transitionEsphomeSensor)(saved, msg, device));
|
|
40
|
+
for (const topic of result.topics) {
|
|
41
|
+
if (subscribed.has(topic))
|
|
42
|
+
continue;
|
|
43
|
+
subscribed.add(topic);
|
|
44
|
+
side.subscribe(topic);
|
|
45
|
+
}
|
|
46
|
+
// Output 1: motion and presence, for occupancy fusion. Output 2: the
|
|
47
|
+
// light level, for the motion lighting policy.
|
|
48
|
+
const outputs = [
|
|
49
|
+
result.occupancy.length ? result.occupancy.map((reading) => ({ ...reading })) : null,
|
|
50
|
+
result.light.length ? result.light.map((reading) => ({ ...reading })) : null
|
|
51
|
+
];
|
|
52
|
+
if (outputs.some((output) => output !== null))
|
|
53
|
+
send(outputs);
|
|
54
|
+
const state = result.state;
|
|
55
|
+
if (state.online === false) {
|
|
56
|
+
node.status({ fill: "grey", shape: "ring", text: "offline" });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const occupied = state.motion === true || state.presence === true;
|
|
60
|
+
const known = state.motion !== null || state.presence !== null;
|
|
61
|
+
// And where its entities came from: its discovery, or its preset.
|
|
62
|
+
const source = result.roles.source === "discovered" ? "discovered" : result.roles.source === "preset" ? "preset" : "preset: discovery is another model";
|
|
63
|
+
const parts = [known ? (occupied ? "occupied" : "clear") : "", state.illuminance !== null ? `${state.illuminance} lx` : "", source].filter(Boolean);
|
|
64
|
+
node.status({ fill: occupied ? "green" : "grey", shape: known ? "dot" : "ring", text: parts.join(" · ") });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
68
|
+
// Its device's messages come from the broker: an MQTT in node wired in
|
|
69
|
+
// changes nothing.
|
|
70
|
+
if (!side.fromBroker(msg))
|
|
71
|
+
handle(msg, send);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
RED.nodes.registerType(type, HomeEsphomeSensor);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=esphome-sensor.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType("home-everything-presence-one", {
|
|
3
|
+
category: "home devices",
|
|
4
|
+
color: "#e2d96e",
|
|
5
|
+
defaults: {
|
|
6
|
+
name: {value: ""},
|
|
7
|
+
// Node-RED's MQTT broker node, through which it subscribes to the
|
|
8
|
+
// device's topics. The editor offers the first broker when the dialog is
|
|
9
|
+
// opened and saved.
|
|
10
|
+
broker: {value: "", type: "mqtt-broker", required: true},
|
|
11
|
+
// No default: it names the user's own device.
|
|
12
|
+
device: {value: "", required: true, validate: function (v) {
|
|
13
|
+
var device = String(v || "").trim().replace(/^\/+|\/+$/g, "");
|
|
14
|
+
return device !== "" && !/[+#]/.test(device);
|
|
15
|
+
}},
|
|
16
|
+
// Where the device's discovery is: ESPHome's default. A node saved
|
|
17
|
+
// before this setting loads without it (the editor applies no defaults
|
|
18
|
+
// to deployed flows); missing or empty means homeassistant, as the
|
|
19
|
+
// runtime reads it.
|
|
20
|
+
discoveryPrefix: {value: "homeassistant", validate: function (v) {
|
|
21
|
+
return !/[+#]/.test(String(v === undefined || v === null ? "" : v));
|
|
22
|
+
}}
|
|
23
|
+
},
|
|
24
|
+
inputs: 1,
|
|
25
|
+
outputs: 2,
|
|
26
|
+
outputLabels: ["motion and presence, to occupancy fusion", "light level, to the motion lighting policy"],
|
|
27
|
+
icon: "font-awesome/fa-eye",
|
|
28
|
+
label: function () { return this.name || this.device || "everything presence one"; },
|
|
29
|
+
paletteLabel: "everything presence one"
|
|
30
|
+
});
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script type="text/html" data-template-name="home-everything-presence-one">
|
|
34
|
+
<div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
|
|
35
|
+
<div class="form-row"><label for="node-input-broker">Broker</label><input type="text" id="node-input-broker"></div>
|
|
36
|
+
<div class="form-row"><label for="node-input-device">Device</label><input type="text" id="node-input-device" placeholder="its ESPHome name"></div>
|
|
37
|
+
<div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
38
|
+
<div class="form-tips">It subscribes to the device's entities and status itself: no MQTT in, change or function nodes.</div>
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<script type="text/html" data-help-name="home-everything-presence-one">
|
|
42
|
+
<p>Connects an <b>Everything Presence One</b> (Everything Smart Technology's ESPHome presence sensor) to a room: its PIR,
|
|
43
|
+
its mmWave radar and its light sensor become the messages <b>home occupancy fusion</b> and the <b>home motion lighting
|
|
44
|
+
policy</b> take, over ESPHome's own MQTT messages: no function or change nodes, and never Home Assistant.</p>
|
|
45
|
+
<p>The device: <a href="https://docs.everythingsmart.io/docs/products/everything-presence-one-ep1" target="_blank">Everything Presence One</a> (Everything Smart Technology's documentation).</p>
|
|
46
|
+
<h3>Wiring</h3>
|
|
47
|
+
<ol>
|
|
48
|
+
<li>Output 1 (motion and presence) → occupancy fusion, with its presence sensor set to hold.</li>
|
|
49
|
+
<li>Output 2 (light level) → the motion lighting policy.</li>
|
|
50
|
+
</ol>
|
|
51
|
+
<p>Choose the <b>Broker</b> the device uses (MQTT on in its ESPHome configuration), and set <b>Device</b> to its ESPHome
|
|
52
|
+
name, the prefix of its MQTT topics (such as <code>everything-presence-one-1a2b3c</code>).</p>
|
|
53
|
+
<h3>What it reads</h3>
|
|
54
|
+
<ul>
|
|
55
|
+
<li><b>Motion</b>: <code>binary_sensor/pir</code>, the PIR: quick to see someone arrive.</li>
|
|
56
|
+
<li><b>Presence</b>: <code>binary_sensor/mmwave</code>, the radar: sees someone sitting still, so occupancy fusion
|
|
57
|
+
holds the room while they stay.</li>
|
|
58
|
+
<li><b>Light level</b>: <code>sensor/illuminance</code>, in lux.</li>
|
|
59
|
+
<li>Not its own <code>occupancy</code> entity: that combines the two on the device, and occupancy fusion does that
|
|
60
|
+
combining here.</li>
|
|
61
|
+
</ul>
|
|
62
|
+
<h3>How it finds its entities</h3>
|
|
63
|
+
<p>From the device's own MQTT discovery first: each entity it describes, by device class (motion; occupancy or
|
|
64
|
+
presence; illuminance), with its state topic, skipping those it marks disabled by default, so a firmware that renames an entity still works. The device's model
|
|
65
|
+
in its discovery must be this one. Without discovery (turn it on with <code>mqtt: discovery: true</code> in the
|
|
66
|
+
device's ESPHome configuration and flash it again), or with another model's, it uses the entity names below. Its
|
|
67
|
+
status ends with <i>discovered</i> or <i>preset</i>.</p>
|
|
68
|
+
<h3>Readings</h3>
|
|
69
|
+
<ul>
|
|
70
|
+
<li>Output 1: <code>{source: "motion" | "presence", payload: true | false}</code>, from ON and OFF only.</li>
|
|
71
|
+
<li>Output 2: <code>{source: "illuminance", payload: <lux>}</code>, from a number only.</li>
|
|
72
|
+
<li>Anything else (such as <code>nan</code>) is ignored with a trace, and only a change is sent.</li>
|
|
73
|
+
<li>As Node-RED starts, ESPHome's retained states are the device's current ones while its status is online. They
|
|
74
|
+
are sent with <code>msg.baseline = true</code>: an occupied room switches nothing on, and an empty one starts its
|
|
75
|
+
vacancy, so its lights go off when the motion policy's delay runs out. A retained state from a device that isn't
|
|
76
|
+
online is ignored.</li>
|
|
77
|
+
</ul>
|
|
78
|
+
</script>
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
return node.homeAssistant === null || node.homeAssistant === undefined;
|
|
20
20
|
}
|
|
21
21
|
RED.nodes.registerType("home-house-schedule-mqtt", {
|
|
22
|
-
category: "home
|
|
22
|
+
category: "home house",
|
|
23
|
+
paletteLabel: "house schedule mqtt",
|
|
23
24
|
color: "#ffd27f",
|
|
24
25
|
defaults: {
|
|
25
26
|
// A marker only a node new from the palette has, as core nodes do: import
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
return publishChoice(node) !== "off" || (saved && (on(node.publishState) || on(node.discovery)));
|
|
28
28
|
}
|
|
29
29
|
RED.nodes.registerType("home-motion-lighting-policy", {
|
|
30
|
-
category: "home
|
|
30
|
+
category: "home lighting",
|
|
31
|
+
paletteLabel: "motion policy",
|
|
31
32
|
color: "#d8bfd8",
|
|
32
33
|
defaults: {
|
|
33
34
|
// A marker only a node new from the palette has, as core nodes do: import
|
|
@@ -137,7 +138,8 @@
|
|
|
137
138
|
<dt>occupancy</dt><dd><code>msg.payload.occupied</code>, from the occupancy fusion node.</dd>
|
|
138
139
|
<dt>illuminance</dt><dd>the light level in lux.</dd>
|
|
139
140
|
<dt>area-enabled</dt><dd><code>true</code> or <code>false</code> for this node; <code>global-enabled</code> for every
|
|
140
|
-
motion node
|
|
141
|
+
motion node (deprecated, removed in 7.0: send <code>area-enabled</code> to each policy instead; it still works
|
|
142
|
+
until then, with a warning once per deploy and a note on the status). Any other value, such as <code>"ON"</code> (accepted before 6.0), is refused: nothing changes, the
|
|
141
143
|
node logs a warning once per deploy and shows it on its status.</dd>
|
|
142
144
|
<dt>delay</dt><dd>a new vacancy time, in <b>seconds</b>, the same unit as <b>Vacancy seconds</b>.</dd>
|
|
143
145
|
<dt>illuminance-cut-off</dt><dd>a new lux cutoff.</dd>
|
|
@@ -168,8 +170,8 @@
|
|
|
168
170
|
<code>home/<area>/motion/availability</code>. It acts on <code>ON</code>/<code>OFF</code> sent to
|
|
169
171
|
<code>…/enabled/set</code> and a delay of 0 to 86400 seconds sent to <code>…/delay/set</code>, as the
|
|
170
172
|
<code>area-enabled</code> and <code>delay</code> inputs do; wire an MQTT in node on
|
|
171
|
-
<code>home/<area>/motion/+/set</code> into this node. The shared <code>global-enabled</code> is
|
|
172
|
-
published, and the switch shows this node's enable only, so motion can still be off everywhere while it
|
|
173
|
+
<code>home/<area>/motion/+/set</code> into this node. The shared <code>global-enabled</code> (deprecated) is
|
|
174
|
+
not published, and the switch shows this node's enable only, so motion can still be off everywhere while it
|
|
173
175
|
shows on.</dd>
|
|
174
176
|
<dt>Publish: MQTT state and Home Assistant discovery</dt><dd>a motion lighting switch and a vacancy delay number (in the device's
|
|
175
177
|
configuration). It includes the MQTT state, which they read.</dd>
|
|
@@ -44,13 +44,17 @@ const registerMotionPolicy = (RED) => {
|
|
|
44
44
|
(0, adapter_1.invalidConfig)(node, error);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
+
// global-enabled, the house-wide enable every motion policy obeys, is
|
|
48
|
+
// deprecated (removed in 7.0): told once per deploy, and on the status
|
|
49
|
+
// from then on. It still works until then.
|
|
50
|
+
let usedGlobalEnabled = false;
|
|
47
51
|
function updateStatus(status) {
|
|
48
52
|
node.status({
|
|
49
53
|
fill: status.enabled ? "green" : "grey",
|
|
50
54
|
shape: "dot",
|
|
51
55
|
text: (status.enabled ? "enabled" : status.paused ? "paused" : "disabled") + " · " +
|
|
52
56
|
(status.illuminance === null ? "lux ?" : status.illuminance + " lux") + " · " +
|
|
53
|
-
status.delaySeconds + "s"
|
|
57
|
+
status.delaySeconds + "s" + (usedGlobalEnabled ? " · global-enabled is deprecated" : "")
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
function armOffTimer(delayMs, generation) {
|
|
@@ -105,6 +109,11 @@ const registerMotionPolicy = (RED) => {
|
|
|
105
109
|
});
|
|
106
110
|
if (input.source === "global-enabled") {
|
|
107
111
|
globalContext.set("MOTION_ENABLED_STATE", result.globalEnabled);
|
|
112
|
+
if (!usedGlobalEnabled) {
|
|
113
|
+
usedGlobalEnabled = true;
|
|
114
|
+
node.warn("global-enabled is deprecated and will be removed in 7.0: send area-enabled (true or false) to each " +
|
|
115
|
+
"motion lighting policy instead");
|
|
116
|
+
}
|
|
108
117
|
}
|
|
109
118
|
for (const effect of result.effects) {
|
|
110
119
|
if (effect.kind === "cancel-off-timer") {
|