matterbridge-mqtt 0.0.3 → 0.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/CHANGELOG.md +14 -1
- package/README.md +49 -2
- package/dist/module.js +40 -7
- package/dist/publishTest.js +235 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,20 @@ 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.
|
|
11
|
+
## [0.0.4] - 2026-06-08
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Add `Power Source` device type.
|
|
16
|
+
- Add `Soil Sensor` device type.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Update `README.md`.
|
|
21
|
+
|
|
22
|
+
<a href="https://www.buymeacoffee.com/luligugithub"><img src="https://matterbridge.io/assets/bmc-button.svg" alt="Buy me a coffee" width="80"></a>
|
|
23
|
+
|
|
24
|
+
## [0.0.3] - 2026-06-07
|
|
12
25
|
|
|
13
26
|
- Initial commit (repository reset).
|
|
14
27
|
|
package/README.md
CHANGED
|
@@ -39,7 +39,53 @@ The **matterbridge-mqtt** plugin bridges any MQTT-capable device into the Matter
|
|
|
39
39
|
|
|
40
40
|
# How it works
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
The plugin is configured through the Matterbridge frontend. The settings are stored in `~/.matterbridge/matterbridge-mqtt.config.json`.
|
|
45
|
+
|
|
46
|
+
| Parameter | Default | Description |
|
|
47
|
+
| -------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------ |
|
|
48
|
+
| `host` | `mqtt://localhost` | Broker URL. Use `mqtt://` for plain TCP, `mqtts://` for TLS, `ws://` for WebSocket, `wss://` for secure WebSocket. |
|
|
49
|
+
| `port` | `1883` | Broker port. Common values: `1883` (plain), `8883` (TLS), `9001` (WebSocket). |
|
|
50
|
+
| `protocolVersion` | `5` | MQTT protocol version: `3`, `4` (MQTT 3.1.1), or `5`. |
|
|
51
|
+
| `clientId` | _(auto)_ | Client identifier sent to the broker. Leave empty to let the library generate one. |
|
|
52
|
+
| `username` | _(empty)_ | Username for broker authentication. Leave empty if the broker does not require credentials. |
|
|
53
|
+
| `password` | _(empty)_ | Password for broker authentication. |
|
|
54
|
+
| `ca` | _(empty)_ | Path to the CA certificate file for TLS broker verification. |
|
|
55
|
+
| `cert` | _(empty)_ | Path to the client certificate file for mutual TLS authentication. |
|
|
56
|
+
| `key` | _(empty)_ | Path to the client private key file for mutual TLS authentication. |
|
|
57
|
+
| `rejectUnauthorized` | `true` | Reject brokers with self-signed or untrusted TLS certificates. Set to `false` for self-signed brokers. |
|
|
58
|
+
| `topic` | `matterbridge` | Base topic prefix used for all device topics. |
|
|
59
|
+
|
|
60
|
+
### Minimal configuration example
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"host": "mqtt://192.168.1.10",
|
|
65
|
+
"port": 1883,
|
|
66
|
+
"protocolVersion": 5,
|
|
67
|
+
"topic": "matterbridge"
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### TLS configuration example
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"host": "mqtts://broker.example.com",
|
|
76
|
+
"port": 8883,
|
|
77
|
+
"protocolVersion": 5,
|
|
78
|
+
"ca": "/path/to/ca.crt",
|
|
79
|
+
"cert": "/path/to/client.crt",
|
|
80
|
+
"key": "/path/to/client.key",
|
|
81
|
+
"rejectUnauthorized": true,
|
|
82
|
+
"topic": "matterbridge"
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Topic structure
|
|
87
|
+
|
|
88
|
+
All topics follow the pattern `<topic>/<deviceId>/<subTopic>/root`, where `<topic>` is the configured base topic (default: `matterbridge`) and `<deviceId>` is a stable identifier you choose for each device.
|
|
43
89
|
|
|
44
90
|
## Publish
|
|
45
91
|
|
|
@@ -54,7 +100,7 @@ only the fixed and optional attributes shall be published here
|
|
|
54
100
|
```typescript
|
|
55
101
|
const config = {
|
|
56
102
|
deviceTypes: ['Dimmable Light'],
|
|
57
|
-
clusters: { BridgedDeviceBasicInformation: {
|
|
103
|
+
clusters: { BridgedDeviceBasicInformation: { nodeLabel: 'Light 1', serialNumber: 'xxx-yyy-xxx' }, LevelControl: { onLevel: 128 } },
|
|
58
104
|
};
|
|
59
105
|
publish('matterbridge/light1/config/root', JSON.stringify(config));
|
|
60
106
|
```
|
|
@@ -89,6 +135,7 @@ Payload: "{"cluster":"OnOff","command":"on","request": MatterRequest | undefined
|
|
|
89
135
|
|
|
90
136
|
# Todo
|
|
91
137
|
|
|
138
|
+
- [ ] Add white and black list
|
|
92
139
|
- [ ] Command handler
|
|
93
140
|
- [ ] Attributes handler in config
|
|
94
141
|
- [ ] Add Chapter 8. Entry Control Device Types
|
package/dist/module.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { airQualitySensor, bridgedNode, colorTemperatureLight, contactSensor, dimmableLight, dimmableMountedSwitch, dimmableOutlet, electricalSensor, extendedColorLight, flowSensor, humiditySensor, lightSensor, MatterbridgeDynamicPlatform, MatterbridgeEndpoint, occupancySensor, onOffLight, onOffMountedSwitch, onOffOutlet, powerSource, pressureSensor, pumpDevice, rainSensor, smokeCoAlarm, soilSensor, temperatureSensor, waterFreezeDetector, waterLeakDetector, waterValve, } from 'matterbridge';
|
|
2
2
|
import { debugStringify, info, warn } from 'matterbridge/logger';
|
|
3
|
+
import { SoilMeasurementServer } from 'matterbridge/matter/behaviors';
|
|
4
|
+
import { MeasurementType } from 'matterbridge/matter/types';
|
|
3
5
|
import { fireAndForget, inspectError } from 'matterbridge/utils';
|
|
4
6
|
import { MqttService } from './mqtt.js';
|
|
5
7
|
export default function initializePlugin(matterbridge, log, config) {
|
|
@@ -137,23 +139,54 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
deviceTypes.push(bridgedNode);
|
|
140
|
-
const
|
|
142
|
+
const bridgedDeviceBasicInformationCluster = jsonPayload.clusters.BridgedDeviceBasicInformation || {};
|
|
143
|
+
const powerSourceCluster = jsonPayload.clusters.PowerSource || {};
|
|
141
144
|
const device = new MatterbridgeEndpoint(deviceTypes, {
|
|
142
145
|
id: deviceId,
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
});
|
|
147
|
+
device.createDefaultBridgedDeviceBasicInformationClusterServer(bridgedDeviceBasicInformationCluster.nodeLabel ?? deviceId, bridgedDeviceBasicInformationCluster.serialNumber ?? deviceId, bridgedDeviceBasicInformationCluster.vendorId, bridgedDeviceBasicInformationCluster.vendorName, bridgedDeviceBasicInformationCluster.productName, bridgedDeviceBasicInformationCluster.softwareVersion, bridgedDeviceBasicInformationCluster.softwareVersionString, bridgedDeviceBasicInformationCluster.hardwareVersion, bridgedDeviceBasicInformationCluster.hardwareVersionString);
|
|
148
|
+
if (jsonPayload.deviceTypes.includes('Power Source')) {
|
|
149
|
+
if (powerSourceCluster.batReplacementDescription !== undefined || powerSourceCluster.batQuantity !== undefined) {
|
|
150
|
+
device.createDefaultPowerSourceReplaceableBatteryClusterServer(powerSourceCluster.batPercentRemaining, powerSourceCluster.batChargeLevel, powerSourceCluster.batVoltage, powerSourceCluster.batReplacementDescription, powerSourceCluster.batQuantity, powerSourceCluster.batReplaceability);
|
|
151
|
+
this.log.debug(`Created Power Source Replaceable Battery Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
152
|
+
}
|
|
153
|
+
else if (powerSourceCluster.batChargeState !== undefined || powerSourceCluster.batFunctionalWhileCharging !== undefined) {
|
|
154
|
+
device.createDefaultPowerSourceRechargeableBatteryClusterServer(powerSourceCluster.batPercentRemaining, powerSourceCluster.batChargeLevel, powerSourceCluster.batVoltage, powerSourceCluster.batReplaceability);
|
|
155
|
+
this.log.debug(`Created Power Source Rechargeable Battery Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
156
|
+
}
|
|
157
|
+
else if (powerSourceCluster.batChargeLevel !== undefined || powerSourceCluster.batReplacementNeeded !== undefined || powerSourceCluster.batReplaceability !== undefined) {
|
|
158
|
+
device.createDefaultPowerSourceBatteryClusterServer(powerSourceCluster.batPercentRemaining, powerSourceCluster.batChargeLevel, powerSourceCluster.batVoltage, powerSourceCluster.batReplaceability);
|
|
159
|
+
this.log.debug(`Created Power Source Battery Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
160
|
+
}
|
|
161
|
+
else if (powerSourceCluster.wiredCurrentType !== undefined) {
|
|
162
|
+
device.createDefaultPowerSourceWiredClusterServer(powerSourceCluster.wiredCurrentType);
|
|
163
|
+
this.log.debug(`Created Power Source Wired Cluster for device ${deviceId} with attributes: ${debugStringify(powerSourceCluster)}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (jsonPayload.deviceTypes.includes('Soil Sensor')) {
|
|
167
|
+
device.behaviors.require(SoilMeasurementServer, {
|
|
168
|
+
soilMoistureMeasurementLimits: {
|
|
169
|
+
measurementType: MeasurementType.SoilMoisture,
|
|
170
|
+
measured: true,
|
|
171
|
+
minMeasuredValue: 0,
|
|
172
|
+
maxMeasuredValue: 100,
|
|
173
|
+
accuracyRanges: [{ rangeMin: 0, rangeMax: 100, fixedMax: 1 }],
|
|
174
|
+
},
|
|
175
|
+
soilMoistureMeasuredValue: 50,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
device.addRequiredClusters();
|
|
146
179
|
fireAndForget(this.registerDevice(device), this.log, `Failed to register device ${deviceId}`);
|
|
147
180
|
}
|
|
148
181
|
async updateHandler(topic, payload) {
|
|
149
182
|
const { deviceId, subTopic, endpointName } = this.mqttTopicParser(topic) ?? {};
|
|
150
183
|
if (!deviceId || !subTopic || !endpointName) {
|
|
151
|
-
this.log.warn(`Skipping MQTT message with topic '${topic}' during
|
|
184
|
+
this.log.warn(`Skipping MQTT message with topic '${topic}' during updateHandler because it does not match expected format.`);
|
|
152
185
|
return;
|
|
153
186
|
}
|
|
154
187
|
const device = this.getDeviceById(deviceId);
|
|
155
188
|
if (!device) {
|
|
156
|
-
this.log.warn(`Skipping MQTT message with topic '${topic}' during
|
|
189
|
+
this.log.warn(`Skipping MQTT message with topic '${topic}' during updateHandler because device with ID '${deviceId}' is not registered.`);
|
|
157
190
|
return;
|
|
158
191
|
}
|
|
159
192
|
if (endpointName === 'root') {
|
|
@@ -164,7 +197,7 @@ export class MqttPlatform extends MatterbridgeDynamicPlatform {
|
|
|
164
197
|
device.log.warn(`Device '${deviceId}' does not have cluster '${cluster}' defined. Skipping cluster configuration for this cluster.`);
|
|
165
198
|
continue;
|
|
166
199
|
}
|
|
167
|
-
await device.setCluster(cluster, parsedPayload[cluster]);
|
|
200
|
+
await device.setCluster(cluster, parsedPayload[cluster], device.log);
|
|
168
201
|
}
|
|
169
202
|
}
|
|
170
203
|
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { PowerSource } from 'matterbridge/matter/clusters';
|
|
5
|
+
import { connectAsync } from 'mqtt';
|
|
6
|
+
const configPath = path.join(homedir(), '.matterbridge', 'matterbridge-mqtt.config.json');
|
|
7
|
+
let config;
|
|
8
|
+
try {
|
|
9
|
+
config = JSON.parse(readFileSync(configPath, 'utf8'));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
console.error(`Config file not found or invalid: ${configPath}`);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
const baseTopic = config.topic ?? 'matterbridge';
|
|
16
|
+
const DEVICES = [
|
|
17
|
+
{
|
|
18
|
+
id: 'test-power-source',
|
|
19
|
+
name: 'Power Source',
|
|
20
|
+
deviceTypes: ['Power Source'],
|
|
21
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200, batVoltage: 3000 } },
|
|
22
|
+
state: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Warning, batPercentRemaining: 150, batVoltage: 2800 } },
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 'test-electrical-sensor',
|
|
26
|
+
name: 'Electrical Sensor',
|
|
27
|
+
deviceTypes: ['Electrical Sensor'],
|
|
28
|
+
configClusters: {},
|
|
29
|
+
state: { ElectricalPowerMeasurement: { activePower: 1200, voltage: 2300, activeCurrent: 520 } },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'test-onoff-light',
|
|
33
|
+
name: 'OnOff Light',
|
|
34
|
+
deviceTypes: ['OnOff Light', 'Power Source'],
|
|
35
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
36
|
+
state: { OnOff: { onOff: false } },
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'test-dimmable-light',
|
|
40
|
+
name: 'Dimmable Light',
|
|
41
|
+
deviceTypes: ['Dimmable Light', 'Power Source'],
|
|
42
|
+
configClusters: { LevelControl: { onLevel: 128 }, PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
43
|
+
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 128 } },
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: 'test-color-temp-light',
|
|
47
|
+
name: 'Color Temperature Light',
|
|
48
|
+
deviceTypes: ['Color Temperature Light', 'Power Source'],
|
|
49
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
50
|
+
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { colorTemperatureMireds: 370 } },
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 'test-extended-color-light',
|
|
54
|
+
name: 'Extended Color Light',
|
|
55
|
+
deviceTypes: ['Extended Color Light', 'Power Source'],
|
|
56
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
57
|
+
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 }, ColorControl: { currentHue: 128, currentSaturation: 200 } },
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 'test-onoff-plugin-unit',
|
|
61
|
+
name: 'OnOff Plugin Unit',
|
|
62
|
+
deviceTypes: ['OnOff Plugin Unit', 'Power Source'],
|
|
63
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
64
|
+
state: { OnOff: { onOff: false } },
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'test-dimmable-plugin-unit',
|
|
68
|
+
name: 'Dimmable PlugIn Unit',
|
|
69
|
+
deviceTypes: ['Dimmable PlugIn Unit', 'Power Source'],
|
|
70
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
71
|
+
state: { OnOff: { onOff: true }, LevelControl: { currentLevel: 200 } },
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'test-mounted-onoff-control',
|
|
75
|
+
name: 'Mounted OnOff Control',
|
|
76
|
+
deviceTypes: ['Mounted OnOff Control', 'Power Source'],
|
|
77
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
78
|
+
state: { OnOff: { onOff: false } },
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
id: 'test-mounted-dimmable-control',
|
|
82
|
+
name: 'Mounted Dimmable Load Control',
|
|
83
|
+
deviceTypes: ['Mounted Dimmable Load Control', 'Power Source'],
|
|
84
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
85
|
+
state: { OnOff: { onOff: false }, LevelControl: { currentLevel: 100 } },
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
id: 'test-pump',
|
|
89
|
+
name: 'Pump',
|
|
90
|
+
deviceTypes: ['Pump', 'Power Source'],
|
|
91
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
92
|
+
state: { OnOff: { onOff: false }, PumpConfigurationAndControl: { effectiveOperationMode: 0, effectiveControlMode: 0 } },
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
id: 'test-water-valve',
|
|
96
|
+
name: 'Water Valve',
|
|
97
|
+
deviceTypes: ['Water Valve', 'Power Source'],
|
|
98
|
+
configClusters: { PowerSource: { wiredCurrentType: PowerSource.WiredCurrentType.Ac } },
|
|
99
|
+
state: { ValveConfigurationAndControl: { currentState: 0, targetState: 0 } },
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
id: 'test-contact-sensor',
|
|
103
|
+
name: 'Contact Sensor',
|
|
104
|
+
deviceTypes: ['Contact Sensor', 'Power Source'],
|
|
105
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
106
|
+
state: { BooleanState: { stateValue: false } },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'test-light-sensor',
|
|
110
|
+
name: 'Light Sensor',
|
|
111
|
+
deviceTypes: ['Light Sensor', 'Power Source'],
|
|
112
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
113
|
+
state: { IlluminanceMeasurement: { measuredValue: 10000 } },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'test-occupancy-sensor',
|
|
117
|
+
name: 'Occupancy Sensor',
|
|
118
|
+
deviceTypes: ['Occupancy Sensor', 'Power Source'],
|
|
119
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
120
|
+
state: { OccupancySensing: { occupancy: { occupied: false } } },
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'test-temperature-sensor',
|
|
124
|
+
name: 'Temperature Sensor',
|
|
125
|
+
deviceTypes: ['Temperature Sensor', 'Power Source'],
|
|
126
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 180 } },
|
|
127
|
+
state: { TemperatureMeasurement: { measuredValue: 2100 } },
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: 'test-pressure-sensor',
|
|
131
|
+
name: 'Pressure Sensor',
|
|
132
|
+
deviceTypes: ['Pressure Sensor', 'Power Source'],
|
|
133
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 160 } },
|
|
134
|
+
state: { PressureMeasurement: { measuredValue: 1013 } },
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'test-flow-sensor',
|
|
138
|
+
name: 'Flow Sensor',
|
|
139
|
+
deviceTypes: ['Flow Sensor', 'Power Source'],
|
|
140
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 140 } },
|
|
141
|
+
state: { FlowMeasurement: { measuredValue: 100 } },
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
id: 'test-humidity-sensor',
|
|
145
|
+
name: 'Humidity Sensor',
|
|
146
|
+
deviceTypes: ['Humidity Sensor', 'Power Source'],
|
|
147
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 130 } },
|
|
148
|
+
state: { RelativeHumidityMeasurement: { measuredValue: 5500 } },
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 'test-smoke-co-alarm',
|
|
152
|
+
name: 'Smoke CO Alarm',
|
|
153
|
+
deviceTypes: ['Smoke CO Alarm', 'Power Source'],
|
|
154
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
155
|
+
state: { SmokeCoAlarm: { smokeState: 0, coState: 0 } },
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 'test-air-quality-sensor',
|
|
159
|
+
name: 'Air Quality Sensor',
|
|
160
|
+
deviceTypes: ['Air Quality Sensor', 'Power Source'],
|
|
161
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 200 } },
|
|
162
|
+
state: { AirQuality: { airQuality: 1 } },
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: 'test-water-freeze-detector',
|
|
166
|
+
name: 'Water Freeze Detector',
|
|
167
|
+
deviceTypes: ['Water Freeze Detector', 'Power Source'],
|
|
168
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 170 } },
|
|
169
|
+
state: { BooleanState: { stateValue: false } },
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
id: 'test-water-leak-detector',
|
|
173
|
+
name: 'Water Leak Detector',
|
|
174
|
+
deviceTypes: ['Water Leak Detector', 'Power Source'],
|
|
175
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 150 } },
|
|
176
|
+
state: { BooleanState: { stateValue: false } },
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
id: 'test-rain-sensor',
|
|
180
|
+
name: 'Rain Sensor',
|
|
181
|
+
deviceTypes: ['Rain Sensor', 'Power Source'],
|
|
182
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 160 } },
|
|
183
|
+
state: { BooleanState: { stateValue: false } },
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: 'test-soil-sensor',
|
|
187
|
+
name: 'Soil Sensor',
|
|
188
|
+
deviceTypes: ['Soil Sensor', 'Power Source'],
|
|
189
|
+
configClusters: { PowerSource: { batChargeLevel: PowerSource.BatChargeLevel.Ok, batPercentRemaining: 140 } },
|
|
190
|
+
state: { SoilMeasurement: { soilMoistureMeasuredValue: 60 } },
|
|
191
|
+
},
|
|
192
|
+
];
|
|
193
|
+
const clientOptions = {
|
|
194
|
+
port: config.port,
|
|
195
|
+
protocolVersion: config.protocolVersion,
|
|
196
|
+
rejectUnauthorized: config.rejectUnauthorized,
|
|
197
|
+
};
|
|
198
|
+
if (config.clientId)
|
|
199
|
+
clientOptions.clientId = config.clientId;
|
|
200
|
+
if (config.username)
|
|
201
|
+
clientOptions.username = config.username;
|
|
202
|
+
if (config.password)
|
|
203
|
+
clientOptions.password = config.password;
|
|
204
|
+
if (config.ca)
|
|
205
|
+
clientOptions.ca = readFileSync(config.ca);
|
|
206
|
+
if (config.cert)
|
|
207
|
+
clientOptions.cert = readFileSync(config.cert);
|
|
208
|
+
if (config.key)
|
|
209
|
+
clientOptions.key = readFileSync(config.key);
|
|
210
|
+
console.log(`Connecting to ${config.host}:${config.port} (protocol v${config.protocolVersion}) ...`);
|
|
211
|
+
const client = await connectAsync(config.host, clientOptions);
|
|
212
|
+
console.log(`Connected. Publishing to base topic "${baseTopic}".\n`);
|
|
213
|
+
const pubOptions = { retain: true, qos: 2 };
|
|
214
|
+
for (const device of DEVICES) {
|
|
215
|
+
const configPayload = JSON.stringify({
|
|
216
|
+
deviceTypes: device.deviceTypes,
|
|
217
|
+
clusters: {
|
|
218
|
+
BridgedDeviceBasicInformation: {
|
|
219
|
+
nodeLabel: device.name,
|
|
220
|
+
serialNumber: `TEST-${device.id}`,
|
|
221
|
+
},
|
|
222
|
+
...device.configClusters,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
const statePayload = JSON.stringify(device.state);
|
|
226
|
+
const configTopic = `${baseTopic}/${device.id}/config/root`;
|
|
227
|
+
const stateTopic = `${baseTopic}/${device.id}/state/root`;
|
|
228
|
+
await client.publishAsync(configTopic, configPayload, pubOptions);
|
|
229
|
+
await client.publishAsync(stateTopic, statePayload, pubOptions);
|
|
230
|
+
console.log(`[${device.name}]`);
|
|
231
|
+
console.log(` config → ${configTopic}`);
|
|
232
|
+
console.log(` state → ${stateTopic}`);
|
|
233
|
+
}
|
|
234
|
+
await client.endAsync();
|
|
235
|
+
console.log(`\nDone. Published config + state for ${DEVICES.length} device(s).`);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matterbridge-mqtt",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "matterbridge-mqtt",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.4",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"mqtt": "5.15.1",
|