homebridge-dahua-vto 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # homebridge-dahua-vto
2
+
3
+ Homebridge plugin for **Dahua VTO** door stations (tested with VTO2111D):
4
+
5
+ - Live camera (H.264 via ffmpeg)
6
+ - Doorbell button events
7
+ - Motion
8
+ - Door lock / unlock (`accessControl.cgi`)
9
+ - **Two-way audio** — same path as Scrypted Amcrest (`audio.cgi` G.711A, 1024-byte chunks @ 8 kHz)
10
+ - Optional **HomeKit Secure Video** (HKSV)
11
+
12
+ ## Requirements
13
+
14
+ - [Homebridge](https://homebridge.io/) `^1.8` (or v2 beta)
15
+ - **ffmpeg with `libfdk_aac`** for talkback (AAC-ELD). Recommended: [ffmpeg-for-homebridge](https://github.com/homebridge/ffmpeg-for-homebridge)
16
+ - Network access from the Homebridge host to the VTO (HTTP CGI + RTSP)
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ hb-service add homebridge-dahua-vto
22
+ # or
23
+ npm install -g homebridge-dahua-vto
24
+ ```
25
+
26
+ Then restart Homebridge and add the platform in the UI, or edit `config.json`.
27
+
28
+ ## Config example
29
+
30
+ ```json
31
+ {
32
+ "platforms": [
33
+ {
34
+ "platform": "DahuaVTO",
35
+ "name": "Dahua VTO",
36
+ "cameras": [
37
+ {
38
+ "name": "Front Door",
39
+ "host": "192.168.80.8",
40
+ "username": "admin",
41
+ "password": "YOUR_PASSWORD",
42
+ "doorChannel": 1,
43
+ "unlockSeconds": 5,
44
+ "twoWayAudio": true,
45
+ "hksv": true,
46
+ "ffmpegPath": "/usr/local/bin/ffmpeg"
47
+ }
48
+ ]
49
+ }
50
+ ]
51
+ }
52
+ ```
53
+
54
+ ### Optional fields
55
+
56
+ | Field | Default | Notes |
57
+ |---|---|---|
58
+ | `rtspUrl` | auto | Full RTSP URL override |
59
+ | `rtspSubtype` | `0` | Main/sub stream if `rtspUrl` not set |
60
+ | `ssl` | `false` | HTTPS for CGI |
61
+ | `ffmpegPath` | `ffmpeg` | Path to ffmpeg-for-homebridge binary |
62
+ | `twoWayAudio` | `true` | Mic in Home → VTO speaker |
63
+ | `hksv` | `true` | Secure Video recording |
64
+ | `motionTimeoutMs` | `10000` | Auto-clear motion |
65
+
66
+ ## Two-way audio
67
+
68
+ Uses the Dahua/Amcrest CGI (same as Scrypted **Doorbell Type = Dahua**):
69
+
70
+ ```text
71
+ POST /cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1
72
+ Content-Type: Audio/G.711A
73
+ ```
74
+
75
+ In the Home app: open the camera → hold the microphone button.
76
+
77
+ ## Unlock
78
+
79
+ ```text
80
+ GET /cgi-bin/accessControl.cgi?action=openDoor&channel=1&UserID=101&Type=Remote
81
+ ```
82
+
83
+ ## Notes for publishing
84
+
85
+ 1. Replace `roysbike` in `package.json` `repository` / `bugs` / `homepage`
86
+ 2. Set `"author"`
87
+ 3. `npm login` && `npm publish`
88
+ 4. Optional: request [Homebridge verified](https://github.com/homebridge/plugins) listing after the plugin is stable
89
+
90
+ ## License
91
+
92
+ MIT
@@ -0,0 +1,113 @@
1
+ {
2
+ "pluginAlias": "DahuaVTO",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Platform Name",
10
+ "type": "string",
11
+ "default": "Dahua VTO",
12
+ "description": "Internal platform name (Homebridge UI)."
13
+ },
14
+ "cameras": {
15
+ "title": "Door stations",
16
+ "type": "array",
17
+ "description": "One or more Dahua VTO / Amcrest-compatible door stations.",
18
+ "items": {
19
+ "type": "object",
20
+ "required": ["host", "password"],
21
+ "properties": {
22
+ "name": {
23
+ "title": "Name",
24
+ "type": "string",
25
+ "default": "Dahua VTO",
26
+ "description": "Name shown in the Home app."
27
+ },
28
+ "host": {
29
+ "title": "Host / IP",
30
+ "type": "string",
31
+ "format": "hostname",
32
+ "placeholder": "192.168.1.30",
33
+ "description": "VTO IP address or hostname."
34
+ },
35
+ "username": {
36
+ "title": "Username",
37
+ "type": "string",
38
+ "default": "admin"
39
+ },
40
+ "password": {
41
+ "title": "Password",
42
+ "type": "string",
43
+ "format": "password"
44
+ },
45
+ "ssl": {
46
+ "title": "Use HTTPS for CGI",
47
+ "type": "boolean",
48
+ "default": false
49
+ },
50
+ "doorChannel": {
51
+ "title": "Door channel",
52
+ "type": "integer",
53
+ "default": 1,
54
+ "minimum": 0,
55
+ "description": "accessControl / audio.cgi channel (usually 1)."
56
+ },
57
+ "unlockSeconds": {
58
+ "title": "Unlock duration (seconds)",
59
+ "type": "integer",
60
+ "default": 5,
61
+ "minimum": 1,
62
+ "maximum": 60
63
+ },
64
+ "rtspUrl": {
65
+ "title": "RTSP URL override",
66
+ "type": "string",
67
+ "description": "Optional. Default: rtsp://user:pass@host:554/cam/realmonitor?channel=1&subtype=0"
68
+ },
69
+ "rtspSubtype": {
70
+ "title": "RTSP subtype (if no rtspUrl)",
71
+ "type": "integer",
72
+ "default": 0,
73
+ "description": "0 = main stream, 1 = sub stream."
74
+ },
75
+ "ffmpegPath": {
76
+ "title": "ffmpeg path",
77
+ "type": "string",
78
+ "default": "ffmpeg",
79
+ "description": "Use ffmpeg-for-homebridge for AAC-ELD talkback (libfdk_aac)."
80
+ },
81
+ "twoWayAudio": {
82
+ "title": "Two-way audio",
83
+ "type": "boolean",
84
+ "default": true,
85
+ "description": "Home mic → VTO speaker via audio.cgi (G.711A), Scrypted Amcrest style."
86
+ },
87
+ "hksv": {
88
+ "title": "HomeKit Secure Video",
89
+ "type": "boolean",
90
+ "default": true,
91
+ "description": "Requires HomePod / Apple TV hub and iCloud+."
92
+ },
93
+ "motionTimeoutMs": {
94
+ "title": "Motion clear timeout (ms)",
95
+ "type": "integer",
96
+ "default": 10000
97
+ },
98
+ "manufacturer": {
99
+ "title": "Manufacturer",
100
+ "type": "string",
101
+ "default": "Dahua"
102
+ },
103
+ "model": {
104
+ "title": "Model",
105
+ "type": "string",
106
+ "default": "VTO"
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+ }
113
+ }
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ const { PLATFORM_NAME, PLUGIN_NAME } = require("./src/settings");
4
+ const { setHap } = require("./src/hap");
5
+
6
+ module.exports = (api) => {
7
+ setHap(api.hap);
8
+ const { DahuaVtoPlatform } = require("./src/platform");
9
+ api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, DahuaVtoPlatform);
10
+ };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "homebridge-dahua-vto",
3
+ "displayName": "Dahua VTO",
4
+ "version": "1.0.0",
5
+ "description": "Homebridge plugin for Dahua VTO door stations — camera, lock, doorbell, two-way audio (Amcrest audio.cgi) and optional HKSV",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "test": "node -e \"require('./index.js');\""
9
+ },
10
+ "keywords": [
11
+ "homebridge-plugin",
12
+ "homebridge",
13
+ "dahua",
14
+ "vto",
15
+ "doorbell",
16
+ "camera",
17
+ "intercom",
18
+ "two-way-audio",
19
+ "hksv"
20
+ ],
21
+ "engines": {
22
+ "node": "^18.20.4 || ^20.16.0 || ^22.5.1",
23
+ "homebridge": "^1.8.0 || ^2.0.0-beta.0"
24
+ },
25
+ "dependencies": {
26
+ "rtp-packet": "^0.1.1"
27
+ },
28
+ "peerDependencies": {
29
+ "homebridge": "^1.8.0 || ^2.0.0-beta.0"
30
+ },
31
+ "author": "Artem Goncharenko",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/roysbike/homebridge-dahua-vto.git"
36
+ },
37
+ "bugs": {
38
+ "url": "https://github.com/roysbike/homebridge-dahua-vto/issues"
39
+ },
40
+ "homepage": "https://github.com/roysbike/homebridge-dahua-vto#readme",
41
+ "files": [
42
+ "index.js",
43
+ "config.schema.json",
44
+ "LICENSE",
45
+ "README.md",
46
+ "src"
47
+ ]
48
+ }
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+
3
+ const { DahuaClient } = require("./dahua/client");
4
+ const { VtoCameraDelegate, buildDoorbellController } = require("./homekit/camera");
5
+
6
+ function normalizeDeviceConfig(raw) {
7
+ const host = raw.host;
8
+ const username = raw.username || "admin";
9
+ const password = raw.password || "";
10
+ const ssl = Boolean(raw.ssl);
11
+ const proto = ssl ? "https" : "http";
12
+ const doorChannel = Number(raw.doorChannel || raw.channel || 1) || 1;
13
+ const unlockSeconds = Number(raw.unlockSeconds || 5) || 5;
14
+ const ffmpegPath = raw.ffmpegPath || raw.videoProcessor || "ffmpeg";
15
+ const twoWayAudio = raw.twoWayAudio !== false;
16
+ const hksv = raw.hksv !== false;
17
+
18
+ const rtspUrl =
19
+ raw.rtspUrl ||
20
+ `rtsp://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${host}:554/cam/realmonitor?channel=1&subtype=${raw.rtspSubtype ?? 0}`;
21
+
22
+ return {
23
+ name: raw.name || `Dahua VTO ${host}`,
24
+ manufacturer: raw.manufacturer || "Dahua",
25
+ model: raw.model || "VTO",
26
+ firmware: raw.firmware || "1.0.0",
27
+ ffmpegPath,
28
+ rtspUrl,
29
+ twoWayAudio,
30
+ dahua: {
31
+ host,
32
+ username,
33
+ password,
34
+ ssl,
35
+ baseUrl: `${proto}://${host}/cgi-bin/`,
36
+ doorChannel,
37
+ unlockSeconds,
38
+ eventCodes: raw.eventCodes || "All",
39
+ },
40
+ hksv: {
41
+ enabled: hksv,
42
+ prebufferMs: Number(raw.hksvPrebufferMs || 4000),
43
+ fragmentMs: Number(raw.hksvFragmentMs || 4000),
44
+ motionTimeoutMs: Number(raw.motionTimeoutMs || 10000),
45
+ },
46
+ };
47
+ }
48
+
49
+ /**
50
+ * One VIDEO_DOORBELL accessory: camera + lock + motion + two-way (Amcrest talkback).
51
+ */
52
+ class DahuaVtoAccessory {
53
+ constructor(log, deviceConfig, api, accessory) {
54
+ this.log = log;
55
+ this.api = api;
56
+ this.accessory = accessory;
57
+ this.config = normalizeDeviceConfig(deviceConfig);
58
+ this.hap = api.hap;
59
+
60
+ const { Service, Characteristic, Categories } = this.hap;
61
+
62
+ accessory
63
+ .getService(Service.AccessoryInformation)
64
+ .setCharacteristic(Characteristic.Manufacturer, this.config.manufacturer)
65
+ .setCharacteristic(Characteristic.Model, this.config.model)
66
+ .setCharacteristic(Characteristic.SerialNumber, this.config.dahua.host)
67
+ .setCharacteristic(Characteristic.FirmwareRevision, this.config.firmware);
68
+
69
+ // Prefer doorbell category
70
+ accessory.category = Categories.VIDEO_DOORBELL;
71
+
72
+ this.motionActive = false;
73
+ this.motionTimer = null;
74
+ this.lockTimeout = null;
75
+ this.unlocking = false;
76
+ this.targetState = Characteristic.LockTargetState.SECURED;
77
+ this.currentState = Characteristic.LockCurrentState.SECURED;
78
+
79
+ this.dahua = new DahuaClient(this.config.dahua, this._logger());
80
+ this.delegate = new VtoCameraDelegate({
81
+ config: this.config,
82
+ log: this._logger(),
83
+ dahua: this.dahua,
84
+ getMotionActive: () => this.motionActive,
85
+ });
86
+
87
+ this.controller = buildDoorbellController(this.delegate, this.config);
88
+ this.delegate.controller = this.controller;
89
+ accessory.configureController(this.controller);
90
+
91
+ this._setupLock();
92
+ this._wireEvents();
93
+ this.dahua.startEventStream();
94
+
95
+ this.log.info(
96
+ `Ready ${this.config.name} @ ${this.config.dahua.host} ` +
97
+ `(twoWay=${this.config.twoWayAudio}, hksv=${this.config.hksv.enabled})`
98
+ );
99
+ }
100
+
101
+ _logger() {
102
+ return {
103
+ info: (...a) => this.log.info(...a),
104
+ warn: (...a) => this.log.warn(...a),
105
+ error: (...a) => this.log.error(...a),
106
+ debug: (...a) => this.log.debug(...a),
107
+ };
108
+ }
109
+
110
+ _setupLock() {
111
+ const { Service, Characteristic } = this.hap;
112
+ let lockService = this.accessory.getService(Service.LockMechanism);
113
+ if (!lockService) {
114
+ lockService = this.accessory.addService(Service.LockMechanism, "Door Lock");
115
+ }
116
+ this.lockService = lockService;
117
+
118
+ const doorbellService = this.accessory.getService(Service.Doorbell);
119
+ if (doorbellService) {
120
+ try {
121
+ doorbellService.addLinkedService(lockService);
122
+ } catch {
123
+ /* already linked */
124
+ }
125
+ }
126
+
127
+ const pushLockState = (target, current) => {
128
+ setTimeout(() => {
129
+ lockService.updateCharacteristic(Characteristic.LockTargetState, target);
130
+ lockService.updateCharacteristic(Characteristic.LockCurrentState, current);
131
+ }, 150);
132
+ };
133
+
134
+ lockService
135
+ .getCharacteristic(Characteristic.LockCurrentState)
136
+ .onGet(() => this.currentState);
137
+
138
+ lockService
139
+ .getCharacteristic(Characteristic.LockTargetState)
140
+ .onGet(() => this.targetState)
141
+ .onSet(async (value) => {
142
+ this.targetState = value;
143
+ if (value !== Characteristic.LockTargetState.UNSECURED) {
144
+ return;
145
+ }
146
+ if (this.unlocking) {
147
+ this.log.info("Lock SET ignored (unlock in progress)");
148
+ return;
149
+ }
150
+
151
+ this.unlocking = true;
152
+ try {
153
+ await this.dahua.openDoor(this.config.dahua.doorChannel);
154
+ this.currentState = Characteristic.LockCurrentState.UNSECURED;
155
+ pushLockState(Characteristic.LockTargetState.UNSECURED, this.currentState);
156
+
157
+ if (this.lockTimeout) {
158
+ clearTimeout(this.lockTimeout);
159
+ }
160
+ this.lockTimeout = setTimeout(() => {
161
+ this.targetState = Characteristic.LockTargetState.SECURED;
162
+ this.currentState = Characteristic.LockCurrentState.SECURED;
163
+ pushLockState(this.targetState, this.currentState);
164
+ this.unlocking = false;
165
+ this.log.info("Door re-secured");
166
+ }, this.config.dahua.unlockSeconds * 1000);
167
+ } catch (err) {
168
+ this.unlocking = false;
169
+ this.log.error(`Unlock failed: ${err.message}`);
170
+ this.targetState = Characteristic.LockTargetState.SECURED;
171
+ this.currentState = Characteristic.LockCurrentState.SECURED;
172
+ pushLockState(this.targetState, this.currentState);
173
+ }
174
+ });
175
+ }
176
+
177
+ setMotion(active, reason = "") {
178
+ const { Service, Characteristic } = this.hap;
179
+ this.motionActive = Boolean(active);
180
+ const motionService = this.accessory.getService(Service.MotionSensor);
181
+ motionService?.updateCharacteristic(Characteristic.MotionDetected, this.motionActive);
182
+ this.log.info(`Motion=${this.motionActive}${reason ? ` (${reason})` : ""}`);
183
+ if (this.motionTimer) {
184
+ clearTimeout(this.motionTimer);
185
+ this.motionTimer = null;
186
+ }
187
+ if (this.motionActive) {
188
+ this.motionTimer = setTimeout(() => {
189
+ this.motionActive = false;
190
+ motionService?.updateCharacteristic(Characteristic.MotionDetected, false);
191
+ this.log.info("Motion auto-cleared");
192
+ }, this.config.hksv.motionTimeoutMs);
193
+ }
194
+ }
195
+
196
+ _wireEvents() {
197
+ this.dahua.on("motion", (active, event) => {
198
+ this.setMotion(active, event?.Code || "motion");
199
+ });
200
+
201
+ this.dahua.on("doorbell", (event) => {
202
+ this.log.info(`Doorbell ring (${event?.Code || "unknown"})`);
203
+ this.setMotion(true, "doorbell");
204
+ try {
205
+ this.controller.ringDoorbell();
206
+ } catch (err) {
207
+ this.log.warn(`ringDoorbell failed: ${err.message}`);
208
+ }
209
+ });
210
+ }
211
+
212
+ teardown() {
213
+ try {
214
+ this.dahua.stop();
215
+ } catch {
216
+ /* ignore */
217
+ }
218
+ if (this.motionTimer) {
219
+ clearTimeout(this.motionTimer);
220
+ }
221
+ if (this.lockTimeout) {
222
+ clearTimeout(this.lockTimeout);
223
+ }
224
+ }
225
+ }
226
+
227
+ module.exports = {
228
+ DahuaVtoAccessory,
229
+ normalizeDeviceConfig,
230
+ };