node-red-contrib-unifi-ultimate 1.1.16 → 1.1.17

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 CHANGED
@@ -202,6 +202,8 @@ Every node has **two outputs**:
202
202
 
203
203
  When an error occurs, the node status turns red and the error message comes out of the second output. Connect it to a **debug** node to see what happened, or wire it to any notification logic in your flow.
204
204
 
205
+ **Startup and missing readings** — Protect, Access and Network device nodes have an advanced **Emit startup states and undefined payloads** checkbox, disabled by default, including for existing flows. With it disabled, initial state snapshots and missing, null or `undefined` readings are suppressed. Valid `false` and `0` readings still pass through. Enable the checkbox to allow startup snapshots and missing payloads. Protect observables never replay an old value when a fresh reading is unavailable; LPR and event-photo actions continue to emit only actual readings or photos.
206
+
205
207
  **Repeat periodically** — for read actions, you can tick _Emit periodically_ in the node editor to have the node send the result automatically at a fixed interval, without needing an Inject node. The **Presence Detection** node offers a similar **Resend (s)** field: set it above `0` to re-emit the last known presence value on that cadence (even when unchanged). Resent messages carry `msg.eventName = "repeat"` so you can tell them apart from real state changes; leave it at `0` to disable.
206
208
 
207
209
  ## Example Flows
@@ -15,6 +15,7 @@
15
15
  inputs: { value: 1 },
16
16
  capability: { value: "observe", required: true },
17
17
  capabilityConfig: { value: "{}" },
18
+ emitStartupAndUndefined: { value: false },
18
19
  autoEmit: { value: false },
19
20
  autoEmitInterval: { value: 60, validate: RED.validators.number() }
20
21
  },
@@ -1165,6 +1166,11 @@
1165
1166
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
1166
1167
  <input type="text" id="node-input-name" placeholder="Node name">
1167
1168
  </div>
1169
+ <div class="form-row">
1170
+ <label for="node-input-emitStartupAndUndefined"><i class="fa fa-sign-out"></i> Output</label>
1171
+ <input type="checkbox" id="node-input-emitStartupAndUndefined" style="display:inline-block; width:auto; vertical-align:top;">
1172
+ <label for="node-input-emitStartupAndUndefined" style="width:auto;">Emit startup states and undefined payloads</label>
1173
+ </div>
1168
1174
  <div class="form-row" id="node-row-autoEmit">
1169
1175
  <label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
1170
1176
  <input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
@@ -1179,6 +1185,7 @@
1179
1185
  </script>
1180
1186
 
1181
1187
  <script type="text/html" data-help-name="unifi-access-device">
1188
+ <p><b>Emit startup states and undefined payloads</b> is disabled by default, including in existing flows. Enable it to emit the initial device state and readings with a missing, null or undefined payload. Otherwise these messages are suppressed; false and zero remain valid values. Missing readings never replay a previous value.</p>
1182
1189
  <p><a href="https://youtube.com/playlist?list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ&si=4MmW1nNTCLrJtEHv" target="_blank" rel="noopener noreferrer"><img src="resources/node-red-contrib-unifi-ultimate/logos/youtube-icon.svg" alt="YouTube" width="24" height="18" style="vertical-align:text-bottom; margin-right:6px;">Youtube Tutorials</a></p>
1183
1190
 
1184
1191
  <p>Use this node to execute a configured UniFi Access action or listen for live Access events.</p>
@@ -21,7 +21,8 @@ const {
21
21
  extractDeviceNameFromPayload,
22
22
  attachDeviceNameToPayload,
23
23
  attachDetails,
24
- buildErrorOutputMessage
24
+ buildErrorOutputMessage,
25
+ sendWithPayload
25
26
  } = require("./utils/common-utils");
26
27
  const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
27
28
 
