@avantics/node-red-home-automation 4.0.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/README.md +117 -4
  2. package/contract-examples/switch-gestures.mjs +1 -1
  3. package/contract-examples/volume-ownership.mjs +6 -5
  4. package/dist/lib/activity-lighting-controller.d.ts +2 -0
  5. package/dist/lib/activity-lighting-controller.js +35 -6
  6. package/dist/lib/adopted-request.d.ts +17 -0
  7. package/dist/lib/adopted-request.js +61 -7
  8. package/dist/lib/avr-controller.d.ts +9 -3
  9. package/dist/lib/avr-controller.js +76 -24
  10. package/dist/lib/avr-publishing.d.ts +3 -3
  11. package/dist/lib/avr-publishing.js +11 -5
  12. package/dist/lib/backlighting-controller.d.ts +2 -0
  13. package/dist/lib/backlighting-controller.js +27 -7
  14. package/dist/lib/cover-publishing.js +1 -1
  15. package/dist/lib/denon-protocol.d.ts +5 -1
  16. package/dist/lib/denon-protocol.js +26 -11
  17. package/dist/lib/display-mode-controller.d.ts +12 -5
  18. package/dist/lib/display-mode-controller.js +181 -87
  19. package/dist/lib/house-schedule-publishing.js +1 -1
  20. package/dist/lib/light-styling.d.ts +2 -2
  21. package/dist/lib/light-styling.js +5 -4
  22. package/dist/lib/motion-publishing.js +1 -1
  23. package/dist/lib/occupancy-publishing.js +1 -1
  24. package/dist/lib/power-reading.d.ts +5 -0
  25. package/dist/lib/power-reading.js +13 -0
  26. package/dist/lib/room-controller.d.ts +2 -3
  27. package/dist/lib/room-controller.js +18 -2
  28. package/dist/lib/room-lighting-discovery.js +1 -1
  29. package/dist/lib/room-publishing.d.ts +3 -0
  30. package/dist/lib/shelly-cover.d.ts +46 -0
  31. package/dist/lib/shelly-cover.js +193 -0
  32. package/dist/lib/source-capability-controller.d.ts +2 -0
  33. package/dist/lib/source-capability-controller.js +27 -6
  34. package/dist/lib/switch-policy.d.ts +1 -1
  35. package/dist/lib/switch-policy.js +1 -1
  36. package/dist/lib/theatre-requests.d.ts +29 -0
  37. package/dist/lib/theatre-requests.js +89 -0
  38. package/dist/lib/theatre-state-contract.d.ts +5 -22
  39. package/dist/lib/theatre-state-contract.js +18 -73
  40. package/dist/lib/toggle-power.d.ts +41 -0
  41. package/dist/lib/toggle-power.js +74 -0
  42. package/dist/lib/topic-names.d.ts +1 -0
  43. package/dist/lib/topic-names.js +7 -0
  44. package/dist/lib/{display-transport.d.ts → transports/display-transport.d.ts} +1 -1
  45. package/dist/lib/{display-transport.js → transports/display-transport.js} +32 -7
  46. package/dist/lib/z2m-light.d.ts +8 -0
  47. package/dist/lib/z2m-light.js +64 -3
  48. package/dist/nodes/activity-lighting-controller.html +8 -0
  49. package/dist/nodes/avr-controller.html +28 -6
  50. package/dist/nodes/avr-controller.js +16 -6
  51. package/dist/nodes/display-mode-controller.html +61 -11
  52. package/dist/nodes/display-mode-controller.js +16 -6
  53. package/dist/nodes/room-controller.js +14 -0
  54. package/dist/nodes/shelly-cover.d.ts +3 -0
  55. package/dist/nodes/shelly-cover.html +65 -0
  56. package/dist/nodes/shelly-cover.js +34 -0
  57. package/examples/Home theatre activity.json +5 -5
  58. package/examples/Home theatre equipment.json +4 -4
  59. package/examples/Shelly cover.json +252 -0
  60. package/package.json +3 -2
