matterbridge-mqtt 0.0.5 → 0.0.6

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/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ If you like this project and find it useful, please consider giving it a star on
8
8
 
9
9
  <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="120"></a>
10
10
 
11
+ ## [0.0.6] - 2026-06-10
12
+
13
+ ### Added
14
+
15
+ - Require Matterbridge 3.9.0.
16
+ - Add subscribe topic **matterbridge/deviceid/subscribe/root**.
17
+ - Remove Jest and add Vitest.
18
+
19
+ <a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
20
+
11
21
  ## [0.0.5] - 2026-06-09
12
22
 
13
23
  ### Added
package/README.md CHANGED
@@ -9,6 +9,7 @@
9
9
  ![Node.js CI](https://github.com/Luligu/matterbridge-mqtt/actions/workflows/build.yml/badge.svg)
10
10
  ![CodeQL](https://github.com/Luligu/matterbridge-mqtt/actions/workflows/codeql.yml/badge.svg)
11
11
  [![codecov](https://codecov.io/gh/Luligu/matterbridge-mqtt/branch/main/graph/badge.svg)](https://codecov.io/gh/Luligu/matterbridge-mqtt)
12
+ [![tested with Vitest](https://img.shields.io/badge/tested_with-vitest-6E9F18.svg?logo=vitest&logoColor=white)](https://vitest.dev)
12
13
  [![formatted with oxfmt](https://img.shields.io/badge/formatted_with-oxfmt-9BE4E0.svg)](https://oxc.rs/docs/guide/usage/formatter.html)
13
14
  [![linted with oxlint](https://img.shields.io/badge/linted_with-oxlint-9BE4E0.svg)](https://oxc.rs/docs/guide/usage/linter.html)
14
15
  [![TypeScript](https://img.shields.io/badge/TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
@@ -31,7 +32,7 @@ The **matterbridge-mqtt** plugin bridges any MQTT-capable device into the Matter
31
32
  - **Zero-code device onboarding** — send a single retained `config` message and Matterbridge automatically creates and registers the corresponding Matter endpoint.
32
33
  - **Broad device-type support** — lights (on/off, dimmable, colour-temperature, extended colour), plugs and outlets, mounted switches, sensors (contact, temperature, humidity, pressure, flow, light, occupancy, smoke/CO, air quality, rain, soil, water freeze/leak), pump, water valve, power source, and electrical sensor.
33
34
  - **Live state sync** — retained `state` messages drive cluster attribute updates so controllers always see the current device state, even after a restart.
34
- - **Matter command forwarding** — every Matter command (e.g. `on`, `off`, `moveToLevel`) is published back to the device's `command` topic as a structured JSON payload.
35
+ - **Matter state forwarding** — every Matter attribute change (e.g. `onOff`, `currentLevel`) is published back to the device's `write` topic as a structured JSON payload.
35
36
  - **Flexible MQTT connectivity** — configurable broker host, port, protocol version (3/4/5), credentials, client ID, and full TLS support (CA certificate, client certificate/key, `rejectUnauthorized`).
36
37
  - **Topic-based multi-device management** — a single broker connection and a single base topic handle an arbitrary number of devices; each device is identified by its `deviceId` path segment.
37
38
 
@@ -89,7 +90,7 @@ All topics follow the pattern `<topic>/<deviceId>/<subTopic>/root`, where `<topi
89
90
 
90
91
  ## Publish
91
92
 
92
- Each device shall publish retained `config` messages and retained `state` messages:
93
+ Each device shall publish retained `config`, `state` and `subscribe` messages:
93
94
 
94
95
  Device types, clusters and attributes all use their Matter names without spaces: device types (e.g. `PowerSource`, `DimmableLight`), clusters (e.g. `PowerSource`, `OnOff`, `LevelControl`) and attributes (e.g. `onOff`, `currentLevel`).
95
96
 
@@ -97,7 +98,7 @@ Device types, clusters and attributes all use their Matter names without spaces:
97
98
 
98
99
  - **matterbridge/deviceid/config/root**
99
100
 
100
- only the fixed and optional attributes shall be published here
101
+ Publish here only the fixed and optional attributes.
101
102
 
102
103
  ```typescript
103
104
  const config = {
@@ -111,34 +112,52 @@ publish('matterbridge/light1/config/root', JSON.stringify(config), { retain: tru
111
112
 
112
113
  - **matterbridge/deviceid/state/root**
113
114
 
114
- only the current attributes shall be published here
115
+ Publish here only the current attribute values.
115
116
 
116
117
  ```typescript
117
118
  const state = { OnOff: { onOff: false }, LevelControl: { currentLevel: 254 } };
118
119
  publish('matterbridge/deviceid/state/root', JSON.stringify(state), { retain: true, qos: 2 });
119
120
  ```
120
121
 
121
- ## Subscribe
122
+ ### subscribe
123
+
124
+ - **matterbridge/deviceid/subscribe/root**
125
+
126
+ Publish here only the attribute changes that the device wants to receive from the controller.
127
+
128
+ ```typescript
129
+ const subscribe = { OnOff: ['onOff'], LevelControl: ['currentLevel'] };
130
+ publish('matterbridge/deviceid/state/root', JSON.stringify(subscribe), { retain: true, qos: 2 });
131
+ ```
122
132
 
123
- Each device shall subscribe:
133
+ ## Subscribe
124
134
 
125
- ### command
135
+ Each device may subscribe to `write` messages:
126
136
 
127
- - **matterbridge/deviceid/command/root**
137
+ ```typescript
138
+ subscribe('matterbridge/deviceid/write/root', { qos: 2 });
139
+ ```
128
140
 
129
- It will receive all Matter commands.
141
+ and will receive all attributes changes it subscribed to.
130
142
 
131
143
  ```typescript
132
- Topic: 'matterbridge/deviceid/command/root'
133
- Payload: "{"cluster":"OnOff","command":"on","request": MatterRequest | undefined }"
144
+ { OnOff: { onOff: false }, LevelControl: { currentLevel: 254 } }
134
145
  ```
135
146
 
136
147
  ---
137
148
 
149
+ # Repository setup
150
+
151
+ > **Note:** This repository uses an experimental new toolchain. It drops the traditional ESLint / Prettier / TypeScript / Jest stack in favor of a faster, lighter setup.
152
+
153
+ - **No ESLint, no Prettier** — replaced by the [oxc](https://oxc.rs) stack ([oxlint](https://oxc.rs/docs/guide/usage/linter.html) for linting and [oxfmt](https://oxc.rs/docs/guide/usage/formatter.html) for formatting).
154
+ - **No `typescript` package** — replaced by [tsgo](https://github.com/microsoft/typescript-go) (`@typescript/native-preview`). The `typescript` package is kept only as a publish-time dependency while tsgo is still in preview.
155
+ - **No Jest** — replaced by [Vitest](https://vitest.dev), which natively supports ESM without extra configuration.
156
+ - **Far fewer dependencies** — the installed package count drops from 600+ to around 200.
157
+ - **Much faster lint and format** — oxlint and oxfmt run in a fraction of the time of the ESLint / Prettier pipeline.
158
+ - **Much faster build** — tsgo compiles the project in a fraction of the time of the standard `tsc` build.
159
+ - **Editor support** — use the VS Code extensions for tsgo and oxc to get the same experience inside the editor.
160
+
138
161
  # Todo
139
162
 
140
- - [x] Add white and black list
141
- - [x] Attributes handler in config
142
- - [ ] Matter command handler
143
- - [ ] Matter Subscribe handler
144
163
  - [ ] Add composed device types
package/dist/module.js CHANGED
@@ -12,8 +12,8 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
12
12
  constructor(matterbridge, log, config) {
13
13
  super(matterbridge, log, config);
14
14
  this.config = config;
15
- if (typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.8.1')) {
16
- throw new Error(`This plugin requires Matterbridge version >= "3.8.1". Please update Matterbridge to the latest version in the frontend.`);
15
+ if (typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('3.9.0')) {
16
+ throw new Error(`This plugin requires Matterbridge version >= "3.9.0". Please update Matterbridge to the latest version in the frontend.`);
17
17
  }
18
18
  this.log.info(`Initializing platform: ${this.config.name}`);
19
19
  this.mqtt = new MqttService(this.config);
@@ -78,13 +78,17 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
78
78
  return;
79
79
  }
80
80
  const { deviceId, subTopic, endpointName } = parsed;
81
+ if (!['config', 'state', 'subscribe', 'write'].includes(subTopic)) {
82
+ this.log.warn(`Received MQTT message with unrecognized subTopic ${warn.magenta.bold `${subTopic}`} on topic ${warn.success.bold `${topic}`}. Ignoring.`);
83
+ return;
84
+ }
81
85
  if (subTopic === 'config' && payload === '') {
82
86
  this.log.debug(`MQTT ${packet.retain ? 'retained ' : ''}message on '${topic}': empty payload`);
83
87
  this.log.info(`Received empty payload on config topic '${topic}', treating as device deletion request.`);
84
88
  this.destroyDevice(deviceId);
85
89
  return;
86
90
  }
87
- if (subTopic === 'state' && payload === '') {
91
+ if (['state', 'subscribe', 'write'].includes(subTopic) && payload === '') {
88
92
  this.log.debug(`MQTT ${packet.retain ? 'retained ' : ''}message on '${topic}': empty payload`);
89
93
  return;
90
94
  }
@@ -116,8 +120,38 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
116
120
  if (this.isConfigured)
117
121
  fireAndForget(this.updateHandler(topic, payload), this.log, `Failed to handle state update for device ${deviceId} on endpoint ${endpointName}`);
118
122
  }
119
- else {
120
- this.log.warn(`Received MQTT message with unrecognized subTopic ${warn.magenta.bold `${subTopic}`} on topic ${warn.success.bold `${topic}`}. Ignoring.`);
123
+ else if (subTopic === 'subscribe') {
124
+ this.log.info(`Received ${info.bgMagenta.black.bold ` subscribe `} message for device ${info.bgCyan.black.bold ` ${deviceId} `} endpoint ${info.bgGreen.black.bold ` ${endpointName} `}`);
125
+ if (typeof message !== 'object' || message === null || Array.isArray(message)) {
126
+ this.log.warn(`Received MQTT message on topic '${topic}' with invalid format: subscribe is missing or not an object. Ignoring.`);
127
+ return;
128
+ }
129
+ for (const clusterName of Object.keys(message)) {
130
+ if (!this.getDeviceById(deviceId)?.hasClusterServer(clusterName)) {
131
+ this.log.warn(`Cannot subscribe to cluster '${clusterName}' for device '${deviceId}' because the device does not have that cluster defined. Skipping subscribe configuration for this cluster.`);
132
+ continue;
133
+ }
134
+ const attributes = message[clusterName];
135
+ if (typeof attributes !== 'object' || attributes === null || !Array.isArray(attributes)) {
136
+ this.log.warn(`Received MQTT message on topic '${topic}' with invalid format: attributes for cluster '${clusterName}' in subscribe are not an array. Ignoring subscribe configuration for this cluster.`);
137
+ continue;
138
+ }
139
+ for (const attributeName of attributes) {
140
+ if (!this.getDeviceById(deviceId)?.hasAttributeServer(clusterName, attributeName)) {
141
+ this.log.warn(`Cannot subscribe to cluster '${clusterName}:${attributeName}' for device '${deviceId}' because the device does not have that attribute defined. Skipping subscribe configuration for this cluster.`);
142
+ continue;
143
+ }
144
+ this.getDeviceById(deviceId)?.subscribeAttribute(clusterName, attributeName, (value) => {
145
+ this.log.debug(`Received update for subscribed attribute '${clusterName}:${attributeName}' on device '${deviceId}': ${debugStringify(value)}`);
146
+ const subscribeTopic = `${this.config.topic}/${deviceId}/write/${endpointName}`;
147
+ const payload = JSON.stringify({ [clusterName]: { [attributeName]: value } });
148
+ fireAndForget(this.mqtt.publish(subscribeTopic, payload, { retain: false }), this.log, `Failed to publish MQTT message for subscribed attribute update on '${subscribeTopic}' with payload ${payload}`);
149
+ });
150
+ }
151
+ }
152
+ }
153
+ else if (subTopic === 'write') {
154
+ return;
121
155
  }
122
156
  }
123
157
  catch (error) {
@@ -147,7 +181,7 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
147
181
  id: deviceId,
148
182
  });
149
183
  device.createDefaultBridgedDeviceBasicInformationClusterServer(deviceName, serialNumber, bridgedDeviceBasicInformationCluster.vendorId, bridgedDeviceBasicInformationCluster.vendorName, bridgedDeviceBasicInformationCluster.productName, bridgedDeviceBasicInformationCluster.softwareVersion, bridgedDeviceBasicInformationCluster.softwareVersionString, bridgedDeviceBasicInformationCluster.hardwareVersion, bridgedDeviceBasicInformationCluster.hardwareVersionString);
150
- this.log.debug(`Created Bridged Device Basic Information Cluster for device ${deviceId} with attributes: ${debugStringify(bridgedDeviceBasicInformationCluster)}`);
184
+ this.log.debug(`Created Bridged Device Basic Information Cluster for device ${deviceId} with attributes: ${debugStringify({ ...bridgedDeviceBasicInformationCluster, nodeLabel: deviceName, serialNumber: serialNumber })}`);
151
185
  if (jsonPayload.deviceTypes.includes('PowerSource')) {
152
186
  const powerSourceCluster = jsonPayload.clusters.PowerSource || {};
153
187
  if (powerSourceCluster.batReplacementDescription !== undefined || powerSourceCluster.batQuantity !== undefined) {
@@ -2,7 +2,7 @@ import { readFileSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { AirQuality, PowerSource, SmokeCoAlarm, ValveConfigurationAndControl } from 'matterbridge/matter/clusters';
5
- import { hasParameter } from 'matterbridge/utils';
5
+ import { getParameter, hasParameter } from 'matterbridge/utils';
6
6
  import { connectAsync } from 'mqtt';
7
7
  const configPath = path.join(homedir(), '.matterbridge', 'matterbridge-mqtt.config.json');
8
8
  let config;
@@ -35,6 +35,7 @@ const DEVICES = [
35
35
  deviceTypes: ['OnOffLight', 'PowerSource'],
36
36
  configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
37
37
  state: { OnOff: { onOff: false } },
38
+ subscribe: { OnOff: ['onOff'] },
38
39
  },
39
40
  {
40
41
  id: 'test-dimmable-light',
@@ -42,6 +43,7 @@ const DEVICES = [
42
43
  deviceTypes: ['DimmableLight', 'PowerSource'],
43
44
  configClusters: { LevelControl: { onLevel: 128 }, PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
44
45
  state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 128 } },
46
+ subscribe: { OnOff: ['onOff'], LevelControl: ['currentLevel'] },
45
47
  },
46
48
  {
47
49
  id: 'test-color-temp-light',
@@ -49,6 +51,7 @@ const DEVICES = [
49
51
  deviceTypes: ['ColorTemperatureLight', 'PowerSource'],
50
52
  configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
51
53
  state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { colorTemperatureMireds: 370 } },
54
+ subscribe: { OnOff: ['onOff'], LevelControl: ['currentLevel'], ColorControl: ['colorTemperatureMireds'] },
52
55
  },
53
56
  {
54
57
  id: 'test-extended-color-light',
@@ -56,6 +59,11 @@ const DEVICES = [
56
59
  deviceTypes: ['ExtendedColorLight', 'PowerSource'],
57
60
  configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
58
61
  state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { currentHue: 128, currentSaturation: 200 } },
62
+ subscribe: {
63
+ OnOff: ['onOff'],
64
+ LevelControl: ['currentLevel'],
65
+ ColorControl: ['colorMode', 'colorTemperatureMireds', 'currentHue', 'currentSaturation', 'currentX', 'currentY'],
66
+ },
59
67
  },
60
68
  {
61
69
  id: 'test-onoff-plugin-unit',
@@ -211,13 +219,19 @@ console.log(`Connecting to ${config.host}:${config.port} (protocol v${config.pro
211
219
  const client = await connectAsync(config.host, clientOptions);
212
220
  console.log(`Connected. Publishing to base topic "${baseTopic}".\n`);
213
221
  const pubOptions = { retain: true, qos: 2 };
222
+ const filter = getParameter('filter');
223
+ if (filter)
224
+ console.log(`Filtering devices with name containing "${filter}"...\n`);
214
225
  for (const device of DEVICES) {
226
+ if (filter && !device.name.includes(filter))
227
+ continue;
215
228
  const configPayload = JSON.stringify({
216
229
  deviceTypes: device.deviceTypes,
217
230
  clusters: {
218
231
  BridgedDeviceBasicInformation: {
219
232
  nodeLabel: device.name,
220
- serialNumber: `TEST-${device.id}`,
233
+ serialNumber: device.id,
234
+ productName: 'Matterbridge MQTT Test Device',
221
235
  },
222
236
  ...device.configClusters,
223
237
  },
@@ -225,11 +239,19 @@ for (const device of DEVICES) {
225
239
  const statePayload = JSON.stringify(device.state);
226
240
  const configTopic = `${baseTopic}/${device.id}/config/root`;
227
241
  const stateTopic = `${baseTopic}/${device.id}/state/root`;
242
+ const subscribeTopic = `${baseTopic}/${device.id}/subscribe/root`;
228
243
  await client.publishAsync(configTopic, hasParameter('delete') ? '' : configPayload, pubOptions);
229
244
  await client.publishAsync(stateTopic, hasParameter('delete') ? '' : statePayload, pubOptions);
245
+ if (device.subscribe) {
246
+ const subscribePayload = JSON.stringify(device.subscribe);
247
+ await client.publishAsync(subscribeTopic, hasParameter('delete') ? '' : subscribePayload, pubOptions);
248
+ }
230
249
  console.log(`${hasParameter('delete') ? 'Deleted' : 'Published'} [${device.name}]`);
231
250
  console.log(` config → ${configTopic}`);
232
251
  console.log(` state → ${stateTopic}`);
252
+ if (device.subscribe) {
253
+ console.log(` subscribe → ${subscribeTopic}`);
254
+ }
233
255
  }
234
256
  await client.endAsync();
235
- console.log(`\nDone. Published config + state for ${DEVICES.length} device(s).`);
257
+ console.log(`\nDone. Published config + state + subscribe for ${DEVICES.length} device(s).`);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "matterbridge-mqtt",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "matterbridge-mqtt",
9
- "version": "0.0.5",
9
+ "version": "0.0.6",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "mqtt": "5.15.1",
@@ -31,9 +31,9 @@
31
31
  }
32
32
  },
33
33
  "node_modules/@types/node": {
34
- "version": "25.9.2",
35
- "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.2.tgz",
36
- "integrity": "sha512-G05zqtJhcDLb8uslf5EjCxXg9G1KQxiV8OS0R26IC//Eoyitzqe8z37I7cqvnZlrlSfgocQRfSn/AHBZJJFyGw==",
34
+ "version": "25.9.3",
35
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.3.tgz",
36
+ "integrity": "sha512-603BddQMv3pUcr4U2dhujk83N2tTDVr/34wII2B6bJy6g+8WD6yUb11jszNs0gdi4PesVWl7ABt8nYMVpnLUcg==",
37
37
  "license": "MIT",
38
38
  "dependencies": {
39
39
  "undici-types": ">=7.24.0 <7.24.7"
@@ -102,15 +102,15 @@
102
102
  }
103
103
  },
104
104
  "node_modules/broker-factory": {
105
- "version": "3.1.14",
106
- "resolved": "https://registry.npmjs.org/broker-factory/-/broker-factory-3.1.14.tgz",
107
- "integrity": "sha512-L45k5HMbPIrMid0nTOZ/UPXG/c0aRuQKVrSDFIb1zOkvfiyHgYmIjc3cSiN1KwQIvRDOtKE0tfb3I9EZ3CmpQQ==",
105
+ "version": "3.1.15",
106
+ "resolved": "https://registry.npmjs.org/broker-factory/-/broker-factory-3.1.15.tgz",
107
+ "integrity": "sha512-ko+aWvgNuP49meGrdjUu7rC+Y+Wai3cCPxP3xWwHsHfehFjOh5ZQM2yC4gEB2UddeZ/YXhm0K1eG/L6fxym2Og==",
108
108
  "license": "MIT",
109
109
  "dependencies": {
110
- "@babel/runtime": "^7.29.2",
110
+ "@babel/runtime": "^7.29.7",
111
111
  "fast-unique-numbers": "^9.0.27",
112
112
  "tslib": "^2.8.1",
113
- "worker-factory": "^7.0.49"
113
+ "worker-factory": "^7.0.50"
114
114
  }
115
115
  },
116
116
  "node_modules/buffer": {
@@ -545,12 +545,12 @@
545
545
  "license": "MIT"
546
546
  },
547
547
  "node_modules/worker-factory": {
548
- "version": "7.0.49",
549
- "resolved": "https://registry.npmjs.org/worker-factory/-/worker-factory-7.0.49.tgz",
550
- "integrity": "sha512-lW7tpgy6aUv2dFsQhv1yv+XFzdkCf/leoKRTGMPVK5/die6RrUjqgJHJf556qO+ZfytNG6wPXc17E8zzsOLUDw==",
548
+ "version": "7.0.50",
549
+ "resolved": "https://registry.npmjs.org/worker-factory/-/worker-factory-7.0.50.tgz",
550
+ "integrity": "sha512-hhwc0G+sFwM4qBuhJIUBn2p1Jf8v/FwmLUANBf/Q+Lt2uI8mfIZQhXaZQACodQD4R7Zp6cn/6702bIvNn2puJQ==",
551
551
  "license": "MIT",
552
552
  "dependencies": {
553
- "@babel/runtime": "^7.29.2",
553
+ "@babel/runtime": "^7.29.7",
554
554
  "fast-unique-numbers": "^9.0.27",
555
555
  "tslib": "^2.8.1"
556
556
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "matterbridge-mqtt",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Matterbridge mqtt plugin",
5
5
  "author": "https://github.com/Luligu",
6
6
  "license": "Apache-2.0",