@@ -98,6 +99,7 @@ module.exports = function(RED) {
98
99
  node.deviceId = config.deviceId || "";
99
100
  node.capability = config.capability || "observe";
100
101
  node.capabilityConfig = config.capabilityConfig || "{}";
102
+ node.emitStartupAndUndefined = parseBoolean(config.emitStartupAndUndefined);
101
103
  node.autoEmit = parseBoolean(config.autoEmit);
102
104
  node.autoEmitIntervalSeconds = parseIntervalSeconds(config.autoEmitInterval, 60);
103
105
  node.autoEmitTimer = null;
@@ -115,7 +117,7 @@ module.exports = function(RED) {
115
117
  const output = { payload };
116
118
  decorateOutputMessage(output, node.currentDevice, eventName);
117
119
  attachDetails(output, { ...details, unifiAccess: buildBaseMetadata(node.deviceType, node.deviceId, node.capability, { source: details.monitor.source }) });
118
- node.send(output);
120
+ sendWithPayload(node.send.bind(node), output, node.emitStartupAndUndefined);
119
121
  }
120
122
  });
121
123
  node.getSimpleMonitorDescriptor = () => node.isObserving && isSimpleMonitor() && node.deviceId ? {
@@ -163,10 +165,10 @@ module.exports = function(RED) {
163
165
  // event messages are available, forward them in sequence.
164
166
  try {
165
167
  if (stateMsg) {
166
- send(stateMsg);
168
+ sendWithPayload(send, stateMsg, node.emitStartupAndUndefined);
167
169
  }
168
170
  if (eventMsg) {
169
- send(eventMsg);
171
+ sendWithPayload(send, eventMsg, node.emitStartupAndUndefined);
170
172
  }
171
173
  } catch (error) {
172
174
  node.warn(`Access output send failed: ${error && error.message ? error.message : error}`);
@@ -207,6 +209,7 @@ module.exports = function(RED) {
207
209
  });
208
210
 
209
211
  setNodeStatus({ fill: "green", shape: "dot", text: buildNodeStatus(deviceType, payload) });
212
+ if (source === "startup" && !node.emitStartupAndUndefined) return;
210
213
  sendOutputs(send, stateMsg, null);
211
214
  }
212
215
 
@@ -406,8 +409,7 @@ module.exports = function(RED) {
406
409
  return;
407
410
  }
408
411
 
409
- // Emit one initial snapshot so the flow starts with a known state
410
- // before websocket events arrive.
412
+ // Load the initial snapshot; output at startup is opt-in.
411
413
  fetchDeviceState(node.deviceType, node.deviceId, "observe", node.send.bind(node), "startup").catch(() => {
412
414
  });
413
415
  }
@@ -13,7 +13,8 @@ const {
13
13
  extractDeviceNameFromPayload,
14
14
  attachDeviceNameToPayload,
15
15
  attachDetails,
16
- buildErrorOutputMessage
16
+ buildErrorOutputMessage,
17
+ sendWithPayload
17
18
  } = require("./utils/common-utils");
18
19
  const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
19
20
 
@@ -864,7 +865,7 @@ module.exports = function(RED) {
864
865
  shape: "dot",
865
866
  text: `p${portIdx} ${formatPowerText(powerW)}W`
866
867
  });
867
- send(output);
868
+ sendWithPayload(send, output);
868
869
  }
869
870
 
870
871
  function handlePowerObservationEvent(send, action, event) {
@@ -919,7 +920,7 @@ module.exports = function(RED) {
919
920
  shape: "dot",
920
921
  text: `p${portIdx} ${formatPowerText(normalizedPowerW)}W`
921
922
  });
922
- send(output);
923
+ sendWithPayload(send, output);
923
924
  }
924
925
 
925
926
  function stopPowerObservation() {
@@ -1074,7 +1075,7 @@ module.exports = function(RED) {
1074
1075
  setNodeStatus({ fill: "yellow", shape: "dot", text: `${effectiveAction.payloadAction} ${okCount}/${results.length}` });
1075
1076
  }
1076
1077
 
1077
- send(output);
1078
+ sendWithPayload(send, output);
1078
1079
  }
1079
1080
 