@@ -40,8 +40,8 @@ const registerAvrController = (RED) => {
40
40
  discoveryPrefix: (0, ha_discovery_1.discoveryPrefixSetting)(config.discoveryPrefix),
41
41
  nodeId: node.id,
42
42
  idScheme: (0, settings_1.optionalChoiceSetting)(config.idScheme, "ID scheme", ha_discovery_1.ID_SCHEMES) ?? "node",
43
- minVolume: controllerConfig.minVolume,
44
- maxVolume: controllerConfig.maxVolume
43
+ minVolumeDb: controllerConfig.minVolumeDb,
44
+ maxVolumeDb: controllerConfig.maxVolumeDb
45
45
  };
46
46
  }
47
47
  catch (error) {
@@ -70,8 +70,10 @@ const registerAvrController = (RED) => {
70
70
  process({ avr: { kind: "tick" } }, node.send.bind(node));
71
71
  }), delay);
72
72
  }
73
+ // As the reducer restores it, so a state saved before 5.0 is published in dB.
73
74
  function observed() {
74
- return context.get("state")?.observed;
75
+ const saved = context.get("state");
76
+ return saved ? (0, avr_controller_1.createAvrState)(controllerConfig, saved).observed : undefined;
75
77
  }
76
78
  // MQTT publications go on the third output, apart from the receiver's
77
79
  // commands and the theatre's events. Available, and clear of what it no
@@ -85,6 +87,7 @@ const registerAvrController = (RED) => {
85
87
  output: 2,
86
88
  outputs: 3
87
89
  });
90
+ let warnedLegacyVolume = false;
88
91
  function process(msg, send) {
89
92
  const before = observed();
90
93
  const result = (0, adapter_1.runReducer)(node, { area: controllerConfig.area, component: "avr-controller" }, (saved, now) => (0, avr_controller_1.transitionAvr)(saved, msg, controllerConfig, now));
@@ -92,6 +95,13 @@ const registerAvrController = (RED) => {
92
95
  payload: Buffer.from(command.payload, "utf8"),
93
96
  avr_command: command.avrCommand
94
97
  }));
98
+ // Once per deploy, so a flow still sending the receiver's own units is
99
+ // told without filling the log.
100
+ if (!warnedLegacyVolume && result.traces.some(({ reason }) => reason === avr_controller_1.LEGACY_VOLUME_UNITS)) {
101
+ warnedLegacyVolume = true;
102
+ node.warn("volume requests with value in the receiver's own 0-98 are deprecated and will stop working in 6.0: " +
103
+ "send valueDb (dB, where the receiver's 80 is 0 dB) instead");
104
+ }
95
105
  const outputs = [...result.events, ...result.targetStates];
