homebridge-zonetouch3 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,69 @@
1
- # Temporary Holding Version
1
+ # homebridge-zonetouch3
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Homebridge plugin for the Polyaire **ZoneTouch 3**. Each configured zone
4
+ shows up in HomeKit as an adjustable Window Covering, with its position mapped
5
+ to the zone damper percentage.
6
+
7
+ ## Status: real, working protocol
8
+
9
+ ZoneTouch 3 talks over a **raw TCP socket** on your local network (default
10
+ port `7030`) — plain binary frames with a CRC16 (Modbus) checksum, no
11
+ auth token required. This was reverse-engineered and confirmed working by
12
+ the Home Assistant community (see the "ZoneTouch 3 by Polyaire" thread on
13
+ community.home-assistant.io); this plugin ports that protocol directly.
14
+
15
+ Supported:
16
+ - Setting each zone damper from 0% (closed) to 100% (fully open)
17
+ - Polling zone state and temperature every `pollIntervalSeconds` (default 30s)
18
+
19
+ The temperature sensor is not exposed as a HomeKit accessory.
20
+
21
+ ## Install
22
+
23
+ Copy this folder to your Homebridge plugins directory and run `npm install`
24
+ inside it (there are no external dependencies — it only uses Node's
25
+ built-in `net` module).
26
+
27
+ ## Config (config.json)
28
+
29
+ ```json
30
+ {
31
+ "platforms": [
32
+ {
33
+ "platform": "ZoneTouch3",
34
+ "name": "ZoneTouch AC",
35
+ "ip": "192.168.1.50",
36
+ "port": 7030,
37
+ "pollIntervalSeconds": 30,
38
+ "zones": [
39
+ { "id": 0, "name": "Living Room" },
40
+ { "id": 1, "name": "Bedroom" }
41
+ ]
42
+ }
43
+ ]
44
+ }
45
+ ```
46
+
47
+ - `ip`: your ZoneTouch 3's local IP (check your router/UniFi client list,
48
+ or the ZoneTouch app's network settings).
49
+ - `port`: 7030 is what's confirmed in the community thread. If your unit
50
+ doesn't respond, this is the first thing worth double-checking.
51
+ - `zones[].id`: zone index starting at 0, in the same order they appear in
52
+ the ZoneTouch app.
53
+ - Each zone's HomeKit position control sets the damper opening percentage.
54
+
55
+ ## A couple of protocol quirks worth knowing
56
+
57
+ - The message ID byte in each frame is randomized on every send. The
58
+ community found that certain fixed ID values caused some units to
59
+ intermittently reject commands — randomizing sidesteps this.
60
+ - There's a small (250ms) gap enforced between outgoing messages, since
61
+ rapid-fire sends were reported as unreliable on some firmware.
62
+
63
+ ## What each file does
64
+
65
+ - `index.js` — registers the platform with Homebridge.
66
+ - `lib/platform.js` — reads config, creates one accessory per zone.
67
+ - `lib/zoneAccessory.js` — exposes a zone as a HomeKit Switch.
68
+ - `lib/zonetouchClient.js` — the TCP connection and the actual ZoneTouch
69
+ 3 binary protocol (message building, CRC16, response parsing).
@@ -0,0 +1,43 @@
1
+ {
2
+ "pluginAlias": "ZoneTouch3",
3
+ "pluginType": "platform",
4
+ "singular": true,
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "name": {
9
+ "title": "Name",
10
+ "type": "string",
11
+ "default": "ZoneTouch AC"
12
+ },
13
+ "ip": {
14
+ "title": "ZoneTouch 3 IP address",
15
+ "type": "string",
16
+ "required": true,
17
+ "placeholder": "192.168.1.50"
18
+ },
19
+ "port": {
20
+ "title": "TCP port",
21
+ "type": "integer",
22
+ "default": 7030,
23
+ "description": "7030 is the port confirmed by the Home Assistant community reverse-engineering thread."
24
+ },
25
+ "pollIntervalSeconds": {
26
+ "title": "Status poll interval (seconds)",
27
+ "type": "integer",
28
+ "default": 30
29
+ },
30
+ "zones": {
31
+ "title": "Zones",
32
+ "type": "array",
33
+ "items": {
34
+ "type": "object",
35
+ "properties": {
36
+ "id": { "title": "Zone index (0-based)", "type": "integer" },
37
+ "name": { "title": "Zone name", "type": "string" }
38
+ }
39
+ }
40
+ }
41
+ }
42
+ }
43
+ }
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ const { ZoneTouch3Platform } = require('./lib/platform');
2
+
3
+ module.exports = (api) => {
4
+ api.registerPlatform('homebridge-zonetouch3', 'ZoneTouch3', ZoneTouch3Platform);
5
+ };
@@ -0,0 +1,52 @@
1
+ const { ZoneTouchClient } = require('./zonetouchClient');
2
+ const { ZoneAccessory } = require('./zoneAccessory');
3
+
4
+ class ZoneTouch3Platform {
5
+ constructor(log, config, api) {
6
+ this.log = log;
7
+ this.config = config;
8
+ this.api = api;
9
+ this.accessories = [];
10
+
11
+ if (!config.ip) {
12
+ this.log.error('ZoneTouch3: "ip" is required in config.json');
13
+ return;
14
+ }
15
+
16
+ this.client = new ZoneTouchClient(
17
+ log,
18
+ config.ip,
19
+ config.port || 7030,
20
+ config.pollIntervalSeconds || 30
21
+ );
22
+
23
+ this.api.on('didFinishLaunching', () => this._setupZones());
24
+ }
25
+
26
+ // Homebridge calls this to restore cached accessories on startup.
27
+ configureAccessory(accessory) {
28
+ this.accessories.push(accessory);
29
+ }
30
+
31
+ _setupZones() {
32
+ const zones = this.config.zones || [];
33
+ if (zones.length === 0) {
34
+ this.log.warn('ZoneTouch3: no zones configured — add them to config.json under "zones"');
35
+ return;
36
+ }
37
+
38
+ for (const zoneConfig of zones) {
39
+ const uuid = this.api.hap.uuid.generate(`zonetouch3-zone-${zoneConfig.id}`);
40
+ let accessory = this.accessories.find((a) => a.UUID === uuid);
41
+
42
+ if (!accessory) {
43
+ accessory = new this.api.platformAccessory(zoneConfig.name, uuid);
44
+ this.api.registerPlatformAccessories('homebridge-zonetouch3', 'ZoneTouch3', [accessory]);
45
+ }
46
+
47
+ new ZoneAccessory(this, accessory, zoneConfig);
48
+ }
49
+ }
50
+ }
51
+
52
+ module.exports = { ZoneTouch3Platform };
@@ -0,0 +1,54 @@
1
+ class ZoneAccessory {
2
+ constructor(platform, accessory, zoneConfig) {
3
+ this.platform = platform;
4
+ this.accessory = accessory;
5
+ this.zoneConfig = zoneConfig;
6
+ this.targetPosition = null;
7
+ const { Service, Characteristic } = platform.api.hap;
8
+
9
+ const oldSwitchService = accessory.getService(Service.Switch);
10
+ if (oldSwitchService) accessory.removeService(oldSwitchService);
11
+
12
+ accessory.displayName = zoneConfig.name;
13
+ this.service =
14
+ accessory.getService(Service.WindowCovering) || accessory.addService(Service.WindowCovering);
15
+
16
+ this.service.setCharacteristic(Characteristic.Name, zoneConfig.name);
17
+
18
+ this.service
19
+ .getCharacteristic(Characteristic.CurrentPosition)
20
+ .onGet(() => this._getPosition());
21
+
22
+ this.service
23
+ .getCharacteristic(Characteristic.TargetPosition)
24
+ .onGet(() => this._getTargetPosition())
25
+ .onSet((value) => this._setPosition(value));
26
+
27
+ this.service
28
+ .getCharacteristic(Characteristic.PositionState)
29
+ .onGet(() => Characteristic.PositionState.STOPPED);
30
+
31
+ platform.client.on('zoneUpdate', (update) => {
32
+ if (update.zoneId === zoneConfig.id) {
33
+ const position = update.isOn ? update.percent : 0;
34
+ this.service.updateCharacteristic(Characteristic.CurrentPosition, position);
35
+ }
36
+ });
37
+ }
38
+
39
+ _getPosition() {
40
+ const state = this.platform.client.getZoneState(this.zoneConfig.id);
41
+ return state.isOn ? state.percent : 0;
42
+ }
43
+
44
+ _getTargetPosition() {
45
+ return this.targetPosition ?? this._getPosition();
46
+ }
47
+
48
+ _setPosition(value) {
49
+ this.targetPosition = value;
50
+ this.platform.client.setZoneOn(this.zoneConfig.id, value > 0, value);
51
+ }
52
+ }
53
+
54
+ module.exports = { ZoneAccessory };
@@ -0,0 +1,223 @@
1
+ const net = require('net');
2
+ const EventEmitter = require('events');
3
+
4
+ /**
5
+ * Talks to a ZoneTouch 3 unit over its real local protocol: a raw TCP
6
+ * socket (default port 7030), exchanging fixed binary frames with a
7
+ * CRC16 (Modbus) checksum. No authentication token is required — that
8
+ * was only needed in earlier drafts of this plugin, which mistakenly
9
+ * targeted Home Assistant's own WebSocket API instead of the device.
10
+ *
11
+ * Protocol reverse-engineered and confirmed working by the Home
12
+ * Assistant community (community.home-assistant.io, "ZoneTouch 3 by
13
+ * Polyaire" thread). Ported here from their working Node-RED flow.
14
+ *
15
+ * Frame layout (all messages):
16
+ * [0x55 0x55 0x55 0xAA] Fixed header
17
+ * [0x80 0xB0] Address
18
+ * [id] Message ID — any byte; some values are
19
+ * flaky per the community's testing, so a
20
+ * random ID is used per message, as they did.
21
+ * [0xC0] Type
22
+ * [len_hi len_lo] Length of what follows up to (not including) CRC
23
+ * [sub_hi sub_lo] Sub-type (0x2000 = set zone, 0x2100 = zone
24
+ * query, 0x2B00 = temperature query)
25
+ * ...payload...
26
+ * [crc_hi crc_lo] CRC16 Modbus over everything after the header
27
+ */
28
+
29
+ const HEADER = Buffer.from([0x55, 0x55, 0x55, 0xaa]);
30
+
31
+ function crc16Modbus(bytes) {
32
+ let crc = 0xffff;
33
+ for (let i = 0; i < bytes.length; i++) {
34
+ crc ^= bytes[i];
35
+ for (let j = 0; j < 8; j++) {
36
+ crc = crc & 0x0001 ? (crc >> 1) ^ 0xa001 : crc >> 1;
37
+ }
38
+ }
39
+ return crc;
40
+ }
41
+
42
+ function buildMessage(payloadBytes) {
43
+ const crc = crc16Modbus(Buffer.from(payloadBytes));
44
+ const crcHi = (crc >> 8) & 0xff;
45
+ const crcLo = crc & 0xff;
46
+ return Buffer.concat([HEADER, Buffer.from(payloadBytes), Buffer.from([crcHi, crcLo])]);
47
+ }
48
+
49
+ function randomId() {
50
+ return Math.floor(Math.random() * 255);
51
+ }
52
+
53
+ class ZoneTouchClient extends EventEmitter {
54
+ constructor(log, ip, port, pollIntervalSeconds) {
55
+ super();
56
+ this.log = log;
57
+ this.ip = ip;
58
+ this.port = port || 7030;
59
+ this.pollIntervalSeconds = pollIntervalSeconds || 30;
60
+ this.socket = null;
61
+ this.connected = false;
62
+ this.buffer = Buffer.alloc(0);
63
+ this.zoneState = new Map(); // zoneId -> { isOn, percent }
64
+ this.sendQueue = [];
65
+ this._sending = false;
66
+ this._connect();
67
+ }
68
+
69
+ _connect() {
70
+ this.log.info(`ZoneTouch3: connecting to ${this.ip}:${this.port}`);
71
+ this.socket = new net.Socket();
72
+
73
+ this.socket.connect(this.port, this.ip, () => {
74
+ this.connected = true;
75
+ this.log.info('ZoneTouch3: TCP connected');
76
+ this.emit('ready');
77
+ this.queryZones();
78
+ this.queryTemperature();
79
+ this._pollTimer = setInterval(() => {
80
+ this.queryZones();
81
+ this.queryTemperature();
82
+ }, this.pollIntervalSeconds * 1000);
83
+ });
84
+
85
+ this.socket.on('data', (chunk) => this._handleData(chunk));
86
+
87
+ this.socket.on('close', () => {
88
+ this.connected = false;
89
+ if (this._pollTimer) clearInterval(this._pollTimer);
90
+ this.log.warn('ZoneTouch3: connection closed, retrying in 5s');
91
+ setTimeout(() => this._connect(), 5000);
92
+ });
93
+
94
+ this.socket.on('error', (err) => {
95
+ this.log.error(`ZoneTouch3: socket error: ${err.message}`);
96
+ });
97
+ }
98
+
99
+ _handleData(chunk) {
100
+ this.buffer = Buffer.concat([this.buffer, chunk]);
101
+
102
+ // eslint-disable-next-line no-constant-condition
103
+ while (true) {
104
+ const headerIdx = this.buffer.indexOf(HEADER);
105
+ if (headerIdx === -1) {
106
+ this.buffer = Buffer.alloc(0);
107
+ return;
108
+ }
109
+ if (headerIdx > 0) this.buffer = this.buffer.slice(headerIdx);
110
+
111
+ // Zone status reply: sub-type byte at offset 10, fixed 60-byte length.
112
+ if (this.buffer.length >= 60 && this.buffer[10] === 0x21) {
113
+ this._parseZoneStatus(this.buffer.slice(0, 60));
114
+ this.buffer = this.buffer.slice(60);
115
+ continue;
116
+ }
117
+
118
+ // Temperature reply: marker byte at offset 18, fixed 24-byte length.
119
+ if (this.buffer.length >= 24 && this.buffer[18] === 0x9f) {
120
+ this._parseTemperature(this.buffer.slice(0, 24));
121
+ this.buffer = this.buffer.slice(24);
122
+ continue;
123
+ }
124
+
125
+ // Not enough bytes yet for either known reply shape — wait for more.
126
+ break;
127
+ }
128
+ }
129
+
130
+ _parseZoneStatus(msg) {
131
+ const zoneCount = msg[17];
132
+ for (let i = 0; i < zoneCount; i++) {
133
+ const byteIdx = 18 + i * 8;
134
+ const rawStatus = msg[byteIdx] - i;
135
+ let percent = msg[byteIdx + 1];
136
+ const isOn = rawStatus !== 0;
137
+ if (!isOn) percent = 0;
138
+
139
+ this.zoneState.set(i, { isOn, percent });
140
+ this.emit('zoneUpdate', { zoneId: i, isOn, percent });
141
+ }
142
+ }
143
+
144
+ _parseTemperature(msg) {
145
+ const raw = ((msg[20] & 0xff) << 8) | (msg[21] & 0xff);
146
+ const celsius = (raw - 500) / 10;
147
+ this.emit('temperature', celsius);
148
+ }
149
+
150
+ _queueSend(buffer) {
151
+ this.sendQueue.push(buffer);
152
+ this._drainQueue();
153
+ }
154
+
155
+ _drainQueue() {
156
+ if (this._sending || this.sendQueue.length === 0) return;
157
+ if (!this.connected) return;
158
+ this._sending = true;
159
+ const buf = this.sendQueue.shift();
160
+ this.socket.write(buf, () => {
161
+ // Small gap between sends — the real app doesn't fire messages
162
+ // back-to-back either, and the community reported flakiness
163
+ // under rapid-fire sends.
164
+ setTimeout(() => {
165
+ this._sending = false;
166
+ this._drainQueue();
167
+ }, 250);
168
+ });
169
+ }
170
+
171
+ /**
172
+ * Turns a zone on (optionally to a given open percentage) or off.
173
+ * Matches the app's own behaviour: ON is sent as two messages —
174
+ * an ON flag, then a percentage — OFF is sent as a single message.
175
+ */
176
+ setZoneOn(zoneId, isOn, percent = 100) {
177
+ if (isOn) {
178
+ this._queueSend(buildMessage(this._setZonePayload(zoneId, 0x03, 0x00)));
179
+ this._queueSend(buildMessage(this._setZonePayload(zoneId, 0x80, percent)));
180
+ } else {
181
+ this._queueSend(buildMessage(this._setZonePayload(zoneId, 0x02, 0x00)));
182
+ }
183
+ }
184
+
185
+ _setZonePayload(zoneId, state, value) {
186
+ return [
187
+ 0x80, 0xb0, // Address
188
+ randomId(), // Message ID
189
+ 0xc0, // Type
190
+ 0x00, 0x0c, // Length
191
+ 0x20, 0x00, // Sub-type: set zone
192
+ 0x00, 0x00, // Common data length
193
+ 0x00, 0x04, // Repeat data count
194
+ 0x00, 0x01, // Repeat data length
195
+ zoneId,
196
+ state, // 0x03 = on, 0x02 = off, 0x80 = percentage
197
+ value,
198
+ 0x00,
199
+ ];
200
+ }
201
+
202
+ queryZones() {
203
+ this._queueSend(
204
+ buildMessage([
205
+ 0x80, 0xb0, 0x01, 0xc0, 0x00, 0x08, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
206
+ ])
207
+ );
208
+ }
209
+
210
+ queryTemperature() {
211
+ this._queueSend(
212
+ buildMessage([
213
+ 0x80, 0xb0, 0x01, 0xc0, 0x00, 0x08, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
214
+ ])
215
+ );
216
+ }
217
+
218
+ getZoneState(zoneId) {
219
+ return this.zoneState.get(zoneId) || { isOn: false, percent: 0 };
220
+ }
221
+ }
222
+
223
+ module.exports = { ZoneTouchClient };
package/package.json CHANGED
@@ -1,6 +1,20 @@
1
1
  {
2
2
  "name": "homebridge-zonetouch3",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Homebridge plugin for Polyaire ZoneTouch 3 AC zone control",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/christopherguzik/homebridge-zonetouch3.git"
8
+ },
9
+ "homepage": "https://github.com/christopherguzik/homebridge-zonetouch3#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/christopherguzik/homebridge-zonetouch3/issues"
12
+ },
13
+ "main": "index.js",
14
+ "keywords": ["homebridge-plugin"],
15
+ "engines": {
16
+ "homebridge": ">=1.6.0",
17
+ "node": ">=16.0.0"
18
+ },
19
+ "dependencies": {}
20
+ }