1080
1081
  node.on("input", async function(msg, send, done) {
@@ -15,6 +15,7 @@
15
15
  inputs: { value: 1 },
16
16
  capability: { value: "observe", required: true },
17
17
  capabilityConfig: { value: "{}" },
18
+ emitStartupAndUndefined: { value: false },
18
19
  autoEmit: { value: false },
19
20
  autoEmitInterval: { value: 60, validate: RED.validators.number() }
20
21
  },
@@ -1279,6 +1280,11 @@
1279
1280
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
1280
1281
  <input type="text" id="node-input-name" placeholder="Node name">
1281
1282
  </div>
1283
+ <div class="form-row">
1284
+ <label for="node-input-emitStartupAndUndefined"><i class="fa fa-sign-out"></i> Output</label>
1285
+ <input type="checkbox" id="node-input-emitStartupAndUndefined" style="display:inline-block; width:auto; vertical-align:top;">
1286
+ <label for="node-input-emitStartupAndUndefined" style="width:auto;">Emit startup states and undefined payloads</label>
1287
+ </div>
1282
1288
  <div class="form-row" id="node-row-autoEmit">
1283
1289
  <label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
1284
1290
  <input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
@@ -1293,6 +1299,7 @@
1293
1299
  </script>
1294
1300
 
1295
1301
  <script type="text/html" data-help-name="unifi-network-device">
1302
+ <p><b>Emit startup states and undefined payloads</b> is disabled by default, including in existing flows. Enable it to emit the initial device state and readings with a missing, null or undefined payload. Otherwise these messages are suppressed; false and zero remain valid values. Missing readings never replay a previous value.</p>
1296
1303
  <p><a href="https://youtube.com/playlist?list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ&si=4MmW1nNTCLrJtEHv" target="_blank" rel="noopener noreferrer"><img src="resources/node-red-contrib-unifi-ultimate/logos/youtube-icon.svg" alt="YouTube" width="24" height="18" style="vertical-align:text-bottom; margin-right:6px;">Youtube Tutorials</a></p>
1297
1304
 
1298
1305
  <p>Use this node to execute a configured UniFi Network action on a selected site, UniFi device, or client.</p>
@@ -20,7 +20,8 @@ const {
20
20
  extractDeviceNameFromPayload,
21
21
  attachDeviceNameToPayload,
22
22
  attachDetails,
23
- buildErrorOutputMessage
23
+ buildErrorOutputMessage,
24
+ sendWithPayload
24
25
  } = require("./utils/common-utils");
25
26
  const UNOFFICIAL_NETWORK_STREAM_CAPABILITY = "observeUnofficialEvents";
26
27
  const UNOFFICIAL_POLL_INTERVAL_MS = 3000;
@@ -502,6 +503,7 @@ module.exports = function(RED) {
502
503
  node.deviceId = config.deviceId || "";
503
504
  node.capability = config.capability || "observe";
504
505
  node.capabilityConfig = config.capabilityConfig || "{}";
506
+ node.emitStartupAndUndefined = parseBoolean(config.emitStartupAndUndefined);
505
507
  node.autoEmit = parseBoolean(config.autoEmit);
506
508
  node.autoEmitIntervalSeconds = parseIntervalSeconds(config.autoEmitInterval, 60);
507
509
  node.autoEmitTimer = null;
@@ -519,7 +521,7 @@ module.exports = function(RED) {
519
521
  const output = { payload };
520
522
  decorateOutputMessage(output, node.currentDevice, eventName);
521
523
  attachDetails(output, { ...details, unifiNetwork: buildBaseMetadata(node.deviceType, node.deviceId, node.capability, { source: details.monitor.source }) });
522
- node.send(output);
524
+ sendWithPayload(node.send.bind(node), output, node.emitStartupAndUndefined);
523
525
  }
524
526
  });