96
106
  if (commands.length || outputs.length) {
97
107
  send([
@@ -123,9 +133,9 @@ const registerAvrController = (RED) => {
123
133
  // to the last one first.
124
134
  let volumeRequests = 0;
125
135
  let volumeSetTimer;
126
- function requestVolume(value) {
136
+ function requestVolume(valueDb) {
127
137
  volumeRequests += 1;
128
- process({ avr: { kind: "volume", requestId: `mqtt-volume-${Date.now()}-${volumeRequests}`, mode: "absolute", value } }, node.send.bind(node));
138
+ process({ avr: { kind: "volume", requestId: `mqtt-volume-${Date.now()}-${volumeRequests}`, mode: "absolute", valueDb } }, node.send.bind(node));
129
139
  }
130
140
  (0, adapter_1.onInput)(node, (msg, send) => {
131
141
  const volume = (0, avr_publishing_1.avrVolumeRequest)(msg, publishing);
@@ -137,7 +147,7 @@ const registerAvrController = (RED) => {
137
147
  clearTimeout(volumeSetTimer);
138
148
  volumeSetTimer = setTimeout((0, adapter_1.guarded)(node, () => {
139
149
  volumeSetTimer = undefined;
140
- requestVolume(volume.value);
150
+ requestVolume(volume.valueDb);
141
151
  }), avr_publishing_1.VOLUME_SET_SETTLE_MS);
142
152
  return;
143
153
  }
@@ -7,8 +7,20 @@
7
7
  area: {value: ""},
8
8
  tvHost: {value: "", required: true},
9
9
  screenHost: {value: "", required: true},
10
- projectorMeterHost: {value: "", required: true},
11
- screenOpenPosition: {value: 82, required: true, validate: RED.validators.number()},
10
+ // projectorMeterHost before 5.0; the dialog fills this from it.
11
+ // Optional: without one, the flow reports the projector's power.
12
+ projectorPowerMeterHost: {value: ""},
13
+ // The name before 5.0, with no form row. Listed so the editor keeps it:
14
+ // it holds only the properties named here. Cleared once the dialog
15
+ // saves the new one.
16
+ projectorMeterHost: {value: ""},
17
+ // Empty: the screen's own open command. No shared default position: a
18
+ // node saved with one keeps it.
19
+ screenOpenPosition: {value: "", validate: function (v) {
20
+ if (v === undefined || v === null || String(v).trim() === "") return true;
21
+ var position = Number(v);
22
+ return isFinite(position) && position > 0 && position <= 100;
23
+ }},
12
24
  screenTolerance: {value: 2, required: true, validate: RED.validators.number()},
13
25
  pollMs: {value: 2000, required: true, validate: RED.validators.number()},
14
26
  queryTimeoutMs: {value: 5000, required: true, validate: RED.validators.number()},
@@ -25,9 +37,20 @@
25
37
  transportTimeoutMs: {value: 5000, required: true, validate: RED.validators.number()}
26
38
  },
27
39
  credentials: {tvPsk: {type: "password"}},
40
+ oneditprepare: function () {
41
+ // A flow saved before 5.0: show its meter host, so saving the dialog keeps it.
42
+ if (!this.projectorPowerMeterHost && this.projectorMeterHost) {
43
+ $("#node-input-projectorPowerMeterHost").val(this.projectorMeterHost);
44
+ }
45
+ },
46
+ oneditsave: function () {
47
+ // The dialog showed the old host in the field, so what's left there is
48
+ // the user's choice, including none.
49
+ this.projectorMeterHost = "";
50
+ },
28
51
  inputs: 1,
29
- outputs: 2,
30
- outputLabels: ["projector IR fallback", "state and results"],
52
+ outputs: 3,
53
+ outputLabels: ["projector IR fallback", "state and results", "projector power queries"],
31
54
  icon: "font-awesome/fa-television",
32
55
  label: function () { return this.name || (this.area ? this.area + " " : "") + "display mode"; }
33
56
  });
@@ -36,11 +59,11 @@
36
59
  <script type="text/html" data-template-name="home-display-mode-controller">
37
60
  <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
38
61
  <div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area"></div>
39
- <div class="form-row"><label for="node-input-tvHost">Bravia host</label><input type="text" id="node-input-tvHost"></div>
40
- <div class="form-row"><label for="node-input-tvPsk">Bravia PSK</label><input type="password" id="node-input-tvPsk"></div>
41
- <div class="form-row"><label for="node-input-screenHost">Screen Shelly host</label><input type="text" id="node-input-screenHost"></div>
42
- <div class="form-row"><label for="node-input-projectorMeterHost">Projector Shelly host</label><input type="text" id="node-input-projectorMeterHost"></div>
43
- <div class="form-row"><label for="node-input-screenOpenPosition">Screen viewing position</label><input type="number" id="node-input-screenOpenPosition"></div>
62
+ <div class="form-row"><label for="node-input-tvHost">TV host</label><input type="text" id="node-input-tvHost"></div>
63
+ <div class="form-row"><label for="node-input-tvPsk">TV pre-shared key</label><input type="password" id="node-input-tvPsk"></div>
64
+ <div class="form-row"><label for="node-input-screenHost">Screen controller host</label><input type="text" id="node-input-screenHost"></div>
65
+ <div class="form-row"><label for="node-input-projectorPowerMeterHost">Projector power meter host (optional)</label><input type="text" id="node-input-projectorPowerMeterHost"></div>
66
+ <div class="form-row"><label for="node-input-screenOpenPosition">Screen viewing position</label><input type="number" min="1" max="100" id="node-input-screenOpenPosition" placeholder="fully open"></div>
44
67
  <div class="form-row"><label for="node-input-screenTolerance">Screen position tolerance</label><input type="number" id="node-input-screenTolerance"></div>
45
68
  <div class="form-row"><label for="node-input-pollMs">Confirmation poll milliseconds</label><input type="number" id="node-input-pollMs"></div>
46
69
  <div class="form-row"><label for="node-input-queryTimeoutMs">Query timeout milliseconds</label><input type="number" id="node-input-queryTimeoutMs"></div>
@@ -65,7 +88,34 @@
65
88
  TV is left on. A projector warming up or cooling down finishes before a newer request changes it; if it doesn't finish in time, the
66
89
  newer request carries on from what the projector then reports.</p>
67
90
  <p>Send <code>msg.display = {kind: "intent", requestId, generation, mode}</code>. Send <code>kind: "startup"</code> after deployment to query every owned device and reconcile persisted intent. Send <code>kind: "refresh"</code> to re-confirm a settled display from fresh readings.</p>
68
- <p>The Bravia and both Shelly devices use direct LAN APIs. Output 1 carries the projector power toggle (<code>msg.payload = "power"</code> with <code>msg.display_command</code>) for your infrared transport, commanded directly rather than through Home Assistant. Enable “Projector power is fallback” to include its use in activity metrics. Output 2 emits observed state plus ready, manual-override, failed, rejected and superseded results, and <code>msg.theatre</code> target state for the theatre activity controller: wire it straight back to that controller.</p>
91
+ <p>Each device is reached directly over its LAN API. The <b>TV host</b> is a Sony Bravia with IP control and a
92
+ pre-shared key. The <b>Screen controller host</b> is a Shelly Gen2 cover (its <code>Cover</code> RPC). For
93
+ projector mode it opens the screen to the <b>Screen viewing position</b> (a percentage of its travel) and confirms it
94
+ within the <b>Screen position tolerance</b>; left empty, it uses the screen's own open command and confirms the
95
+ screen fully open, which also suits a screen that isn't calibrated for positions. Other modes close it with its
96
+ own close, which runs to the end and restores a position the screen has lost. A viewing position needs a screen
97
+ that knows where it is: one that doesn't is closed first, and if it still has no position (not calibrated), the
98
+ request fails with reason <code>screen-not-calibrated</code>; calibrate it, or clear the viewing position. The
99
+ <b>Projector power meter host</b>, if set, is a Shelly Gen2 switch with power metering on the projector's supply
100
+ (switch 1), read against <b>Projector on watts</b> and <b>Projector standby watts</b>. A flow saved before 5.0 names
101
+ that host <code>projectorMeterHost</code>, which is still read.</p>
102
+ <p>Output 1 carries the projector power toggle (<code>msg.payload = "power"</code> with <code>msg.display_command</code>) for your infrared transport, commanded directly rather than through Home Assistant. Enable “Projector power is fallback” to include its use in activity metrics. Output 2 emits observed state plus ready, manual-override, failed, rejected and superseded results, and <code>msg.theatre</code> target state for the theatre activity controller: wire it straight back to that controller. Output 3 asks for the projector's power when there is no meter host (below).</p>
103
+ <h3>Projector power from your own flow</h3>
104
+ <p>Leave <b>Projector power meter host</b> empty to report the projector's power from any meter or adapter: send
105
+ <code>msg.display = {kind: "observed", device: "projector", power: "on"}</code> (<code>"on"</code>,
106
+ <code>"standby"</code> or <code>"transitioning"</code>, in lower case), or a meter's reading as <code>watts: 140</code>,
107
+ read against the on and standby watts. A smart plug's own <code>ON</code> and <code>OFF</code> are its socket, not the
108
+ lamp, so send its power in watts instead. A lamp <code>"transitioning"</code>, or watts between the two, keeps its last
109
+ settled state while it warms or cools. <code>observedAt</code> (an ISO time) and <code>source</code> are optional.</p>
110
+ <p>The node needs a fresh projector reading at every request and while it confirms a change. When it does, it sends
111
+ <code>msg.payload = "query"</code> on output 3: wire that to whatever makes your meter report, such as a Zigbee2MQTT
112
+ plug's <code>/get</code> topic. Output 3 can be left unwired only if the meter reports on its own at least once every
113
+ <b>Query timeout milliseconds</b>, whether or not the power changes; a meter that reports only on a change says
114
+ nothing while the projector sits steady. A device that hasn't reported within the query timeout is asked again, up to
115
+ <b>Maximum idempotent attempts</b> in all, and then the request fails with reason <code>no-reading</code>, naming
116
+ the device. This applies to every device, with or without a meter host: keep <b>Transport timeout milliseconds</b>
117
+ below <b>Query timeout milliseconds</b> &times; <b>Maximum idempotent attempts</b>, so a slow device's answer
118
+ arrives before it is given up on.</p>
69
119
  <p>An unsolicited physical-state change after readiness latches manual ownership. The controller observes and reports it without issuing corrective commands; a newer activity intent resumes automation.</p>
70
- <p>The Bravia PSK remains in Node-RED's encrypted credential store and is never emitted in a message or status.</p>
120
+ <p>The TV pre-shared key remains in Node-RED's encrypted credential store and is never emitted in a message or status.</p>
71
121
  </script>
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const display_mode_controller_1 = require("../lib/display-mode-controller");
3
- const display_transport_1 = require("../lib/display-transport");
3
+ const display_transport_1 = require("../lib/transports/display-transport");
4
4
  const adapter_1 = require("./adapter");
5
5
  const settings_1 = require("../lib/settings");
6
6
  const registerDisplayModeController = (RED) => {
@@ -12,14 +12,18 @@ const registerDisplayModeController = (RED) => {
12
12
  // Defaults and limits come from the reducer's own normalisation.
13
13
  let controllerConfig;
14
14
  let transport;
15
+ let projectorPowerMeterHost;
15
16
  try {
16
17
  controllerConfig = (0, display_mode_controller_1.normaliseConfig)(config);
18
+ // Optional: without a meter of its own, the node asks the flow for the
19
+ // projector's power on its third output, and reads what comes back.
20
+ projectorPowerMeterHost = String(config.projectorPowerMeterHost ?? "").trim() || String(config.projectorMeterHost ?? "").trim();
17
21
  transport = new display_transport_1.DisplayTransport({
18
22
  // No defaults: these name the user's own devices.
19
23
  tvHost: (0, settings_1.textSetting)(config.tvHost, "TV host"),
20
24
  tvPsk: String(node.credentials?.tvPsk ?? ""),
21
25
  screenHost: (0, settings_1.textSetting)(config.screenHost, "screen host"),
22
- projectorMeterHost: (0, settings_1.textSetting)(config.projectorMeterHost, "projector meter host"),
26
+ projectorMeterHost: projectorPowerMeterHost,
23
27
  timeoutMs: (0, settings_1.numberSetting)(config.transportTimeoutMs, "transport timeout", 5000)
24
28
  });
25
29
  }
@@ -42,9 +46,11 @@ const registerDisplayModeController = (RED) => {
42
46
  function schedule(state) {
43
47
  clearTimeout(timer);
44
48
  timer = undefined;
45
- if (!state.pending?.nextAt)
49
+ // The pending step's next check or the discovery deadline, whichever is first.
50
+ const due = [state.pending?.nextAt, state.discovery?.nextAt].filter((at) => Number.isFinite(at));
51
+ if (!due.length)
46
52
  return;
47
- const delay = Math.max(0, state.pending.nextAt - Date.now());
53
+ const delay = Math.max(0, Math.min(...due) - Date.now());
48
54
  const generation = state.desired?.generation || state.generation;
49
55
  timer = setTimeout((0, adapter_1.guarded)(node, () => {
50
56
  process({ display: { kind: "tick", generation } }, node.send.bind(node));
@@ -55,7 +61,11 @@ const registerDisplayModeController = (RED) => {
55
61
  node.send([{
56
62
  payload: "power",
57
63
  display_command: command
58
- }, null]);
64
+ }, null, null]);
65
+ return;
66
+ }
67
+ if (command.device === "projector" && command.operation === "query_power" && !projectorPowerMeterHost) {
68
+ node.send([null, null, { payload: "query", display_command: command }]);
59
69
  return;
60
70
  }
61
71
  const result = await transport.execute(command);
@@ -66,7 +76,7 @@ const registerDisplayModeController = (RED) => {
66
76
  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));
67
77
  const outputs = [...result.events, ...result.targetStates];
68
78
  if (outputs.length) {
69
- send([null, outputs.map((event) => ({ payload: undefined, ...event }))]);
79
+ send([null, outputs.map((event) => ({ payload: undefined, ...event })), null]);
70
80
  }
71
81
  updateStatus(result.status);
72
82
  schedule(result.state);
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const room_controller_1 = require("../lib/room-controller");
2
3
  const circadian_1 = require("../lib/circadian");
3
4
  const circadian_schedule_1 = require("../lib/circadian-schedule");
4
5
  const publishing_lifecycle_1 = require("./publishing-lifecycle");
@@ -105,9 +106,22 @@ const registerRoomController = (RED) => {
105
106
  if (result.outputs.length) {
106
107
  send([result.outputs.map((output) => ({ ...output, payload: output.payload }))]);
107
108
  }
109
+ // Once per deploy, so a flow still sending Zigbee2MQTT units is told
110
+ // without filling the log.
111
+ if (!warnedLegacyUnits && result.traces.some(({ reason }) => reason === room_controller_1.LEGACY_LIGHT_UNITS)) {
112
+ warnedLegacyUnits = true;
113
+ node.warn("lighting values in brightness (1-254) or color_temp (mireds) are deprecated and will stop working in 6.0: " +
114
+ "send brightnessPct (0-100) and colorTempKelvin instead");
115
+ }
116
+ if (!warnedInvalidValues && result.traces.some(({ reason }) => reason === room_controller_1.INVALID_LIGHT_VALUES)) {
117
+ warnedInvalidValues = true;
118
+ node.warn("lighting values left out: brightnessPct must be a number and colorTempKelvin a number above 0");
119
+ }
108
120
  updateStatus(result.status);
109
121
  return result;
110
122
  }
123
+ let warnedLegacyUnits = false;
124
+ let warnedInvalidValues = false;
111
125
  (0, adapter_1.onInput)(node, (msg, send) => {
112
126
  // The startup's own announcement comes from publishRoom.
113
127
  if ((0, adapter_1.objectField)(msg, "lighting")?.kind === "startup")
@@ -0,0 +1,3 @@
1
+ import type { NodeInitializer } from "node-red";
2
+ declare const registerShellyCover: NodeInitializer;
3
+ export = registerShellyCover;
@@ -0,0 +1,65 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType("home-shelly-cover", {
3
+ category: "home automation",
4
+ color: "#e2d96e",
5
+ defaults: {
6
+ name: {value: ""},
7
+ // No default: it names the user's own device.
8
+ topicPrefix: {value: "", required: true, validate: function (v) {
9
+ var prefix = String(v || "").trim().replace(/^\/+|\/+$/g, "");
10
+ return prefix !== "" && !/[+#]/.test(prefix);
11
+ }},
12
+ channel: {value: 0, required: true, validate: function (v) {
13
+ return /^\d+$/.test(String(v).trim());
14
+ }}
15
+ },
16
+ inputs: 1,
17
+ outputs: 2,
18
+ outputLabels: ["to the device (MQTT out)", "to the cover controller"],
19
+ icon: "font-awesome/fa-exchange",
20
+ label: function () { return this.name || "shelly cover"; },
21
+ paletteLabel: "shelly cover"
22
+ });
23
+ </script>
24
+
25
+ <script type="text/html" data-template-name="home-shelly-cover">
26
+ <div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
27
+ <div class="form-row"><label for="node-input-topicPrefix">MQTT topic prefix</label><input type="text" id="node-input-topicPrefix" placeholder="the device's ID, e.g. shellyplus2pm-a8032ab12345"></div>
28
+ <div class="form-row"><label for="node-input-channel">Cover ID</label><input type="number" min="0" step="1" id="node-input-channel"></div>
29
+ </script>
30
+
31
+ <script type="text/html" data-help-name="home-shelly-cover">
32
+ <p>Connects a Shelly Gen2 or later device in cover mode to a <b>home cover controller</b>, over the device's own
33
+ MQTT API: no function nodes, no Home Assistant and no HTTP.</p>
34
+ <h3>Wiring</h3>
35
+ <ol>
36
+ <li>An <b>MQTT in</b> node subscribed to <code>&lt;prefix&gt;/#</code> (output: auto-detect) → this node.</li>
37
+ <li>The cover controller's first output (its device commands) → this node.</li>
38
+ <li>This node's first output → an <b>MQTT out</b> node on the same broker, with no topic set.</li>
39
+ <li>This node's second output → the cover controller.</li>
40
+ </ol>
41
+ <p>On the device, MQTT must be on with <b>Enable MQTT Control</b> (the default): without it the device ignores
42
+ the commands this node sends. <b>RPC status notifications</b> (also the default) report each change; with
43
+ <b>Generic status update</b> it also reports a full status on every significant change. Calibrate the cover
44
+ on the device first.</p>
45
+ <h3>Settings</h3>
46
+ <dl class="message-properties">
47
+ <dt>MQTT topic prefix</dt><dd>the device's topic prefix: its device ID (such as
48
+ <code>shellyplus2pm-a8032ab12345</code>) unless a custom one is set on the device.</dd>
49
+ <dt>Cover ID</dt><dd><code>0</code>, or <code>1</code> for a device's second cover.</dd>
50
+ </dl>
51
+ <h3>What it does</h3>
52
+ <ul>
53
+ <li><code>set_position</code> is sent as <code>pos,&lt;0-100&gt;</code>, <code>stop</code> as <code>stop</code>,
54
+ and <code>observe</code> as <code>status_update</code>, which makes the device report a fresh status, on
55
+ <code>&lt;prefix&gt;/command/cover:&lt;id&gt;</code>.</li>
56
+ <li>The device's status, from <code>&lt;prefix&gt;/status/cover:&lt;id&gt;</code> and its change notifications on
57
+ <code>&lt;prefix&gt;/events/rpc</code>, becomes <code>msg.cover = {kind: "observed", position, motion,
58
+ observedAt}</code>, with 0 closed and 100 open (set <b>invert</b> on the controller if yours runs the other
59
+ way). <code>&lt;prefix&gt;/online</code> becomes <code>{kind: "availability", online}</code>.</li>
60
+ <li>A cover that isn't calibrated, or doesn't know its position, has no position to report: the controller's
61
+ command in hand fails with reason <code>not-calibrated</code> or <code>position-unknown</code>, and a
62
+ position isn't sent to an uncalibrated cover, which would refuse it.</li>
63
+ <li>Anything else on the input is ignored. The node's status shows the cover's last state and position.</li>
64
+ </ul>
65
+ </script>
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ const shelly_cover_1 = require("../lib/shelly-cover");
3
+ const adapter_1 = require("./adapter");
4
+ const registerShellyCover = (RED) => {
5
+ function HomeShellyCover(config) {
6
+ RED.nodes.createNode(this, config);
7
+ const node = this;
8
+ let device;
9
+ try {
10
+ device = (0, shelly_cover_1.normaliseShellyCoverConfig)(config);
11
+ }
12
+ catch (error) {
13
+ (0, adapter_1.invalidConfig)(node, error);
14
+ return;
15
+ }
16
+ const trace = { area: "", component: "shelly-cover" };
17
+ node.status({ fill: "grey", shape: "ring", text: "waiting for the device" });
18
+ (0, adapter_1.onInput)(node, (msg, send) => {
19
+ const result = (0, adapter_1.runReducer)(node, trace, (saved, now) => (0, shelly_cover_1.transitionShellyCover)(saved, msg, device, now));
20
+ // MQTT publications for the device on output 1, for an MQTT out node;
21
+ // readings for the cover controller on output 2.
22
+ const outputs = [
23
+ result.publications.length ? result.publications.map((publication) => ({ ...publication })) : null,
24
+ result.readings.length ? result.readings.map((reading) => ({ payload: undefined, ...reading })) : null
25
+ ];
26
+ if (outputs.some((output) => output !== null))
27
+ send(outputs);
28
+ node.status({ fill: result.status.calibrated ? "green" : "yellow", shape: "dot", text: result.status.text });
29
+ });
30
+ }
31
+ RED.nodes.registerType("home-shelly-cover", HomeShellyCover);
32
+ };
33
+ module.exports = registerShellyCover;
34
+ //# sourceMappingURL=shelly-cover.js.map
@@ -126,7 +126,7 @@
126
126
  "type": "home-activity-lighting-controller",
127
127
  "name": "",
128
128
  "area": "",
129
- "profiles": "{\"off\":{\"targets\":[],\"values\":{}},\"tv\":{\"targets\":[\"main\"],\"values\":{\"brightness\":64,\"color_temp\":400}}}",
129
+ "profiles": "{\"off\":{\"targets\":[],\"values\":{}},\"tv\":{\"targets\":[\"main\"],\"values\":{\"brightnessPct\":25,\"colorTempKelvin\":2500}}}",
130
130
  "confirmationTimeoutMs": 15000,
131
131
  "maxAttempts": 2,
132
132
  "x": 1380,
@@ -240,8 +240,8 @@
240
240
  "area": "",
241
241
  "tvHost": "",
242
242
  "screenHost": "",
243
- "projectorMeterHost": "",
244
- "screenOpenPosition": 82,
243
+ "projectorPowerMeterHost": "",
244
+ "screenOpenPosition": "",
245
245
  "screenTolerance": 2,
246
246
  "pollMs": 2000,
247
247
  "queryTimeoutMs": 5000,
@@ -312,8 +312,8 @@
312
312
  "sources": "{\"shield\":\"SAT/CBL\",\"playstation\":\"GAME\"}",
313
313
  "retryMs": 2000,
314
314
  "maxAttempts": 3,
315
- "minVolume": 0,
316
- "maxVolume": 60,
315
+ "minVolumeDb": -80,
316
+ "maxVolumeDb": -20,
317
317
  "x": 1380,
318
318
  "y": 280,
319
319
  "wires": [
@@ -40,8 +40,8 @@
40
40
  "sources": "{\"shield\":\"SAT/CBL\",\"playstation\":\"GAME\"}",
41
41
  "retryMs": 2000,
42
42
  "maxAttempts": 3,
43
- "minVolume": 0,
44
- "maxVolume": 60,
43
+ "minVolumeDb": -80,
44
+ "maxVolumeDb": -20,
45
45
  "x": 420,
46
46
  "y": 100,
47
47
  "wires": [
@@ -116,8 +116,8 @@
116
116
  "area": "",
117
117
  "tvHost": "",
118
118
  "screenHost": "",
119
- "projectorMeterHost": "",
120
- "screenOpenPosition": 82,
119
+ "projectorPowerMeterHost": "",
120
+ "screenOpenPosition": "",
121
121
  "screenTolerance": 2,
122
122
  "pollMs": 2000,
123
123
  "queryTimeoutMs": 5000,