node-red-contrib-unifi-ultimate 1.0.2 → 1.0.4
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 +62 -239
- package/nodes/unifi-access-config.html +18 -0
- package/nodes/unifi-access-config.js +3 -1
- package/nodes/unifi-access-device.html +34 -12
- package/nodes/unifi-access-device.js +14 -76
- package/nodes/unifi-network-config.html +18 -0
- package/nodes/unifi-network-config.js +11 -5
- package/nodes/unifi-network-control-poe.html +38 -15
- package/nodes/unifi-network-control-poe.js +11 -67
- package/nodes/unifi-network-device.html +34 -12
- package/nodes/unifi-network-device.js +14 -79
- package/nodes/unifi-network-presence.html +38 -14
- package/nodes/unifi-network-presence.js +16 -54
- package/nodes/unifi-protect-config.html +18 -0
- package/nodes/unifi-protect-config.js +3 -1
- package/nodes/unifi-protect-device.html +34 -12
- package/nodes/unifi-protect-device.js +14 -76
- package/nodes/utils/common-utils.js +157 -0
- package/nodes/utils/unifi-access-utils.js +11 -4
- package/nodes/utils/unifi-network-utils.js +5 -2
- package/nodes/utils/unifi-protect-utils.js +5 -2
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
# node-red-contrib-unifi-ultimate
|
|
15
15
|
|
|
16
|
-
Control and monitor
|
|
16
|
+
Control and monitor your **UniFi Network**, **UniFi Protect**, and **UniFi Access** devices directly from Node-RED — no technical knowledge required.
|
|
17
17
|
|
|
18
18
|
[View Changelog](CHANGELOG.md)
|
|
19
19
|
|
|
@@ -41,16 +41,18 @@ In Node-RED:
|
|
|
41
41
|
|
|
42
42
|
## Quick Start
|
|
43
43
|
|
|
44
|
-
1. Add
|
|
45
|
-
2. Enter
|
|
46
|
-
3. Add the matching
|
|
47
|
-
4. Select the
|
|
44
|
+
1. Add a config node for your UniFi product: **Unifi Network Config**, **Unifi Protect Config**, or **Unifi Access Config**.
|
|
45
|
+
2. Enter your UniFi controller address and login credentials.
|
|
46
|
+
3. Add the matching node to your flow.
|
|
47
|
+
4. Select the device you want to control or monitor.
|
|
48
48
|
5. Select the action.
|
|
49
|
-
6. Deploy
|
|
50
|
-
7. Send any message into the node to run the
|
|
49
|
+
6. Click **Deploy**.
|
|
50
|
+
7. Send any message into the node to run the action.
|
|
51
51
|
|
|
52
|
-
For most actions, the incoming message is
|
|
53
|
-
|
|
52
|
+
> **Tip:** For most actions, the incoming message is just a trigger — the node uses the device and action you configured in the editor.
|
|
53
|
+
> The only exception is **Control POE** with the *POE controlled by incoming message* action: send `true` to turn PoE on and `false` to turn it off.
|
|
54
|
+
|
|
55
|
+
> **Custom port:** Each config node has an optional **Port** field. Leave it empty to use the default (`443` for Network/Protect, `12445` for Access). Set it when your controller listens on a custom port — for example a **UniFi OS server** that uses `11443`. A port written directly in the controller address (`host:port`) takes precedence over this field.
|
|
54
56
|
|
|
55
57
|
<br/>
|
|
56
58
|
<br/>
|
|
@@ -60,33 +62,24 @@ Exception: in `Unifi Network Control POE`, action `POE controlled by msg.payload
|
|
|
60
62
|
</a>
|
|
61
63
|
</p>
|
|
62
64
|
|
|
63
|
-
Use Network nodes to work with:
|
|
65
|
+
Use **Network** nodes to work with:
|
|
64
66
|
|
|
65
67
|
- sites
|
|
66
68
|
- UniFi devices such as switches and access points
|
|
67
|
-
- clients such as phones, computers, and IoT devices
|
|
68
|
-
- switch ports
|
|
69
|
-
-
|
|
70
|
-
- client presence
|
|
71
|
-
|
|
72
|
-
Common uses:
|
|
73
|
-
|
|
74
|
-
- Check whether a client is online.
|
|
75
|
-
- Count online clients for a site.
|
|
76
|
-
- Create simple guest vouchers.
|
|
77
|
-
- Read CPU, memory, and uptime from UniFi devices.
|
|
78
|
-
- Read Temperatures when the selected UniFi device exposes thermal sensor data.
|
|
79
|
-
- Restart a UniFi device.
|
|
80
|
-
- Power-cycle a PoE port.
|
|
81
|
-
- Turn PoE on or off for a selected switch port.
|
|
82
|
-
- Select a client and let the PoE node find the connected switch and port when the information is available.
|
|
69
|
+
- connected clients such as phones, computers, and IoT devices
|
|
70
|
+
- switch ports and PoE control
|
|
71
|
+
- client presence detection
|
|
83
72
|
|
|
84
|
-
|
|
73
|
+
Things you can do:
|
|
85
74
|
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
-
|
|
75
|
+
- Check whether a device or phone is connected to your network.
|
|
76
|
+
- Count how many clients are currently online.
|
|
77
|
+
- Create guest Wi-Fi vouchers.
|
|
78
|
+
- Read CPU usage, memory, and uptime from a switch or access point.
|
|
79
|
+
- Read the temperature of a switch (where supported).
|
|
80
|
+
- Restart a UniFi device.
|
|
81
|
+
- Power-cycle or turn on/off a PoE port.
|
|
82
|
+
- Let the PoE node automatically find which port a client is connected to.
|
|
90
83
|
|
|
91
84
|
<br/>
|
|
92
85
|
<br/>
|
|
@@ -96,27 +89,23 @@ Editor conveniences:
|
|
|
96
89
|
</a>
|
|
97
90
|
</p>
|
|
98
91
|
|
|
99
|
-
Use Protect nodes to work with:
|
|
92
|
+
Use **Protect** nodes to work with:
|
|
100
93
|
|
|
101
94
|
- cameras
|
|
102
|
-
- sensors
|
|
95
|
+
- sensors (motion, contact, temperature, humidity, leak)
|
|
103
96
|
- lights
|
|
104
97
|
- chimes
|
|
105
98
|
- viewers
|
|
106
|
-
-
|
|
107
|
-
- NVR information
|
|
99
|
+
- NVR
|
|
108
100
|
|
|
109
|
-
|
|
101
|
+
Things you can do:
|
|
110
102
|
|
|
111
|
-
- Receive motion, ring, contact, tamper, leak, and battery
|
|
103
|
+
- Receive motion, ring, contact, tamper, leak, and low-battery alerts.
|
|
112
104
|
- Read the current state of a camera or sensor.
|
|
113
|
-
- Take camera
|
|
114
|
-
- Control PTZ cameras.
|
|
115
|
-
-
|
|
116
|
-
- Switch viewer live
|
|
117
|
-
- Update supported device properties.
|
|
118
|
-
|
|
119
|
-
For supported observables, the node can output normalized values while still keeping the raw UniFi event details available (`true/false` for event states, numeric values for sensor metrics like temperature and humidity).
|
|
105
|
+
- Take a camera snapshot.
|
|
106
|
+
- Control PTZ cameras (move to preset, start/stop patrol).
|
|
107
|
+
- Display a custom message on a doorbell screen.
|
|
108
|
+
- Switch a viewer to a different live feed.
|
|
120
109
|
|
|
121
110
|
<br/>
|
|
122
111
|
<br/>
|
|
@@ -126,218 +115,52 @@ For supported observables, the node can output normalized values while still kee
|
|
|
126
115
|
</a>
|
|
127
116
|
</p>
|
|
128
117
|
|
|
129
|
-
Use Access nodes to work with:
|
|
118
|
+
Use **Access** nodes to work with:
|
|
130
119
|
|
|
131
120
|
- doors
|
|
132
|
-
- Access devices
|
|
133
|
-
- door events
|
|
134
|
-
- lock rules
|
|
135
|
-
- emergency mode
|
|
121
|
+
- Access devices (hubs, intercoms)
|
|
122
|
+
- door events (unlock, ring, DPS, emergency)
|
|
123
|
+
- lock rules and schedules
|
|
136
124
|
- doorbell actions
|
|
137
125
|
|
|
138
|
-
|
|
126
|
+
Things you can do:
|
|
139
127
|
|
|
140
|
-
- Unlock a door.
|
|
141
|
-
-
|
|
128
|
+
- Unlock a door remotely.
|
|
129
|
+
- Set a temporary unlock window with a custom duration.
|
|
142
130
|
- Enable lockdown or evacuation mode.
|
|
143
|
-
- Receive
|
|
144
|
-
- Trigger or cancel an intercom doorbell
|
|
131
|
+
- Receive door events in real time.
|
|
132
|
+
- Trigger or cancel an intercom doorbell.
|
|
145
133
|
|
|
146
134
|
## Outputs
|
|
147
135
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
- `msg.details.unifiNetwork`
|
|
159
|
-
- `msg.details.unifiNetworkPresence`
|
|
160
|
-
- `msg.details.unifiNetworkPoe`
|
|
161
|
-
- `msg.details.unifiProtect`
|
|
162
|
-
- `msg.details.unifiAccess`
|
|
163
|
-
|
|
164
|
-
When `msg.payload` is an object, it also includes `payload.deviceName` with the same value.
|
|
165
|
-
|
|
166
|
-
## Output Examples
|
|
167
|
-
|
|
168
|
-
### Unifi Network Device
|
|
169
|
-
|
|
170
|
-
```json
|
|
171
|
-
{
|
|
172
|
-
"topic": "Switch Soffitta",
|
|
173
|
-
"deviceName": "Soffitta",
|
|
174
|
-
"eventName": "request:readState",
|
|
175
|
-
"payload": {
|
|
176
|
-
"id": "8c072de0-d71d-37bd-a6f5-eac67c95a314",
|
|
177
|
-
"name": "Soffitta",
|
|
178
|
-
"state": "READY",
|
|
179
|
-
"deviceName": "Soffitta"
|
|
180
|
-
},
|
|
181
|
-
"details": {
|
|
182
|
-
"unifiNetwork": {
|
|
183
|
-
"nodeType": "device",
|
|
184
|
-
"deviceType": "device",
|
|
185
|
-
"capability": "readState",
|
|
186
|
-
"source": "request"
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
`Unifi Network Device` action `Read Temperatures` returns:
|
|
193
|
-
|
|
194
|
-
| Field | Type | Guaranteed | Notes |
|
|
195
|
-
| ---------------------------------- | ------ | ---------- | ----------------------------------------------------------- |
|
|
196
|
-
| `msg.payload` | number | no | First normalized temperature reading in Celsius. |
|
|
197
|
-
| `msg.details.temperature` | object | yes | Full normalized temperature details and all readings found. |
|
|
198
|
-
| `msg.details.temperatureSources[]` | array | yes | Sources used, for example `official` and/or `legacy`. |
|
|
199
|
-
|
|
200
|
-
Some switch models and controller versions do not expose temperature data; in that case the action emits `msg.payload = null` and details include `hasTemperatures: false`.
|
|
201
|
-
|
|
202
|
-
Other simple `Unifi Network Device` actions return compact payloads:
|
|
203
|
-
|
|
204
|
-
| Action | `msg.payload` | Details |
|
|
205
|
-
| ---------------------- | ------------------------------- | ----------------------------- |
|
|
206
|
-
| `Is Client Online` | `true` or `false` | `msg.details.client` |
|
|
207
|
-
| `Count Online Clients` | online client count | `msg.details.onlineClients[]` |
|
|
208
|
-
| `Read CPU` | CPU percentage | `msg.details.statistics` |
|
|
209
|
-
| `Read Memory` | memory percentage | `msg.details.statistics` |
|
|
210
|
-
| `Read Uptime` | uptime in seconds | `msg.details.statistics` |
|
|
211
|
-
| `Create Guest Voucher` | one voucher code, or code array | `msg.details.vouchers[]` |
|
|
212
|
-
|
|
213
|
-
For read-only actions on Network, Protect, and Access device nodes, enable `Emit periodically` to send the configured result at a fixed interval without using an Inject node. This option is hidden for event streams and write actions.
|
|
214
|
-
|
|
215
|
-
Request timeouts are handled internally. Existing nodes do not need timeout settings, and Network PoE power polling uses a 15 second default when the shared config value is left empty.
|
|
216
|
-
|
|
217
|
-
### Unifi Network Presence
|
|
218
|
-
|
|
219
|
-
```json
|
|
220
|
-
{
|
|
221
|
-
"topic": "iPhone Massimo Presence",
|
|
222
|
-
"deviceName": "iPhone-Massimo",
|
|
223
|
-
"eventName": "connected",
|
|
224
|
-
"payload": true,
|
|
225
|
-
"present": true,
|
|
226
|
-
"details": {
|
|
227
|
-
"unifiNetworkPresence": {
|
|
228
|
-
"nodeType": "presence",
|
|
229
|
-
"source": "poll",
|
|
230
|
-
"reason": "connected"
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Unifi Network Control POE
|
|
237
|
-
|
|
238
|
-
```json
|
|
239
|
-
{
|
|
240
|
-
"topic": "POE Soffitta Port 2",
|
|
241
|
-
"deviceName": "Soffitta",
|
|
242
|
-
"eventName": "request:enable",
|
|
243
|
-
"payload": {
|
|
244
|
-
"status": "ok",
|
|
245
|
-
"deviceName": "Soffitta",
|
|
246
|
-
"portIdx": 2,
|
|
247
|
-
"portName": "Port 2",
|
|
248
|
-
"portPowerW": 2.6,
|
|
249
|
-
"powerConsumptionSwitchTotal": 36.4
|
|
250
|
-
},
|
|
251
|
-
"details": {
|
|
252
|
-
"unifiNetworkPoe": {
|
|
253
|
-
"nodeType": "poe-control",
|
|
254
|
-
"action": "enable",
|
|
255
|
-
"portIdx": 2,
|
|
256
|
-
"portPowerW": 2.6,
|
|
257
|
-
"powerConsumptionSwitchTotal": 36.4
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
Power fields for `Unifi Network Control POE`:
|
|
264
|
-
|
|
265
|
-
| Field | Type | Guaranteed | Notes |
|
|
266
|
-
| --------------------------------------------------------- | ------ | ---------- | ------------------------------------------------------------------------ |
|
|
267
|
-
| `msg.payload.portIdx` | number | yes | Selected port index. |
|
|
268
|
-
| `msg.payload.portName` | string | yes | Selected port display name. |
|
|
269
|
-
| `msg.payload.portPowerW` | number | no | Current PoE power draw for the selected port (W), when UniFi exposes it. |
|
|
270
|
-
| `msg.payload.powerConsumptionSwitchTotal` | number | no | Sum of all port PoE consumptions on the switch (W), when available. |
|
|
271
|
-
| `msg.details.unifiNetworkPoe.portPowerW` | number | no | Same value as `msg.payload.portPowerW`. |
|
|
272
|
-
| `msg.details.unifiNetworkPoe.powerConsumptionSwitchTotal` | number | no | Same value as `msg.payload.powerConsumptionSwitchTotal`. |
|
|
273
|
-
|
|
274
|
-
### Unifi Protect Device
|
|
275
|
-
|
|
276
|
-
```json
|
|
277
|
-
{
|
|
278
|
-
"topic": "Front Door Camera",
|
|
279
|
-
"deviceName": "Front Door Camera",
|
|
280
|
-
"eventName": "smartDetectZone",
|
|
281
|
-
"payload": {
|
|
282
|
-
"device": {
|
|
283
|
-
"id": "camera-id"
|
|
284
|
-
},
|
|
285
|
-
"event": {
|
|
286
|
-
"type": "smartDetectZone"
|
|
287
|
-
},
|
|
288
|
-
"deviceName": "Front Door Camera"
|
|
289
|
-
},
|
|
290
|
-
"details": {
|
|
291
|
-
"unifiProtect": {
|
|
292
|
-
"nodeType": "device",
|
|
293
|
-
"deviceType": "camera",
|
|
294
|
-
"capability": "observe",
|
|
295
|
-
"source": "events"
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
### Unifi Access Device
|
|
302
|
-
|
|
303
|
-
```json
|
|
304
|
-
{
|
|
305
|
-
"topic": "Main Door",
|
|
306
|
-
"deviceName": "Main Door",
|
|
307
|
-
"eventName": "door.unlock",
|
|
308
|
-
"payload": {
|
|
309
|
-
"event": "door.unlock",
|
|
310
|
-
"deviceName": "Main Door"
|
|
311
|
-
},
|
|
312
|
-
"details": {
|
|
313
|
-
"unifiAccess": {
|
|
314
|
-
"nodeType": "device",
|
|
315
|
-
"deviceType": "door",
|
|
316
|
-
"capability": "observe",
|
|
317
|
-
"source": "events"
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
```
|
|
136
|
+
Every node has **two outputs**:
|
|
137
|
+
|
|
138
|
+
| Output | When it fires |
|
|
139
|
+
| ------ | ------------- |
|
|
140
|
+
| **1 — result** | The action completed successfully. The result is available in `msg.payload`. |
|
|
141
|
+
| **2 — error** | Something went wrong (connection problem, timeout, unsupported action). |
|
|
142
|
+
|
|
143
|
+
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.
|
|
144
|
+
|
|
145
|
+
**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.
|
|
322
146
|
|
|
323
147
|
## Example Flows
|
|
324
148
|
|
|
325
149
|
Import from `examples/`:
|
|
326
150
|
|
|
327
|
-
| Flow file
|
|
328
|
-
|
|
|
329
|
-
| [examples/unifi-protect-info.json](examples/unifi-protect-info.json)
|
|
330
|
-
| [examples/unifi-protect-sensor-observe.json](examples/unifi-protect-sensor-observe.json)
|
|
331
|
-
| [examples/unifi-protect-camera-actions.json](examples/unifi-protect-camera-actions.json)
|
|
332
|
-
| [examples/unifi-access-door-control.json](examples/unifi-access-door-control.json)
|
|
333
|
-
| [examples/unifi-access-intercom-doorbell.json](examples/unifi-access-intercom-doorbell.json) | Intercom
|
|
151
|
+
| Flow file | What it demonstrates |
|
|
152
|
+
| --------- | -------------------- |
|
|
153
|
+
| [examples/unifi-protect-info.json](examples/unifi-protect-info.json) | Read the state of a Protect camera |
|
|
154
|
+
| [examples/unifi-protect-sensor-observe.json](examples/unifi-protect-sensor-observe.json) | Receive sensor events (motion, temperature, humidity, …) |
|
|
155
|
+
| [examples/unifi-protect-camera-actions.json](examples/unifi-protect-camera-actions.json) | Take snapshots, move PTZ, show doorbell messages |
|
|
156
|
+
| [examples/unifi-access-door-control.json](examples/unifi-access-door-control.json) | Door state, remote unlock, temporary lock rule |
|
|
157
|
+
| [examples/unifi-access-intercom-doorbell.json](examples/unifi-access-intercom-doorbell.json) | Intercom — receive ring, trigger and cancel doorbell |
|
|
334
158
|
|
|
335
159
|
## Notes
|
|
336
160
|
|
|
337
|
-
- You need valid
|
|
338
|
-
- Some actions
|
|
339
|
-
- UniFi
|
|
340
|
-
- For safety, actions exposed by the nodes are intentionally limited to known supported operations.
|
|
161
|
+
- You need valid login credentials for the UniFi application you want to use.
|
|
162
|
+
- Some actions are only available on specific device models.
|
|
163
|
+
- UniFi behavior can vary between application versions.
|
|
341
164
|
|
|
342
165
|
[npm-version-image]: https://img.shields.io/npm/v/node-red-contrib-unifi-ultimate.svg
|
|
343
166
|
[npm-url]: https://www.npmjs.com/package/node-red-contrib-unifi-ultimate
|
|
@@ -6,6 +6,16 @@
|
|
|
6
6
|
defaults: {
|
|
7
7
|
name: { value: "Unifi Access Config" },
|
|
8
8
|
host: { value: "", required: true },
|
|
9
|
+
port: {
|
|
10
|
+
value: "",
|
|
11
|
+
required: false,
|
|
12
|
+
validate: function (value) {
|
|
13
|
+
if (value === undefined || value === null || value === "") {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return /^\d+$/.test(String(value)) && Number(value) >= 1 && Number(value) <= 65535;
|
|
17
|
+
}
|
|
18
|
+
},
|
|
9
19
|
rejectUnauthorized: { value: false }
|
|
10
20
|
},
|
|
11
21
|
credentials: {
|
|
@@ -17,14 +27,17 @@
|
|
|
17
27
|
oneditprepare: function () {
|
|
18
28
|
const node = this;
|
|
19
29
|
const $hostInput = $("#node-config-input-host");
|
|
30
|
+
const $port = $("#node-config-input-port");
|
|
20
31
|
const $apiToken = $("#node-config-input-apiToken");
|
|
21
32
|
const $rejectUnauthorized = $("#node-config-input-rejectUnauthorized");
|
|
33
|
+
const $portRow = $port.closest(".form-row");
|
|
22
34
|
const $apiTokenRow = $apiToken.closest(".form-row");
|
|
23
35
|
const $securityRow = $rejectUnauthorized.closest(".form-row");
|
|
24
36
|
const $advancedRow = $("#node-config-row-advanced");
|
|
25
37
|
|
|
26
38
|
function syncProgressiveRows() {
|
|
27
39
|
const hasHost = String($hostInput.val() || node.host || "").trim() !== "";
|
|
40
|
+
$portRow.toggle(hasHost);
|
|
28
41
|
$apiTokenRow.toggle(hasHost);
|
|
29
42
|
$securityRow.toggle(hasHost);
|
|
30
43
|
$advancedRow.toggle(hasHost);
|
|
@@ -60,6 +73,10 @@
|
|
|
60
73
|
<label for="node-config-input-host"><i class="fa fa-globe"></i> Controller</label>
|
|
61
74
|
<input type="text" id="node-config-input-host" placeholder="192.168.1.10 or access.local:12445">
|
|
62
75
|
</div>
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-config-input-port"><i class="fa fa-plug"></i> Port</label>
|
|
78
|
+
<input type="text" id="node-config-input-port" placeholder="12445 (default)">
|
|
79
|
+
</div>
|
|
63
80
|
<div class="form-row">
|
|
64
81
|
<label for="node-config-input-apiToken"><i class="fa fa-key"></i> API Token</label>
|
|
65
82
|
<input type="password" id="node-config-input-apiToken" placeholder="Paste your UniFi Access token">
|
|
@@ -84,6 +101,7 @@
|
|
|
84
101
|
|
|
85
102
|
<h3>Configuration</h3>
|
|
86
103
|
<p><b>Controller</b> accepts the UniFi Access host or <code>host:port</code>. If you omit the port, the node uses the default UniFi Access port automatically.</p>
|
|
104
|
+
<p><b>Port</b> is optional. Leave it empty to use the default <code>12445</code>. Set it when your UniFi Access controller listens on a custom port. A port embedded directly in the Controller field (<code>host:port</code>) takes precedence over this field.</p>
|
|
87
105
|
<p><b>API Token</b> is the bearer token used for authentication.</p>
|
|
88
106
|
<p><b>Security</b> controls certificate verification. Disable it only when your controller uses a self-signed certificate.</p>
|
|
89
107
|
<p><b>Name</b> is the config node name shown in the editor.</p>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
4
|
buildBaseUrlFromHost,
|
|
5
|
+
normalizePort,
|
|
5
6
|
buildQueryString,
|
|
6
7
|
doRequest,
|
|
7
8
|
buildRequestHeaders,
|
|
@@ -67,7 +68,8 @@ module.exports = function(RED) {
|
|
|
67
68
|
const node = this;
|
|
68
69
|
node.name = config.name;
|
|
69
70
|
node.host = String(config.host || "").trim();
|
|
70
|
-
node.
|
|
71
|
+
node.port = normalizePort(config.port);
|
|
72
|
+
node.baseUrl = buildBaseUrlFromHost(node.host, node.port);
|
|
71
73
|
node.rejectUnauthorized = config.rejectUnauthorized !== false && config.rejectUnauthorized !== "false";
|
|
72
74
|
node.nodeClients = [];
|
|
73
75
|
node.wsNotifications = null;
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
autoEmitInterval: { value: 60, validate: RED.validators.number() }
|
|
19
19
|
},
|
|
20
20
|
inputs: 1,
|
|
21
|
-
outputs:
|
|
21
|
+
outputs: 2,
|
|
22
22
|
icon: "unifi-u-logo-light-access.svg",
|
|
23
23
|
paletteLabel: "ACCESS",
|
|
24
|
-
outputLabels: ["result"],
|
|
24
|
+
outputLabels: ["result", "error"],
|
|
25
25
|
label: function () {
|
|
26
26
|
return this.name || this.deviceId || "Unifi Access";
|
|
27
27
|
},
|
|
@@ -1152,16 +1152,32 @@
|
|
|
1152
1152
|
<li>Input message properties are ignored by this node.</li>
|
|
1153
1153
|
</ul>
|
|
1154
1154
|
|
|
1155
|
-
<h3>
|
|
1156
|
-
<
|
|
1157
|
-
<
|
|
1158
|
-
<
|
|
1159
|
-
<
|
|
1160
|
-
<
|
|
1161
|
-
<
|
|
1162
|
-
<
|
|
1163
|
-
|
|
1164
|
-
|
|
1155
|
+
<h3>Outputs</h3>
|
|
1156
|
+
<dl class="message-properties">
|
|
1157
|
+
<dt>Output 1 — result</dt>
|
|
1158
|
+
<dd>Emits state and live event messages for the selected door or Access device. When <code>Receive Events</code> is active, both state and event messages use this pin.</dd>
|
|
1159
|
+
<dt class="optional">msg.topic</dt>
|
|
1160
|
+
<dd>Node name from the editor.</dd>
|
|
1161
|
+
<dt class="optional">msg.deviceName</dt>
|
|
1162
|
+
<dd>Remembered/observed name of the selected device.</dd>
|
|
1163
|
+
<dt class="optional">msg.eventName</dt>
|
|
1164
|
+
<dd>Trigger or event that produced the message.</dd>
|
|
1165
|
+
<dt class="optional">msg.details.unifiAccess</dt>
|
|
1166
|
+
<dd>Standardized metadata for the device and selected capability.</dd>
|
|
1167
|
+
<dt class="optional">msg.payload.skipped</dt>
|
|
1168
|
+
<dd><code>true</code> when <code>Cancel Doorbell</code> is blocked because no active ring is currently tracked.</dd>
|
|
1169
|
+
</dl>
|
|
1170
|
+
<dl class="message-properties">
|
|
1171
|
+
<dt>Output 2 — error</dt>
|
|
1172
|
+
<dd>Emitted when the action fails (API error, timeout, or configuration problem). The node status also turns red. Errors are additionally forwarded to any connected <code>catch</code> node.</dd>
|
|
1173
|
+
<dt class="optional">msg.payload</dt>
|
|
1174
|
+
<dd><code>null</code></dd>
|
|
1175
|
+
<dt class="optional">msg.topic</dt>
|
|
1176
|
+
<dd>Node name from the editor.</dd>
|
|
1177
|
+
<dt class="optional">msg.error.message</dt>
|
|
1178
|
+
<dd>Human-readable error description.</dd>
|
|
1179
|
+
</dl>
|
|
1180
|
+
<p>Example output (pin 1):</p>
|
|
1165
1181
|
<pre><code>{
|
|
1166
1182
|
"topic": "Main Door",
|
|
1167
1183
|
"deviceName": "Main Door",
|
|
@@ -1178,5 +1194,11 @@
|
|
|
1178
1194
|
"source": "events"
|
|
1179
1195
|
}
|
|
1180
1196
|
}
|
|
1197
|
+
}</code></pre>
|
|
1198
|
+
<p>Example output (pin 2 — error):</p>
|
|
1199
|
+
<pre><code>{
|
|
1200
|
+
"topic": "Main Door",
|
|
1201
|
+
"payload": null,
|
|
1202
|
+
"error": { "message": "Request timed out" }
|
|
1181
1203
|
}</code></pre>
|
|
1182
1204
|
</script>
|
|
@@ -9,6 +9,18 @@ const {
|
|
|
9
9
|
matchesObservable
|
|
10
10
|
} = require("./utils/unifi-access-device-registry");
|
|
11
11
|
const { extractAccessData } = require("./utils/unifi-access-utils");
|
|
12
|
+
const {
|
|
13
|
+
parseBoolean,
|
|
14
|
+
parseIntervalSeconds,
|
|
15
|
+
buildStatusTimestampText,
|
|
16
|
+
appendStatusTimestamp,
|
|
17
|
+
resolveNodeName,
|
|
18
|
+
resolveDeviceName,
|
|
19
|
+
extractDeviceNameFromPayload,
|
|
20
|
+
attachDeviceNameToPayload,
|
|
21
|
+
attachDetails,
|
|
22
|
+
buildErrorOutputMessage
|
|
23
|
+
} = require("./utils/common-utils");
|
|
12
24
|
const DEFAULT_REQUEST_TIMEOUT_MS = 15000;
|
|
13
25
|
|
|
14
26
|
function resolveDeviceType(configuredDeviceType) {
|
|
@@ -46,18 +58,6 @@ function resolveCapabilityConfig(configuredCapabilityConfig) {
|
|
|
46
58
|
return parseCapabilityConfig(configuredCapabilityConfig);
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
function parseBoolean(value) {
|
|
50
|
-
return value === true || value === "true" || value === 1 || value === "1";
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function parseIntervalSeconds(value, fallback) {
|
|
54
|
-
const numeric = Number(value);
|
|
55
|
-
if (!Number.isFinite(numeric) || numeric < 5) {
|
|
56
|
-
return fallback;
|
|
57
|
-
}
|
|
58
|
-
return Math.trunc(numeric);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
61
|
function buildNodeStatus(deviceType, payload) {
|
|
62
62
|
const normalizedType = String(deviceType || "").trim();
|
|
63
63
|
const item = payload && typeof payload === "object" ? payload : {};
|
|
@@ -77,70 +77,6 @@ function requiresDeviceSpecificCapabilityValidation(deviceType, capabilityId) {
|
|
|
77
77
|
return String(deviceType || "").trim() === "device" && ["triggerDoorbell", "cancelDoorbell"].includes(String(capabilityId || "").trim());
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function resolveNodeName(value) {
|
|
81
|
-
return String(value || "").trim();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function resolveDeviceName(value) {
|
|
85
|
-
return String(value || "").trim();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function extractDeviceNameFromPayload(payload) {
|
|
89
|
-
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
|
|
90
|
-
return "";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return resolveDeviceName(
|
|
94
|
-
payload.name
|
|
95
|
-
|| payload.displayName
|
|
96
|
-
|| payload.alias
|
|
97
|
-
|| payload.full_name
|
|
98
|
-
|| payload.id
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function attachDeviceNameToPayload(payload, deviceName) {
|
|
103
|
-
if (!deviceName) {
|
|
104
|
-
return payload;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (payload && typeof payload === "object" && !Array.isArray(payload)) {
|
|
108
|
-
return {
|
|
109
|
-
...payload,
|
|
110
|
-
deviceName
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return payload;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function attachDetails(outputMsg, details) {
|
|
118
|
-
if (!details || typeof details !== "object" || Array.isArray(details)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const currentDetails = outputMsg.details && typeof outputMsg.details === "object" && !Array.isArray(outputMsg.details)
|
|
123
|
-
? outputMsg.details
|
|
124
|
-
: {};
|
|
125
|
-
|
|
126
|
-
outputMsg.details = {
|
|
127
|
-
...currentDetails,
|
|
128
|
-
...details
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function buildStatusTimestampText() {
|
|
133
|
-
const now = new Date();
|
|
134
|
-
const time = now.toTimeString().split(" ")[0];
|
|
135
|
-
return `(day ${now.getDate()}, ${time})`;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function appendStatusTimestamp(text) {
|
|
139
|
-
const normalized = String(text === undefined || text === null ? "" : text).trim();
|
|
140
|
-
const suffix = buildStatusTimestampText();
|
|
141
|
-
return normalized ? `${normalized} ${suffix}` : suffix;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
80
|
function resolveConfiguredObservable(capabilityConfig) {
|
|
145
81
|
return String(
|
|
146
82
|
capabilityConfig && capabilityConfig.observable !== undefined
|
|
@@ -470,6 +406,7 @@ module.exports = function(RED) {
|
|
|
470
406
|
invokeCapability(node.send.bind(node), "interval")
|
|
471
407
|
.catch((error) => {
|
|
472
408
|
setNodeStatus({ fill: "red", shape: "ring", text: "auto error" });
|
|
409
|
+
node.send([null, buildErrorOutputMessage(error, node.name)]);
|
|
473
410
|
node.error(error);
|
|
474
411
|
})
|
|
475
412
|
.finally(() => {
|
|
@@ -499,6 +436,7 @@ module.exports = function(RED) {
|
|
|
499
436
|
}
|
|
500
437
|
} catch (error) {
|
|
501
438
|
setNodeStatus({ fill: "red", shape: "ring", text: "error" });
|
|
439
|
+
node.send([null, buildErrorOutputMessage(error, node.name)]);
|
|
502
440
|
if (typeof done === "function") {
|
|
503
441
|
done(error);
|
|
504
442
|
} else {
|