525
527
  node.getSimpleMonitorDescriptor = () => node.isObserving && isSimpleMonitor() && node.deviceId ? {
@@ -616,7 +618,8 @@ module.exports = function(RED) {
616
618
  decorateOutputMessage(outputMsg, payload, source || "observe");
617
619
 
618
620
  setNodeStatus({ fill: "green", shape: "dot", text: buildNodeStatus(deviceType, payload) });
619
- send(outputMsg);
621
+ if (source === "startup" && !node.emitStartupAndUndefined) return;
622
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
620
623
  }
621
624
 
622
625
  async function fetchDeviceTemperatures(deviceType, deviceId, capabilityId, send) {
@@ -660,7 +663,7 @@ module.exports = function(RED) {
660
663
  ? `${statusTemperatureC} C`
661
664
  : "no temperature";
662
665
  setNodeStatus({ fill: temperatures.length > 0 ? "green" : "yellow", shape: "dot", text: statusText });
663
- send(outputMsg);
666
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
664
667
  }
665
668
 
666
669
  async function executeConfiguredCapabilityRequest(deviceType, deviceId, capabilityId, capabilityConfig) {
@@ -742,7 +745,7 @@ module.exports = function(RED) {
742
745
  decorateOutputMessage(outputMsg, outputMsg.payload, `request:${capabilityId}`);
743
746
 
744
747
  setNodeStatus({ fill: online ? "green" : "yellow", shape: "dot", text: online ? "online" : "offline" });
745
- send(outputMsg);
748
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
746
749
  }
747
750
 
748
751
  async function countOnlineClients(deviceType, deviceId, capabilityId, send) {
@@ -777,7 +780,7 @@ module.exports = function(RED) {
777
780
  decorateOutputMessage(outputMsg, outputMsg.payload, `request:${capabilityId}`);
778
781
 
779
782
  setNodeStatus({ fill: "green", shape: "dot", text: `${onlineClients.length} online` });
780
- send(outputMsg);
783
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
781
784
  }
782
785
 
783
786
  async function fetchDeviceSimpleStatistic(deviceType, deviceId, capabilityId, capabilityConfig, send) {
@@ -836,7 +839,7 @@ module.exports = function(RED) {
836
839
  ? `${metric.label} n/a`
837
840
  : `${metric.label} ${payloadValue}${metric.unit}`;
838
841
  setNodeStatus({ fill: payloadValue === null ? "yellow" : "green", shape: "dot", text: statusText });
839
- send(outputMsg);
842
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
840
843
  }
841
844
 
842
845
  async function createGuestVoucher(deviceType, deviceId, capabilityId, capabilityConfig, send) {
@@ -882,7 +885,7 @@ module.exports = function(RED) {
882
885
  decorateOutputMessage(outputMsg, outputMsg.payload, `request:${capabilityId}`);
883
886
 
884
887
  setNodeStatus({ fill: vouchers.length > 0 ? "green" : "yellow", shape: "dot", text: `${vouchers.length} voucher` });
885
- send(outputMsg);
888
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
886
889
  }
887
890
 
888
891
  async function invokeCapability(send, triggerSource) {
@@ -977,7 +980,7 @@ module.exports = function(RED) {
977
980
  decorateOutputMessage(outputMsg, responseData, `request:${capabilityId}`);
978
981
 
979
982
  setNodeStatus({ fill: "green", shape: "dot", text: `${capability.label}` });
980
- send(outputMsg);
983
+ sendWithPayload(send, outputMsg, node.emitStartupAndUndefined);
981
984
  }
982
985
 
983
986
  function resolveConfiguredCapabilityDefinition() {
@@ -1052,8 +1055,7 @@ module.exports = function(RED) {
1052
1055
  }
1053
1056
  const capabilityId = resolveCapabilityId(node.capability);
1054
1057
 
1055
- // Emit an initial snapshot at startup so the flow has a known state
1056
- // as soon as Node-RED starts.
1058
+ // Load the initial snapshot; output at startup is opt-in.
1057
1059
  fetchDeviceState(node.deviceType, node.deviceId, capabilityId, node.send.bind(node), "startup").catch(() => {
1058
1060
  });
1059
1061
  refreshUnofficialPollingFallback();
@@ -1163,7 +1165,7 @@ module.exports = function(RED) {
1163
1165
  })
1164
1166
  });
1165
1167
  decorateOutputMessage(output, output.payload, eventName);
1166
- node.send(output);
1168
+ sendWithPayload(node.send.bind(node), output, node.emitStartupAndUndefined);
1167
1169
  } catch (error) {
1168
1170
  }
1169
1171
  };
@@ -1241,7 +1243,7 @@ module.exports = function(RED) {
1241
1243
  })
1242
1244
  });
