@avantics/node-red-home-automation 4.0.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +447 -64
- package/contract-examples/room-lighting.mjs +39 -27
- package/contract-examples/switch-gestures.mjs +1 -1
- package/contract-examples/volume-ownership.mjs +6 -5
- package/dist/lib/activity-lighting-controller.d.ts +9 -2
- package/dist/lib/activity-lighting-controller.js +107 -19
- package/dist/lib/adopted-request.d.ts +17 -0
- package/dist/lib/adopted-request.js +61 -7
- package/dist/lib/avr-controller.d.ts +9 -3
- package/dist/lib/avr-controller.js +71 -24
- package/dist/lib/avr-publishing.d.ts +3 -3
- package/dist/lib/avr-publishing.js +11 -5
- package/dist/lib/backlighting-controller.d.ts +2 -0
- package/dist/lib/backlighting-controller.js +27 -7
- 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/cover-publishing.js +1 -1
- package/dist/lib/denon-protocol.d.ts +5 -1
- package/dist/lib/denon-protocol.js +27 -11
- package/dist/lib/display-mode-controller.d.ts +12 -5
- package/dist/lib/display-mode-controller.js +181 -87
- package/dist/lib/enable-input.d.ts +3 -0
- package/dist/lib/enable-input.js +18 -0
- package/dist/lib/house-schedule-publishing.js +1 -1
- 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/light-styling.d.ts +2 -2
- package/dist/lib/light-styling.js +5 -4
- package/dist/lib/motion-policy.d.ts +0 -1
- package/dist/lib/motion-policy.js +9 -8
- package/dist/lib/motion-publishing.js +3 -2
- package/dist/lib/mqtt-message.d.ts +6 -0
- package/dist/lib/mqtt-message.js +21 -0
- package/dist/lib/occupancy-publishing.js +1 -1
- package/dist/lib/power-reading.d.ts +5 -0
- package/dist/lib/power-reading.js +13 -0
- package/dist/lib/room-controller.d.ts +39 -29
- package/dist/lib/room-controller.js +314 -192
- package/dist/lib/room-lighting-discovery.d.ts +0 -14
- package/dist/lib/room-lighting-discovery.js +20 -126
- package/dist/lib/room-publishing.d.ts +10 -12
- package/dist/lib/room-publishing.js +65 -125
- package/dist/lib/shelly-cover.d.ts +44 -0
- package/dist/lib/shelly-cover.js +153 -0
- 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/source-capability-controller.d.ts +2 -0
- package/dist/lib/source-capability-controller.js +27 -6
- package/dist/lib/switch-policy.d.ts +1 -1
- package/dist/lib/switch-policy.js +1 -1
- package/dist/lib/theatre-requests.d.ts +29 -0
- package/dist/lib/theatre-requests.js +89 -0
- package/dist/lib/theatre-state-contract.d.ts +5 -22
- package/dist/lib/theatre-state-contract.js +30 -77
- package/dist/lib/toggle-power.d.ts +41 -0
- package/dist/lib/toggle-power.js +74 -0
- package/dist/lib/topic-names.d.ts +1 -0
- package/dist/lib/topic-names.js +7 -0
- package/dist/lib/{display-transport.d.ts → transports/display-transport.d.ts} +1 -1
- package/dist/lib/{display-transport.js → transports/display-transport.js} +32 -7
- 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 +8 -0
- package/dist/lib/z2m-light.js +61 -3
- package/dist/nodes/activity-lighting-controller.html +20 -3
- package/dist/nodes/activity-lighting-controller.js +21 -0
- package/dist/nodes/avr-controller.html +25 -6
- package/dist/nodes/avr-controller.js +16 -6
- package/dist/nodes/circadian-policy.d.ts +3 -0
- package/dist/nodes/circadian-policy.html +140 -0
- package/dist/nodes/circadian-policy.js +162 -0
- package/dist/nodes/cover-controller.html +4 -3
- package/dist/nodes/display-mode-controller.html +58 -11
- package/dist/nodes/display-mode-controller.js +19 -6
- package/dist/nodes/house-schedule.html +3 -3
- package/dist/nodes/motion-policy.html +5 -2
- package/dist/nodes/motion-policy.js +3 -0
- package/dist/nodes/refused-enable.d.ts +7 -0
- package/dist/nodes/refused-enable.js +24 -0
- package/dist/nodes/room-controller.html +215 -82
- package/dist/nodes/room-controller.js +71 -83
- package/dist/nodes/shelly-cover.d.ts +3 -0
- package/dist/nodes/shelly-cover.html +65 -0
- package/dist/nodes/shelly-cover.js +34 -0
- package/dist/nodes/shelly-switch.d.ts +3 -0
- package/dist/nodes/shelly-switch.html +82 -0
- package/dist/nodes/shelly-switch.js +48 -0
- package/dist/nodes/theatre-state-contract.html +4 -3
- 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 +72 -0
- package/dist/nodes/z2m-light.js +50 -0
- package/examples/Cover control.json +24 -56
- package/examples/Home theatre activity.json +54 -9
- package/examples/Home theatre equipment.json +4 -4
- package/examples/House schedule.json +106 -24
- package/examples/Room lighting.json +54 -11
- package/examples/Shelly cover.json +252 -0
- package/examples/Shelly switch.json +197 -0
- package/package.json +13 -4
- package/dist/lib/room-schedule.d.ts +0 -8
- package/dist/lib/room-schedule.js +0 -41
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normaliseZ2mCoverConfig = normaliseZ2mCoverConfig;
|
|
4
|
+
exports.z2mCoverTopics = z2mCoverTopics;
|
|
5
|
+
exports.transitionZ2mCover = transitionZ2mCover;
|
|
6
|
+
const mqtt_message_1 = require("./mqtt-message");
|
|
7
|
+
// Settings may be editor strings. The friendly name is the user's own
|
|
8
|
+
// device's, so it has no default.
|
|
9
|
+
function normaliseZ2mCoverConfig(config) {
|
|
10
|
+
const baseTopic = String(config.baseTopic ?? "").trim().replace(/^\/+|\/+$/g, "") || "zigbee2mqtt";
|
|
11
|
+
const friendlyName = String(config.friendlyName ?? "").trim().replace(/^\/+|\/+$/g, "");
|
|
12
|
+
if (!friendlyName)
|
|
13
|
+
throw new Error("the device's friendly name is required");
|
|
14
|
+
if (/[+#]/.test(baseTopic) || /[+#]/.test(friendlyName))
|
|
15
|
+
throw new Error("the base topic and friendly name can't contain + or #");
|
|
16
|
+
return { baseTopic, friendlyName };
|
|
17
|
+
}
|
|
18
|
+
function z2mCoverTopics(config) {
|
|
19
|
+
const device = `${config.baseTopic}/${config.friendlyName}`;
|
|
20
|
+
return { device, set: `${device}/set`, get: `${device}/get`, availability: `${device}/availability` };
|
|
21
|
+
}
|
|
22
|
+
// "pause": stopped part-way, as some motors report it.
|
|
23
|
+
const MOTOR_STATES = { opening: "opening", closing: "closing", stopped: "stopped", pause: "stopped" };
|
|
24
|
+
const MOVING = { UP: "opening", DOWN: "closing", STOP: "stopped" };
|
|
25
|
+
const COMMAND_STATES = { open: "OPEN", close: "CLOSE", stop: "STOP" };
|
|
26
|
+
// The motion a state report gives, if any: running alone says the motor is
|
|
27
|
+
// moving but not which way, so only its false (stopped) counts.
|
|
28
|
+
function motionOf(report) {
|
|
29
|
+
if (typeof report.motor_state === "string" && MOTOR_STATES[report.motor_state])
|
|
30
|
+
return MOTOR_STATES[report.motor_state];
|
|
31
|
+
if (typeof report.moving === "string" && MOVING[report.moving])
|
|
32
|
+
return MOVING[report.moving];
|
|
33
|
+
if (report.running === false)
|
|
34
|
+
return "stopped";
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
function transitionZ2mCover(saved, msg, config, now) {
|
|
38
|
+
const state = { reportsPosition: saved?.reportsPosition !== false };
|
|
39
|
+
const topics = z2mCoverTopics(config);
|
|
40
|
+
const publications = [];
|
|
41
|
+
const readings = [];
|
|
42
|
+
const traces = [];
|
|
43
|
+
const trace = (event, outcome, reason = null, details = {}) => {
|
|
44
|
+
traces.push({ event, outcome, reason, details });
|
|
45
|
+
};
|
|
46
|
+
const publish = (topic, payload) => publications.push({ topic, payload: JSON.stringify(payload) });
|
|
47
|
+
const command = msg.cover_command;
|
|
48
|
+
if ((0, mqtt_message_1.isObject)(command)) {
|
|
49
|
+
const operation = String(command.operation);
|
|
50
|
+
if (operation === "set_position") {
|
|
51
|
+
const position = Number(command.position);
|
|
52
|
+
if (!Number.isFinite(position))
|
|
53
|
+
throw new Error("set_position needs a position");
|
|
54
|
+
publish(topics.set, { position: Math.round(Math.max(0, Math.min(100, position))) });
|
|
55
|
+
trace("command", "sent", null, { operation, position });
|
|
56
|
+
}
|
|
57
|
+
else if (Object.hasOwn(COMMAND_STATES, operation)) {
|
|
58
|
+
publish(topics.set, { state: COMMAND_STATES[operation] });
|
|
59
|
+
trace("command", "sent", null, { operation });
|
|
60
|
+
}
|
|
61
|
+
else if (operation === "observe") {
|
|
62
|
+
// A fresh read, not the last report: its position, or for a cover with
|
|
63
|
+
// none, its state. The device answers on its state topic.
|
|
64
|
+
publish(topics.get, state.reportsPosition ? { position: "" } : { state: "" });
|
|
65
|
+
trace("command", "sent", null, { operation, read: state.reportsPosition ? "position" : "state" });
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
trace("command", "ignored", "unknown-operation", { operation });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (msg.topic === topics.device) {
|
|
72
|
+
const report = (0, mqtt_message_1.parsedPayload)(msg.payload);
|
|
73
|
+
if (!(0, mqtt_message_1.isObject)(report))
|
|
74
|
+
throw new Error(`${topics.device} must carry the device's state object`);
|
|
75
|
+
const position = typeof report.position === "number" && Number.isFinite(report.position) && report.position >= 0 && report.position <= 100
|
|
76
|
+
? report.position : undefined;
|
|
77
|
+
const motion = motionOf(report);
|
|
78
|
+
// With a position, an end state only at the ends: Zigbee2MQTT's OPEN
|
|
79
|
+
// can mean no more than "not closed". Without one, its OPEN or CLOSE,
|
|
80
|
+
// but only once the motor reports it has stopped: the state can change
|
|
81
|
+
// as soon as a move is asked for, before the cover gets there.
|
|
82
|
+
const end = position !== undefined
|
|
83
|
+
? (position === 100 ? "open" : position === 0 ? "closed" : undefined)
|
|
84
|
+
: motion !== "stopped" ? undefined
|
|
85
|
+
: report.state === "OPEN" ? "open" : report.state === "CLOSE" ? "closed" : undefined;
|
|
86
|
+
if (position === undefined && motion === undefined && end === undefined) {
|
|
87
|
+
trace("report", "ignored", "no-cover-state");
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
state.reportsPosition = position !== undefined;
|
|
91
|
+
readings.push({ cover: {
|
|
92
|
+
kind: "observed",
|
|
93
|
+
...(position !== undefined ? { position } : {}),
|
|
94
|
+
...(end ? { state: end } : {}),
|
|
95
|
+
...(motion ? { motion } : {}),
|
|
96
|
+
// When received, never a time the device gives: its clock may be off.
|
|
97
|
+
observedAt: now.toISOString(),
|
|
98
|
+
...(typeof report.battery === "number" ? { battery: report.battery } : {}),
|
|
99
|
+
// A string, or a binary's true or false: passed on as text.
|
|
100
|
+
...(typeof report.charging_status === "string" || typeof report.charging_status === "boolean"
|
|
101
|
+
? { charging: String(report.charging_status) } : {})
|
|
102
|
+
} });
|
|
103
|
+
trace("report", "read", null, { position: position ?? null, motion: motion ?? null, state: end ?? null });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else if (msg.topic === topics.availability) {
|
|
107
|
+
// {"state": "online"}, or the plain "online" of older setups.
|
|
108
|
+
const received = (0, mqtt_message_1.parsedPayload)(msg.payload);
|
|
109
|
+
const value = (0, mqtt_message_1.isObject)(received) ? received.state : received;
|
|
110
|
+
if (value !== "online" && value !== "offline")
|
|
111
|
+
throw new Error(`${topics.availability} must say online or offline`);
|
|
112
|
+
readings.push({ cover: { kind: "availability", online: value === "online" } });
|
|
113
|
+
trace("availability", value);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
trace("message", "ignored", "unrelated-message", { topic: typeof msg.topic === "string" ? msg.topic : null });
|
|
117
|
+
}
|
|
118
|
+
return { state, publications, readings, traces };
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=z2m-cover.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TraceEntry } from "./bounded-trace";
|
|
2
|
+
import { ECHO_WINDOW_MS, type ExpectedCommand } from "./command-echo";
|
|
3
|
+
import type { LightCommandMessage, LightField, LightReading } from "./light-contract";
|
|
4
|
+
export { ECHO_WINDOW_MS };
|
|
5
|
+
export interface Z2mLightConfig {
|
|
6
|
+
target: string;
|
|
7
|
+
baseTopic: string;
|
|
8
|
+
friendlyName: string;
|
|
9
|
+
group: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface DeviceReport {
|
|
12
|
+
on: boolean;
|
|
13
|
+
brightness: unknown;
|
|
14
|
+
color_temp: unknown;
|
|
15
|
+
observedAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface Z2mLightState {
|
|
18
|
+
expected: ExpectedCommand[];
|
|
19
|
+
last: {
|
|
20
|
+
payload: Record<string, unknown>;
|
|
21
|
+
id: string;
|
|
22
|
+
} | null;
|
|
23
|
+
report: DeviceReport | null;
|
|
24
|
+
fields: LightField[];
|
|
25
|
+
online: boolean | null;
|
|
26
|
+
}
|
|
27
|
+
export interface Z2mLightMessage {
|
|
28
|
+
topic?: unknown;
|
|
29
|
+
payload?: unknown;
|
|
30
|
+
retain?: unknown;
|
|
31
|
+
light?: unknown;
|
|
32
|
+
}
|
|
33
|
+
export interface Publication {
|
|
34
|
+
topic: string;
|
|
35
|
+
payload: unknown;
|
|
36
|
+
retain: false;
|
|
37
|
+
}
|
|
38
|
+
export declare function normaliseZ2mLightConfig(config: {
|
|
39
|
+
target?: unknown;
|
|
40
|
+
baseTopic?: unknown;
|
|
41
|
+
friendlyName?: unknown;
|
|
42
|
+
group?: unknown;
|
|
43
|
+
}): Z2mLightConfig;
|
|
44
|
+
export declare function z2mLightTopics(config: Z2mLightConfig): {
|
|
45
|
+
device: string;
|
|
46
|
+
set: string;
|
|
47
|
+
get: string;
|
|
48
|
+
availability: string;
|
|
49
|
+
};
|
|
50
|
+
export declare function parseZ2mTargetTopics(stateTopic: unknown, commandTopic: unknown): {
|
|
51
|
+
baseTopic: string;
|
|
52
|
+
friendlyName: string;
|
|
53
|
+
} | null;
|
|
54
|
+
export declare function createZ2mLightState(saved?: Partial<Z2mLightState>): Z2mLightState;
|
|
55
|
+
export declare function z2mLightPayload(command: LightCommandMessage): Record<string, unknown>;
|
|
56
|
+
export declare function transitionZ2mLight(saved: Partial<Z2mLightState> | undefined, msg: Z2mLightMessage, config: Z2mLightConfig, nowValue?: Date | string | number): {
|
|
57
|
+
state: Z2mLightState;
|
|
58
|
+
publications: Publication[];
|
|
59
|
+
readings: LightReading[];
|
|
60
|
+
traces: TraceEntry<Record<string, unknown>>[];
|
|
61
|
+
ignored: boolean;
|
|
62
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ECHO_WINDOW_MS = void 0;
|
|
4
|
+
exports.normaliseZ2mLightConfig = normaliseZ2mLightConfig;
|
|
5
|
+
exports.z2mLightTopics = z2mLightTopics;
|
|
6
|
+
exports.parseZ2mTargetTopics = parseZ2mTargetTopics;
|
|
7
|
+
exports.createZ2mLightState = createZ2mLightState;
|
|
8
|
+
exports.z2mLightPayload = z2mLightPayload;
|
|
9
|
+
exports.transitionZ2mLight = transitionZ2mLight;
|
|
10
|
+
const command_echo_1 = require("./command-echo");
|
|
11
|
+
Object.defineProperty(exports, "ECHO_WINDOW_MS", { enumerable: true, get: function () { return command_echo_1.ECHO_WINDOW_MS; } });
|
|
12
|
+
const settings_1 = require("./settings");
|
|
13
|
+
const z2m_light_1 = require("./z2m-light");
|
|
14
|
+
function normaliseZ2mLightConfig(config) {
|
|
15
|
+
const target = (0, settings_1.textSetting)(config.target, "target", "");
|
|
16
|
+
const friendlyName = (0, settings_1.textSetting)(config.friendlyName, "friendly name", "");
|
|
17
|
+
const baseTopic = (0, settings_1.textSetting)(config.baseTopic, "base topic", "zigbee2mqtt").replace(/^\/+|\/+$/g, "");
|
|
18
|
+
if (!target)
|
|
19
|
+
throw new Error("target is required: the room's id for this light");
|
|
20
|
+
if (!friendlyName)
|
|
21
|
+
throw new Error("friendly name is required");
|
|
22
|
+
if (!baseTopic)
|
|
23
|
+
throw new Error("base topic is required");
|
|
24
|
+
if (/[+#]/.test(baseTopic + friendlyName))
|
|
25
|
+
throw new Error("base topic and friendly name cannot contain + or #");
|
|
26
|
+
return { target, baseTopic, friendlyName, group: config.group === true || config.group === "true" };
|
|
27
|
+
}
|
|
28
|
+
function z2mLightTopics(config) {
|
|
29
|
+
const device = `${config.baseTopic}/${config.friendlyName}`;
|
|
30
|
+
return { device, set: `${device}/set`, get: `${device}/get`, availability: `${device}/availability` };
|
|
31
|
+
}
|
|
32
|
+
// Where a 5.x room target's topics point, when they are Zigbee2MQTT's own:
|
|
33
|
+
// <base>/<name> and <base>/<name>/set. Null for anything else, which is set
|
|
34
|
+
// up by hand on the neutral contract.
|
|
35
|
+
function parseZ2mTargetTopics(stateTopic, commandTopic) {
|
|
36
|
+
if (typeof stateTopic !== "string" || typeof commandTopic !== "string")
|
|
37
|
+
return null;
|
|
38
|
+
if (commandTopic !== `${stateTopic}/set`)
|
|
39
|
+
return null;
|
|
40
|
+
const slash = stateTopic.indexOf("/");
|
|
41
|
+
if (slash <= 0 || slash === stateTopic.length - 1)
|
|
42
|
+
return null;
|
|
43
|
+
return { baseTopic: stateTopic.slice(0, slash), friendlyName: stateTopic.slice(slash + 1) };
|
|
44
|
+
}
|
|
45
|
+
function createZ2mLightState(saved = {}) {
|
|
46
|
+
return {
|
|
47
|
+
expected: Array.isArray(saved.expected) ? saved.expected.map((entry) => ({ ...entry })) : [],
|
|
48
|
+
last: saved.last && typeof saved.last === "object" ? { payload: { ...saved.last.payload }, id: String(saved.last.id) } : null,
|
|
49
|
+
report: saved.report && typeof saved.report === "object" ? { ...saved.report } : null,
|
|
50
|
+
fields: Array.isArray(saved.fields) ? saved.fields.filter((field) => field === "brightness" || field === "colorTemp") : [],
|
|
51
|
+
online: typeof saved.online === "boolean" ? saved.online : null
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// A command as Zigbee2MQTT's /set payload, field for field and in the order
|
|
55
|
+
// the room built it before 6.0: the state, any other fields the intent gave,
|
|
56
|
+
// brightness and colour temperature, then the transition unless an extra
|
|
57
|
+
// field already set one.
|
|
58
|
+
function z2mLightPayload(command) {
|
|
59
|
+
if (command.state === "OFF")
|
|
60
|
+
return { state: "OFF" };
|
|
61
|
+
const payload = { state: "ON", ...(command.extra ?? {}) };
|
|
62
|
+
if (typeof command.brightnessPct === "number")
|
|
63
|
+
payload.brightness = (0, z2m_light_1.zigbeeBrightness)(command.brightnessPct);
|
|
64
|
+
if (typeof command.colorTempKelvin === "number")
|
|
65
|
+
payload.color_temp = (0, z2m_light_1.zigbeeColorTemp)(command.colorTempKelvin);
|
|
66
|
+
if (typeof command.transitionSeconds === "number" && !Object.hasOwn(payload, "transition"))
|
|
67
|
+
payload.transition = command.transitionSeconds;
|
|
68
|
+
return payload;
|
|
69
|
+
}
|
|
70
|
+
function sameValues(payload, report) {
|
|
71
|
+
return (payload.brightness === undefined || Number(report.brightness) === payload.brightness) &&
|
|
72
|
+
(payload.color_temp === undefined || Number(report.color_temp) === payload.color_temp);
|
|
73
|
+
}
|
|
74
|
+
function reportedFields(payload) {
|
|
75
|
+
const fields = [];
|
|
76
|
+
if (payload.brightness !== undefined && payload.brightness !== null)
|
|
77
|
+
fields.push("brightness");
|
|
78
|
+
if (payload.color_temp !== undefined && payload.color_temp !== null)
|
|
79
|
+
fields.push("colorTemp");
|
|
80
|
+
return fields;
|
|
81
|
+
}
|
|
82
|
+
function transitionZ2mLight(saved, msg, config, nowValue = new Date()) {
|
|
83
|
+
const now = nowValue instanceof Date ? nowValue : new Date(nowValue);
|
|
84
|
+
const nowMs = now.getTime();
|
|
85
|
+
const state = createZ2mLightState(saved);
|
|
86
|
+
const topics = z2mLightTopics(config);
|
|
87
|
+
const publications = [];
|
|
88
|
+
const readings = [];
|
|
89
|
+
const traces = [];
|
|
90
|
+
const trace = (event, outcome, reason = null, details = {}) => traces.push({ event, outcome, reason, details });
|
|
91
|
+
const target = config.target;
|
|
92
|
+
const light = msg.light && typeof msg.light === "object" ? msg.light : null;
|
|
93
|
+
if (light && (light.kind === "command" || light.kind === "observe")) {
|
|
94
|
+
// The room's messages for every light arrive here; only this one's count.
|
|
95
|
+
if (light.target !== target)
|
|
96
|
+
return { state, publications, readings, traces, ignored: true };
|
|
97
|
+
if (light.kind === "observe") {
|
|
98
|
+
if (config.group) {
|
|
99
|
+
// A group can't be asked: Zigbee2MQTT sends its state as it changes.
|
|
100
|
+
trace("observe", "ignored", "group-has-no-get");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
publications.push({ topic: topics.get, payload: { state: "" }, retain: false });
|
|
104
|
+
trace("observe", "sent");
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
const command = light;
|
|
109
|
+
const payload = z2mLightPayload(command);
|
|
110
|
+
if (command.restyle === true && state.report?.on === true && payload.state === "ON" && sameValues(payload, state.report)) {
|
|
111
|
+
// Already there: nothing to send, as the room skipped it before 6.0.
|
|
112
|
+
readings.push({ kind: "skipped", target, id: String(command.id), observedAt: state.report.observedAt });
|
|
113
|
+
trace("command", "skipped", "already-at-level", { id: command.id });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
state.expected = (0, command_echo_1.rememberCommand)(state.expected, payload, nowMs);
|
|
117
|
+
state.last = { payload, id: String(command.id) };
|
|
118
|
+
publications.push({ topic: topics.set, payload, retain: false });
|
|
119
|
+
if (command.restyle === true)
|
|
120
|
+
readings.push({ kind: "sent", target, id: String(command.id) });
|
|
121
|
+
trace("command", "sent", null, { id: command.id, source: command.source, state: payload.state });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return { state, publications, readings, traces, ignored: false };
|
|
125
|
+
}
|
|
126
|
+
const topic = typeof msg.topic === "string" ? msg.topic : "";
|
|
127
|
+
const parsed = (0, command_echo_1.parsePayload)(msg.payload);
|
|
128
|
+
if (topic === topics.device) {
|
|
129
|
+
const payload = parsed && typeof parsed === "object" ? parsed : null;
|
|
130
|
+
const report = payload ? (0, z2m_light_1.readLightReport)(payload) : null;
|
|
131
|
+
if (!payload || !report) {
|
|
132
|
+
trace("report", "ignored", "no-state");
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
state.report = { ...report, observedAt: now.toISOString() };
|
|
136
|
+
for (const field of reportedFields(payload))
|
|
137
|
+
if (!state.fields.includes(field))
|
|
138
|
+
state.fields.push(field);
|
|
139
|
+
readings.push(observedReading(state.report));
|
|
140
|
+
trace("report", "read", null, { on: report.on });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else if (topic === topics.set) {
|
|
144
|
+
const payload = parsed && typeof parsed === "object" ? parsed : null;
|
|
145
|
+
if (msg.retain === true) {
|
|
146
|
+
trace("set", "ignored", "retained-message");
|
|
147
|
+
}
|
|
148
|
+
else if (payload) {
|
|
149
|
+
const echo = (0, command_echo_1.checkCommandEcho)(state.expected, payload, nowMs);
|
|
150
|
+
state.expected = echo.queue;
|
|
151
|
+
const requested = String(payload.state ?? "").toUpperCase();
|
|
152
|
+
if (echo.changed) {
|
|
153
|
+
readings.push({ kind: "echo-changed", target, id: state.last?.id ?? null, state: requested });
|
|
154
|
+
trace("set", "own", "mutated-own-command", { state: requested });
|
|
155
|
+
}
|
|
156
|
+
else if (echo.own) {
|
|
157
|
+
trace("set", "own", "echo");
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
readings.push({ kind: "external", target, state: requested, setsValues: (0, z2m_light_1.setsLightValues)(payload), observedAt: now.toISOString() });
|
|
161
|
+
trace("set", "external", null, { state: requested });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (topic === topics.availability && !config.group) {
|
|
166
|
+
const value = parsed && typeof parsed === "object" ? parsed.state : parsed;
|
|
167
|
+
const online = String(value).toLowerCase() === "online";
|
|
168
|
+
if (String(value).toLowerCase() === "online" || String(value).toLowerCase() === "offline") {
|
|
169
|
+
state.online = online;
|
|
170
|
+
readings.push({ kind: "availability", target, online });
|
|
171
|
+
trace("availability", online ? "online" : "offline");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else if (topic !== "") {
|
|
175
|
+
trace("message", "ignored", "other-topic", { topic });
|
|
176
|
+
}
|
|
177
|
+
return { state, publications, readings, traces, ignored: false };
|
|
178
|
+
function observedReading(report) {
|
|
179
|
+
const brightness = Number(report.brightness);
|
|
180
|
+
const colorTemp = Number(report.color_temp);
|
|
181
|
+
const last = state.last?.payload;
|
|
182
|
+
const showsLast = last !== undefined && report.on === (last.state === "ON") && (last.state === "OFF" || sameValues(last, report));
|
|
183
|
+
return {
|
|
184
|
+
kind: "observed",
|
|
185
|
+
target,
|
|
186
|
+
on: report.on,
|
|
187
|
+
...(report.brightness !== null && Number.isFinite(brightness) ? { brightnessPct: brightness * 100 / 254 } : {}),
|
|
188
|
+
...(report.color_temp !== null && Number.isFinite(colorTemp) && colorTemp > 0 ? { colorTempKelvin: 1_000_000 / colorTemp } : {}),
|
|
189
|
+
fields: [...state.fields],
|
|
190
|
+
showsLast,
|
|
191
|
+
observedAt: report.observedAt
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=z2m-light-adapter.js.map
|
package/dist/lib/z2m-light.d.ts
CHANGED
|
@@ -11,6 +11,14 @@ export type LightCommand = {
|
|
|
11
11
|
color_temp?: number;
|
|
12
12
|
transition?: number;
|
|
13
13
|
};
|
|
14
|
+
export declare function zigbeeBrightness(percent: number): number;
|
|
15
|
+
export declare function zigbeeColorTemp(kelvin: number): number;
|
|
14
16
|
export declare function lightCommand(state: string, style: LightStyle, transitionSeconds: number): LightCommand;
|
|
17
|
+
export declare const REMOVED_LIGHT_FIELDS: readonly ["brightness", "color_temp"];
|
|
18
|
+
export declare function lightValues(values: Record<string, unknown>): {
|
|
19
|
+
values: Record<string, unknown>;
|
|
20
|
+
removed: string[];
|
|
21
|
+
invalid: string[];
|
|
22
|
+
};
|
|
15
23
|
export declare function setsLightValues(command: Record<string, unknown>): boolean;
|
|
16
24
|
export declare function alreadyStyled(style: LightStyle, report: LightReport | undefined): boolean;
|
package/dist/lib/z2m-light.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REMOVED_LIGHT_FIELDS = void 0;
|
|
3
4
|
exports.readLightReport = readLightReport;
|
|
5
|
+
exports.zigbeeBrightness = zigbeeBrightness;
|
|
6
|
+
exports.zigbeeColorTemp = zigbeeColorTemp;
|
|
4
7
|
exports.lightCommand = lightCommand;
|
|
8
|
+
exports.lightValues = lightValues;
|
|
5
9
|
exports.setsLightValues = setsLightValues;
|
|
6
10
|
exports.alreadyStyled = alreadyStyled;
|
|
7
11
|
// A state report, or null when it carries no ON/OFF state.
|
|
@@ -11,12 +15,65 @@ function readLightReport(payload) {
|
|
|
11
15
|
return null;
|
|
12
16
|
return { on: state === "ON", brightness: payload.brightness ?? null, color_temp: payload.color_temp ?? null };
|
|
13
17
|
}
|
|
18
|
+
// Brightness percent as Zigbee2MQTT's 1-254, and kelvin as mireds.
|
|
19
|
+
function zigbeeBrightness(percent) {
|
|
20
|
+
return Math.min(254, Math.max(1, Math.round(percent * 254 / 100)));
|
|
21
|
+
}
|
|
22
|
+
// Rounded after trimming float noise to 12 significant digits, so a mired
|
|
23
|
+
// value that is exactly n.5 in decimal rounds up as it always has, rather than
|
|
24
|
+
// down because its kelvin round trip left it a hair under.
|
|
25
|
+
function zigbeeColorTemp(kelvin) {
|
|
26
|
+
return Math.round(Number((1_000_000 / kelvin).toPrecision(12)));
|
|
27
|
+
}
|
|
28
|
+
function zigbeeStyle(style) {
|
|
29
|
+
return { brightness: zigbeeBrightness(style.brightnessPct), color_temp: zigbeeColorTemp(style.colorTempKelvin) };
|
|
30
|
+
}
|
|
14
31
|
// A command for a light: OFF on its own, otherwise the state with a style
|
|
15
32
|
// faded in over the transition.
|
|
16
33
|
function lightCommand(state, style, transitionSeconds) {
|
|
17
34
|
if (state === "OFF")
|
|
18
35
|
return { state };
|
|
19
|
-
return { state, ...style, transition: transitionSeconds };
|
|
36
|
+
return { state, ...zigbeeStyle(style), transition: transitionSeconds };
|
|
37
|
+
}
|
|
38
|
+
// A brightness percent or kelvin as a number: a number, or a finite numeric
|
|
39
|
+
// string; null otherwise.
|
|
40
|
+
function numberValue(value) {
|
|
41
|
+
const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
|
|
42
|
+
return Number.isFinite(number) ? number : null;
|
|
43
|
+
}
|
|
44
|
+
// The package's own value fields and the Zigbee2MQTT field each becomes.
|
|
45
|
+
const NEUTRAL_FIELDS = { brightnessPct: "brightness", colorTempKelvin: "color_temp" };
|
|
46
|
+
// The fields in Zigbee2MQTT's own units that 5.x still took, removed in 6.0.
|
|
47
|
+
exports.REMOVED_LIGHT_FIELDS = ["brightness", "color_temp"];
|
|
48
|
+
// An intent's or profile's values as Zigbee2MQTT fields: brightnessPct and
|
|
49
|
+
// colorTempKelvin converted; anything else (an effect, say) passed on as it
|
|
50
|
+
// is. brightness and color_temp, Zigbee2MQTT's own units, are no longer
|
|
51
|
+
// taken: they are `removed`, and never reach the device. An unusable
|
|
52
|
+
// brightnessPct or colorTempKelvin is `invalid`, and never reaches it either.
|
|
53
|
+
function lightValues(values) {
|
|
54
|
+
const converted = {};
|
|
55
|
+
const removed = [];
|
|
56
|
+
const invalid = [];
|
|
57
|
+
const neutral = {};
|
|
58
|
+
for (const [field, device] of Object.entries(NEUTRAL_FIELDS)) {
|
|
59
|
+
if (!Object.hasOwn(values, field))
|
|
60
|
+
continue;
|
|
61
|
+
const number = numberValue(values[field]);
|
|
62
|
+
if (number === null || (field === "colorTempKelvin" && number <= 0))
|
|
63
|
+
invalid.push(field);
|
|
64
|
+
else
|
|
65
|
+
neutral[device] = field === "brightnessPct" ? zigbeeBrightness(number) : zigbeeColorTemp(number);
|
|
66
|
+
}
|
|
67
|
+
for (const [key, value] of Object.entries(values)) {
|
|
68
|
+
if (Object.hasOwn(NEUTRAL_FIELDS, key))
|
|
69
|
+
continue;
|
|
70
|
+
if (exports.REMOVED_LIGHT_FIELDS.includes(key)) {
|
|
71
|
+
removed.push(key);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
converted[key] = value;
|
|
75
|
+
}
|
|
76
|
+
return { values: { ...converted, ...neutral }, removed, invalid };
|
|
20
77
|
}
|
|
21
78
|
// Command fields that set a light's values rather than just its power.
|
|
22
79
|
const VALUE_FIELDS = [
|
|
@@ -29,8 +86,9 @@ function setsLightValues(command) {
|
|
|
29
86
|
// Whether a light already shows a style, by its own latest report. A bulb
|
|
30
87
|
// that missed a command reports something else, so it is not "styled".
|
|
31
88
|
function alreadyStyled(style, report) {
|
|
89
|
+
const expected = zigbeeStyle(style);
|
|
32
90
|
return report?.on === true &&
|
|
33
|
-
Number(report.brightness) ===
|
|
34
|
-
Number(report.color_temp) ===
|
|
91
|
+
Number(report.brightness) === expected.brightness &&
|
|
92
|
+
Number(report.color_temp) === expected.color_temp;
|
|
35
93
|
}
|
|
36
94
|
//# sourceMappingURL=z2m-light.js.map
|
|
@@ -30,10 +30,27 @@
|
|
|
30
30
|
</script>
|
|
31
31
|
|
|
32
32
|
<script type="text/html" data-help-name="home-activity-lighting-controller">
|
|
33
|
-
<p>Applies configuration-owned activity styles only to room lights that are already on and not manually owned
|
|
34
|
-
|
|
33
|
+
<p>Applies configuration-owned activity styles only to room lights that are already on and not manually owned. If
|
|
34
|
+
a person changes a light the activity holds, the node reports <code>manual_override</code>, as the display,
|
|
35
|
+
receiver and backlight do; lighting is optional, so the theatre is degraded, not failed, and the next request takes
|
|
36
|
+
the light back.</p>
|
|
37
|
+
<p>Input <code>msg.activityLighting</code> carries generation-scoped intent, refresh, result or tick events. Wire the room lighting controller's third output here too: it passes on each light's reading (<code>msg.light</code>, from the light's adapter) with whether a person set it, which the node takes as an observation of the request in hand. Output 1 emits standard <code>msg.lighting</code> intents for a room controller. Output 2 emits theatre <code>target_state</code> evidence. Room-light failure is optional degradation, not activity success.</p>
|
|
38
|
+
<p>Each profile is <code>{targets: [...], values: {...}}</code>, with <code>values</code> in the package's own units:
|
|
39
|
+
<code>brightnessPct</code> (0-100) and <code>colorTempKelvin</code>, for example
|
|
40
|
+
<code>{"tv": {"targets": ["main"], "values": {"brightnessPct": 25, "colorTempKelvin": 2500}}}</code>.
|
|
41
|
+
<code>brightnessPct</code> runs from 0 (the dimmest the light goes, not off) to 100, and
|
|
42
|
+
<code>colorTempKelvin</code> must be above 0; anything else is an invalid configuration. The room
|
|
43
|
+
controller converts them for the light, and a light's report (in its own units) is compared after the same
|
|
44
|
+
conversion. Zigbee2MQTT's own <code>brightness</code> and <code>color_temp</code> were removed in 6.0: a profile
|
|
45
|
+
using them is an invalid configuration.</p>
|
|
46
|
+
<p>Each light is judged by what it reports. A light that has reported none of a profile's fields since the node
|
|
47
|
+
started (no brightness, no colour temperature), as one that only switches on and off, is confirmed by being on;
|
|
48
|
+
once it has reported one, it is held to the profile's values: it confirms when its adapter says it shows the last
|
|
49
|
+
command sent to it, which is the profile's while the activity holds it. A profile that gives values to a light that has never
|
|
50
|
+
reported them gets one warning per deploy: they may not apply. Mark such a light <code>onOffOnly</code> on the
|
|
51
|
+
room, and the room won't send them.</p>
|
|
35
52
|
<p>While a profile is active, its lights are overridden in the room controller under <b>Owner</b>
|
|
36
|
-
(default <code>activity</code>), so circadian
|
|
53
|
+
(default <code>activity</code>), so the room's style (from a circadian lighting policy) leaves the activity's alone. When a new profile
|
|
37
54
|
no longer includes a light, including a switch to an off profile with no targets, the node emits
|
|
38
55
|
<code>{kind: "release", owner, targets}</code> for those lights and the room controller restyles them.
|
|
39
56
|
Give each activity-lighting node that feeds the same room controller its own owner.</p>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const activity_lighting_controller_1 = require("../lib/activity-lighting-controller");
|
|
3
|
+
const light_contract_1 = require("../lib/light-contract");
|
|
3
4
|
const adapter_1 = require("./adapter");
|
|
4
5
|
const settings_1 = require("../lib/settings");
|
|
5
6
|
const registerActivityLightingController = (RED) => {
|
|
@@ -59,8 +60,17 @@ const registerActivityLightingController = (RED) => {
|
|
|
59
60
|
}
|
|
60
61
|
updateStatus(result.status);
|
|
61
62
|
schedule(result.state);
|
|
63
|
+
// Once per deploy: a light the profile gives values to that reports
|
|
64
|
+
// none of them, confirmed by being on.
|
|
65
|
+
const unreported = result.traces.find(({ reason }) => reason === activity_lighting_controller_1.VALUES_NOT_REPORTED);
|
|
66
|
+
if (unreported && !warnedUnreported) {
|
|
67
|
+
warnedUnreported = true;
|
|
68
|
+
node.warn(`${String(unreported.details.target)} reports no brightness or colour, so the activity confirms it ` +
|
|
69
|
+
"by its being on, and the profile's values for it may not apply: a light that only switches on and off can be marked onOffOnly on the room");
|
|
70
|
+
}
|
|
62
71
|
return result;
|
|
63
72
|
}
|
|
73
|
+
let warnedUnreported = false;
|
|
64
74
|
// A pending transition is here only if the node's context survived its
|
|
65
75
|
// stop, which needs a configured context store (see the README); timers
|
|
66
76
|
// never survive. Recover it with the reducer's own startup (re-observe,
|
|
@@ -72,6 +82,17 @@ const registerActivityLightingController = (RED) => {
|
|
|
72
82
|
}), 0);
|
|
73
83
|
}
|
|
74
84
|
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
85
|
+
// A light's reading, as the room controller passes it on (its third
|
|
86
|
+
// output): an observation for the request in hand.
|
|
87
|
+
const light = (0, light_contract_1.isLightReading)(msg.light) && msg.light.kind === "observed" ? msg.light : null;
|
|
88
|
+
if (light) {
|
|
89
|
+
const generation = context.get("state")?.generation ?? 0;
|
|
90
|
+
if (generation < 1)
|
|
91
|
+
return;
|
|
92
|
+
process({ activityLighting: { kind: "observed", generation, target: light.target, on: light.on, manual: light.manual === true,
|
|
93
|
+
fields: light.fields, showsLast: light.showsLast, observedAt: light.observedAt } }, send);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
75
96
|
process({
|
|
76
97
|
activityLighting: (0, adapter_1.objectField)(msg, "activityLighting")
|
|
77
98
|
}, send);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
2
|
(function () {
|
|
3
3
|
function on(value) { return value === true || value === "true"; }
|
|
4
|
+
function given(value) { return value !== undefined && value !== null && String(value).trim() !== ""; }
|
|
5
|
+
// A dB bound. A node saved before 5.0 has none (its 0-98 bounds were
|
|
6
|
+
// removed in 6.0), so it shows as invalid until they are set.
|
|
7
|
+
function volumeBound(value) { return given(value) && Number.isFinite(Number(value)); }
|
|
4
8
|
RED.nodes.registerType("home-avr-controller", {
|
|
5
9
|
category: "home automation",
|
|
6
10
|
color: "#c7d9f1",
|
|
@@ -17,8 +21,18 @@
|
|
|
17
21
|
sources: {value: "{\"shield\":\"SAT/CBL\",\"playstation\":\"GAME\"}", required: true, validate: function (v) { try { JSON.parse(v); return true; } catch (e) { return false; } }},
|
|
18
22
|
retryMs: {value: 2000, required: true, validate: RED.validators.number()},
|
|
19
23
|
maxAttempts: {value: 3, required: true, validate: RED.validators.number()},
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
// In dB (the receiver's 80 is 0 dB).
|
|
25
|
+
minVolumeDb: {value: -80, validate: volumeBound},
|
|
26
|
+
maxVolumeDb: {value: -20, validate: volumeBound},
|
|
27
|
+
// The 0-98 bounds of a node saved before 5.0, removed in 6.0 but kept
|
|
28
|
+
// here, with no form row, so the editor carries them: the editor keeps
|
|
29
|
+
// only the properties named here, and without them a deploy from the
|
|
30
|
+
// editor would leave the node with no bounds at all, which the runtime
|
|
31
|
+
// would give the default bounds, possibly louder than the old cap.
|
|
32
|
+
// With them, the node stays an invalid configuration until its dB
|
|
33
|
+
// bounds are set.
|
|
34
|
+
minVolume: {value: ""},
|
|
35
|
+
maxVolume: {value: ""},
|
|
22
36
|
// The receiver published nothing before these settings, so both start off.
|
|
23
37
|
publishState: {value: false},
|
|
24
38
|
discovery: {value: false},
|
|
@@ -45,6 +59,11 @@
|
|
|
45
59
|
$("#node-input-publishState, #node-input-discovery").on("change", follow);
|
|
46
60
|
follow();
|
|
47
61
|
},
|
|
62
|
+
// Once the dB bounds are set, the removed 0-98 ones go.
|
|
63
|
+
oneditsave: function () {
|
|
64
|
+
if (given($("#node-input-minVolumeDb").val())) this.minVolume = "";
|
|
65
|
+
if (given($("#node-input-maxVolumeDb").val())) this.maxVolume = "";
|
|
66
|
+
},
|
|
48
67
|
inputs: 1,
|
|
49
68
|
outputs: 3,
|
|
50
69
|
outputLabels: ["Denon commands", "state and results", "MQTT publications"],
|
|
@@ -60,8 +79,8 @@
|
|
|
60
79
|
<div class="form-row"><label for="node-input-sources">Sources</label><input type="text" id="node-input-sources"></div>
|
|
61
80
|
<div class="form-row"><label for="node-input-retryMs">Retry milliseconds</label><input type="number" id="node-input-retryMs"></div>
|
|
62
81
|
<div class="form-row"><label for="node-input-maxAttempts">Maximum attempts</label><input type="number" id="node-input-maxAttempts"></div>
|
|
63
|
-
<div class="form-row"><label for="node-input-
|
|
64
|
-
<div class="form-row"><label for="node-input-
|
|
82
|
+
<div class="form-row"><label for="node-input-minVolumeDb">Minimum volume (dB)</label><input type="number" step="0.5" id="node-input-minVolumeDb"></div>
|
|
83
|
+
<div class="form-row"><label for="node-input-maxVolumeDb">Maximum volume (dB)</label><input type="number" step="0.5" id="node-input-maxVolumeDb"></div>
|
|
65
84
|
<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>
|
|
66
85
|
<div class="form-row"><label for="node-input-discovery">Home Assistant discovery</label><input type="checkbox" id="node-input-discovery" style="display:inline-block; width:auto;"> <span>(needs Publish state)</span></div>
|
|
67
86
|
<div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
@@ -71,7 +90,7 @@
|
|
|
71
90
|
<p>Owns explicit power, main-zone, source and bounded volume commands for a Denon AVR.</p>
|
|
72
91
|
<p>Send protocol observations as <code>msg.avr = {kind: "observed", line: msg.payload}</code>.</p>
|
|
73
92
|
<p>Send activity requests as <code>msg.avr = {kind: "intent", requestId, generation, power: "on", source: "shield"}</code>. Omit <code>source</code> to preserve the current input, or use <code>power: "standby"</code> to stop the AVR.</p>
|
|
74
|
-
<p>Send volume requests as <code>msg.avr = {kind: "volume", requestId, mode: "absolute",
|
|
93
|
+
<p>Send volume requests as <code>msg.avr = {kind: "volume", requestId, mode: "absolute", valueDb: -50}</code> or use <code>mode: "relative"</code> with a positive or negative change. Volume is in dB, as are the bounds, results and published state; the receiver's 80 is 0 dB. A <code>value</code> in the receiver's own 0-98 was removed in 6.0: such a request is answered <code>volume_rejected</code> with reason <code>removed-volume-value</code>, with a warning in the log. A node saved before 5.0 with only its 0-98 bounds is an invalid configuration until <b>Minimum volume (dB)</b> and <b>Maximum volume (dB)</b> are set. The controller applies configured bounds, accumulates rapid relative requests, confirms fresh <code>MV</code> evidence and releases ownership so external adjustments are preserved.</p>
|
|
75
94
|
<p>Send <code>kind: "startup"</code> after deployment to discard stale observations and query the receiver; a volume request still pending then is reported as failed with reason <code>restart</code>. Send <code>kind: "refresh"</code> to re-read the receiver without disturbing work in flight. Output 1 connects to a TCP output node; output 2 emits state plus ready, failed, rejected, superseded and volume results.</p>
|
|
76
95
|
<p>While it has a request, output 2 also carries <code>msg.theatre = {kind: "target_state", target: "avr", requestId, generation, status, observedAt, details}</code>, so it can be wired straight back to a theatre activity controller. A ready state is stamped with the oldest receiver reading the request relies on, and a <code>refresh</code> is answered once the receiver reports again.</p>
|
|
77
96
|
<h3>Volume results</h3>
|
|
@@ -89,7 +108,7 @@
|
|
|
89
108
|
<code>home/<area>/receiver/power/state</code> (<code>ON</code> or <code>OFF</code>),
|
|
90
109
|
<code>…/source/state</code> (the source name) and <code>…/volume/state</code>, with <code>online</code> or
|
|
91
110
|
<code>offline</code> on <code>…/availability</code>.</dd>
|
|
92
|
-
<dt>Home Assistant discovery</dt><dd>power and source sensors, and a volume number between <b>Minimum volume</b>
|
|
111
|
+
<dt>Home Assistant discovery</dt><dd>power and source sensors, and a volume number in dB between <b>Minimum volume</b>
|
|
93
112
|
and <b>Maximum volume</b>. It needs <b>Publish state</b>. A volume set there arrives on
|
|
94
113
|
<code>…/volume/set</code>; wire an MQTT in node on that topic into this node. Sets arriving within 0.3 seconds
|
|
95
114
|
of each other (a slider, repeated taps) are settled to the last one, which becomes an ordinary absolute
|