1243
1245
  decorateOutputMessage(output, output.payload, resolvedEventName);
1244
- node.send(output);
1246
+ sendWithPayload(node.send.bind(node), output, node.emitStartupAndUndefined);
1245
1247
  } catch (error) {
1246
1248
  }
1247
1249
  };
@@ -10,7 +10,8 @@ const {
10
10
  extractDeviceNameFromPayload,
11
11
  attachDetails,
12
12
  buildErrorOutputMessage,
13
- parseBoolean
13
+ parseBoolean,
14
+ sendWithPayload
14
15
  } = require("./utils/common-utils");
15
16
  const DEFAULT_REQUEST_TIMEOUT_MS = 8000;
16
17
 
@@ -105,7 +106,7 @@ function setupNetworkClientWatch(node, config) {
105
106
  };
106
107
  attachDetails(outputMsg, { client });
107
108
 
108
- node.send([outputMsg, null]);
109
+ sendWithPayload(node.send.bind(node), [outputMsg, null]);
109
110
  }
110
111
 
111
112
  function diffAndEmit(currentClients) {
@@ -389,7 +390,7 @@ module.exports = function(RED) {
389
390
  }
390
391
 
391
392
  try {
392
- node.send(outputMsg);
393
+ sendWithPayload(node.send.bind(node), outputMsg);
393
394
  } catch (error) {
394
395
  node.warn(`Presence output send failed: ${error && error.message ? error.message : error}`);
395
396
  }
@@ -7,7 +7,8 @@ const {
7
7
  appendStatusTimestamp,
8
8
  resolveNodeName,
9
9
  attachDetails,
10
- buildErrorOutputMessage
10
+ buildErrorOutputMessage,
11
+ sendWithPayload
11
12
  } = require("./utils/common-utils");
12
13
 
13
14
  const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
@@ -343,7 +344,7 @@ module.exports = function(RED) {
343
344
  setNodeStatus({ fill: "yellow", shape: "ring", text: `${succeeded}/${results.length} ok` });
344
345
  }
345
346
 
346
- send([output, null]);
347
+ sendWithPayload(send, [output, null]);
347
348
  }
348
349
 
349
350
  node.on("input", async function(msg, send, done) {
@@ -15,6 +15,7 @@
15
15
  inputs: { value: 1 },
16
16
  capability: { value: "observe", required: true },
17
17
  capabilityConfig: { value: "{}" },
18
+ emitStartupAndUndefined: { value: false },
18
19
  autoEmit: { value: false },
19
20
  autoEmitInterval: { value: 60, validate: RED.validators.number() }
20
21
  },
@@ -1173,6 +1174,11 @@
1173
1174
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
1174
1175
  <input type="text" id="node-input-name" placeholder="Node name">
1175
1176
  </div>
1177
+ <div class="form-row">
1178
+ <label for="node-input-emitStartupAndUndefined"><i class="fa fa-sign-out"></i> Output</label>
1179
+ <input type="checkbox" id="node-input-emitStartupAndUndefined" style="display:inline-block; width:auto; vertical-align:top;">
1180
+ <label for="node-input-emitStartupAndUndefined" style="width:auto;">Emit startup states and undefined payloads</label>
1181
+ </div>
1176
1182
  <div class="form-row" id="node-row-autoEmit">
1177
1183
  <label for="node-input-autoEmit"><i class="fa fa-repeat"></i> Repeat</label>
1178
1184
  <input type="checkbox" id="node-input-autoEmit" style="display:inline-block; width:auto; vertical-align:top;">
@@ -1187,6 +1193,7 @@
1187
1193
  </script>
1188
1194
 
1189
1195
  <script type="text/html" data-help-name="unifi-protect-device">
1196
+ <p><b>Emit startup states and undefined payloads</b> is disabled by default, including in existing flows. Enable it to emit the initial device state and readings with a missing, null or undefined payload. Otherwise these messages are suppressed; false and zero remain valid values. Missing readings never replay a previous value.</p>
1190
1197
  <p><a href="https://youtube.com/playlist?list=PL9Yh1bjbLAYrWKtMlopN0swuQXbdJ8MFJ&si=4MmW1nNTCLrJtEHv" target="_blank" rel="noopener noreferrer"><img src="resources/node-red-contrib-unifi-ultimate/logos/youtube-icon.svg" alt="YouTube" width="24" height="18" style="vertical-align:text-bottom; margin-right:6px;">Youtube Tutorials</a></p>
1191
1198
 
1192
1199
  <p>Use this node to execute a configured UniFi Protect action or listen for live Protect events.</p>
@@ -18,7 +18,9 @@ const {
18
18
  extractDeviceNameFromPayload,
19
19
  attachDeviceNameToPayload,
20
20
  attachDetails,
21
- buildErrorOutputMessage
21
+ buildErrorOutputMessage,
22
+ sendWithPayload,
23
+ hasPayloadValue
22
24
  } = require("./utils/common-utils");
23
25
  const { parseKnownPlates, namePlate, matchesDetection, describeDetection } = require("./utils/unifi-protect-detections");
24
26
  const { LICENSE_PLATE_EVENT_TYPES, extractLicensePlates, isLicensePlateEvent } = require("./utils/unifi-protect-lpr");
@@ -106,6 +108,7 @@ module.exports = function(RED) {
106
108
  node.deviceId = config.deviceId || "";
107
109
  node.capability = config.capability || "observe";
108
110
  node.capabilityConfig = config.capabilityConfig || "{}";
111
+ node.emitStartupAndUndefined = parseBoolean(config.emitStartupAndUndefined);
109
112
  node.autoEmit = parseBoolean(config.autoEmit);
110
113
  node.autoEmitIntervalSeconds = parseIntervalSeconds(config.autoEmitInterval, 60);
111
114
  node.autoEmitTimer = null;
@@ -164,10 +167,10 @@ module.exports = function(RED) {
164
167
  // event messages are available, forward them in sequence.
165
168
  try {
166
169
  if (stateMsg) {
167
- send(stateMsg);
170
+ sendWithPayload(send, stateMsg, node.emitStartupAndUndefined);
168
171
  }
169
172
  if (eventMsg) {
170
- send(eventMsg);
173
+ sendWithPayload(send, eventMsg, node.emitStartupAndUndefined);
171
174
  }
172
175
  } catch (error) {
173
176
  node.warn(`Protect output send failed: ${error && error.message ? error.message : error}`);
@@ -194,7 +197,8 @@ module.exports = function(RED) {
194
197
  if (observable) {
195
198
  // Observables let the node collapse complex Protect payloads into
196
199
  // a stable typed value while preserving the original context in details.raw.
197
- const observableValue = resolveObservableState(deviceType, payload, observable, node.currentObservableValue);
200
+ const observableValue = resolveObservableState(deviceType, payload, observable);
201
+ if (!node.emitStartupAndUndefined && !hasPayloadValue(observableValue)) return null;
198
202
  node.currentObservableValue = observableValue;
199
203
 
200
204
  const outputMsg = {
@@ -254,6 +258,7 @@ module.exports = function(RED) {
254
258
  const stateMsg = buildObservedStateMessage(deviceType, deviceId, capabilityConfig, payload, source);
255
259
 
256
260
  setNodeStatus({ fill: "green", shape: "dot", text: buildNodeStatus(deviceType, payload) });
261
+ if (source === "startup" && !node.emitStartupAndUndefined) return;
257
262
  sendOutputs(send, stateMsg, null);
258
263
  }
259
264
 
@@ -293,7 +298,7 @@ module.exports = function(RED) {
293
298
  const { events, ...history } = result;
294
299
  attachDetails(output, { history, unifiProtect: buildBaseMetadata(deviceType, deviceId, capabilityId, { source: "history" }) });
295
300
  setNodeStatus({ fill: result.hasMore ? "yellow" : "green", shape: "dot", text: `${events.length} detections${result.hasMore ? "; more available" : ""}` });
296
- send(output);
301
+ sendWithPayload(send, output, node.emitStartupAndUndefined);
297
302
  return;
298
303
  }
299
304
 
@@ -688,7 +693,7 @@ module.exports = function(RED) {
688
693
  decorateOutputMessage(output, node.currentDevice, "detectionWithImage");
689
694
  attachDetails(output, { raw: event, unifiProtect: buildBaseMetadata(node.deviceType, node.deviceId, node.capability, { source: "events" }) });
690
695
  state.sent = true;
691
- node.send(output);
696
+ sendWithPayload(node.send.bind(node), output, node.emitStartupAndUndefined);
692
697
  setNodeStatus({ fill: "blue", shape: "dot", text: "event photo received" });
693
698
  }).catch((error) => {
694
699
  if (!node.isObserving) return;
@@ -726,6 +731,7 @@ module.exports = function(RED) {
726
731
  // state output directly instead of only the event payload.
727
732
  const observation = resolveObservableEventValue(node.deviceType, item, observable, observableScopeId);
728
733
  if (observation.matched) {
734
+ if (!node.emitStartupAndUndefined && !hasPayloadValue(observation.value)) return;
729
735
  const resolvedDeviceName = resolveOutputDeviceName(node.currentDevice);
730
736
  node.currentObservableValue = observation.value;
731
737
  setNodeStatus({ fill: "blue", shape: "ring", text: `${item.type || "event"}` });
@@ -776,9 +782,9 @@ module.exports = function(RED) {
776
782
  return;
777
783
  }
778
784
 
779
- if (observation.eventTypeMatched) {
780
- return;
781
- }
785
+ // No value for the selected observable: do not emit a raw
786
+ // event as an alternative downstream command.
787
+ return;
782
788
  }
783
789
 
784
790
  setNodeStatus({ fill: "blue", shape: "ring", text: `${item.type || "event"}` });
@@ -131,6 +131,24 @@ function attachDetails(outputMsg, details) {
131
131
  };
132
132
  }
133
133
 
134
+ // Missing readings must never become downstream commands. Keep false and zero.
135
+ function hasPayloadValue(value) {
136
+ return value !== undefined && value !== null
137
+ && !(typeof value === "string" && value.trim().toLowerCase() === "undefined");
138
+ }
139
+
140
+ function sendWithPayload(send, messages, allowMissing = false) {
141
+ function filter(message) {
142
+ if (Array.isArray(message)) {
143
+ const filtered = message.map(filter);
144
+ return filtered.some((item) => item !== null) ? filtered : null;
145
+ }
146
+ return message && (allowMissing || hasPayloadValue(message.payload)) ? message : null;
147
+ }
148
+ const filtered = filter(messages);
149
+ if (filtered !== null) send(filtered);
150
+ }
151
+
134
152
  function buildErrorOutputMessage(error, nodeName) {
135
153
  return {
136
154
  topic: String(nodeName || "").trim() || undefined,
@@ -153,5 +171,7 @@ module.exports = {
153
171
  extractDeviceNameFromPayload,
154
172
  attachDeviceNameToPayload,
155
173
  attachDetails,
156
- buildErrorOutputMessage
174
+ buildErrorOutputMessage,
175
+ hasPayloadValue,
176
+ sendWithPayload
157
177
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-unifi-ultimate",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "Node-RED nodes for Ubiquiti UniFi integrations, including UniFi Protect, UniFi Access, and UniFi Network.",
5
5
  "files": [
6
6
  "nodes/",
@@ -82,4 +82,4 @@
82
82
  "bugs": {
83
83
  "url": "https://github.com/Supergiovane/node-red-contrib-unifi-ultimate/issues"
84
84
  }
85
- }
85
+ }