matterbridge-mqtt-gateway 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/README.md ADDED
@@ -0,0 +1,254 @@
1
+ # matterbridge-mqtt-gateway
2
+
3
+ > Plugin [Matterbridge](https://github.com/Luligu/matterbridge) qui expose des **topics MQTT comme des appareils Matter virtuels**.
4
+
5
+ Idéal pour piloter des équipements via **Node-RED** (ou tout autre client MQTT) depuis Apple Home, Google Home, Amazon Alexa, Home Assistant, etc.
6
+
7
+ ---
8
+
9
+ ## Fonctionnement
10
+
11
+ ```
12
+ [Matter Controller] [matterbridge-mqtt-gateway] [MQTT Broker] [Node-RED]
13
+ Apple Home ──ON──► commandTopic publish ──► home/plug1/set ──► mqtt-in node
14
+ Google Home ◄──ON── stateTopic subscribe ◄── home/plug1/state ◄── mqtt-out node
15
+ ```
16
+
17
+ Le plugin joue un **double rôle** :
18
+ - **Matter → MQTT** : quand un contrôleur Matter envoie une commande (ON, OFF, niveau…), le plugin publie sur le `commandTopic` configuré.
19
+ - **MQTT → Matter** : quand un message arrive sur le `stateTopic`, le plugin met à jour l'état de l'appareil virtuel Matter (utile pour refléter une action physique ou une règle Node-RED).
20
+
21
+ ---
22
+
23
+ ## Types d'appareils supportés
24
+
25
+ | `type` | Appareil Matter | Clusters Matter |
26
+ |------------------|-----------------------------|------------------------------|
27
+ | `outlet` | Prise commandée | OnOff |
28
+ | `switch` | Interrupteur | OnOff |
29
+ | `light` | Ampoule dimmable | OnOff + LevelControl |
30
+ | `colorlight` | Ampoule couleur/CT | OnOff + Level + ColorControl |
31
+ | `contact_sensor` | Capteur d'ouverture | BooleanState |
32
+ | `temperature` | Capteur de température | TemperatureMeasurement |
33
+ | `humidity` | Capteur d'humidité | RelativeHumidityMeasurement |
34
+ | `occupancy` | Détecteur de présence | OccupancySensing |
35
+
36
+ ---
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ # Dans votre répertoire Matterbridge
42
+ cd ~/Matterbridge
43
+ npm install -g /chemin/vers/matterbridge-mqtt-gateway
44
+ matterbridge -add matterbridge-mqtt-gateway
45
+ matterbridge
46
+ ```
47
+
48
+ Ou en développement local :
49
+
50
+ ```bash
51
+ git clone <repo> matterbridge-mqtt-gateway
52
+ cd matterbridge-mqtt-gateway
53
+ npm install
54
+ npm run build
55
+ npm link
56
+ matterbridge -add matterbridge-mqtt-gateway
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Configuration
62
+
63
+ Éditez la config via le **frontend Matterbridge** (recommandé) ou directement dans `~/.matterbridge/matterbridge-mqtt-gateway.config.json`.
64
+
65
+ ### Paramètres globaux
66
+
67
+ | Paramètre | Type | Défaut | Description |
68
+ |-------------|--------|----------------------|------------------------------------------|
69
+ | `host` | string | `mqtt://localhost` | URL du broker MQTT (mqtt://, mqtts://) |
70
+ | `port` | number | `1883` | Port TCP du broker |
71
+ | `username` | string | `""` | Identifiant MQTT (optionnel) |
72
+ | `password` | string | `""` | Mot de passe MQTT (optionnel) |
73
+ | `clientId` | string | auto-généré | ClientId MQTT |
74
+ | `debug` | bool | `false` | Logs détaillés (topics, payloads) |
75
+ | `devices` | array | `[]` | Liste des appareils virtuels (voir ci-dessous) |
76
+
77
+ ### Paramètres par appareil
78
+
79
+ | Paramètre | Type | Défaut | Applicable à |
80
+ |---------------------------|--------|----------|-----------------------|
81
+ | `id` | string | — | Tous (obligatoire, unique) |
82
+ | `name` | string | — | Tous (obligatoire) |
83
+ | `type` | string | `outlet` | Tous |
84
+ | `stateTopic` | string | — | Tous |
85
+ | `commandTopic` | string | — | outlet, switch, light, colorlight |
86
+ | `payloadOn` | string | `ON` | outlet, switch, light, colorlight, occupancy |
87
+ | `payloadOff` | string | `OFF` | outlet, switch, light, colorlight |
88
+ | `retain` | bool | `false` | outlet, switch, light, colorlight |
89
+ | `brightnessStateTopic` | string | — | light, colorlight |
90
+ | `brightnessCommandTopic` | string | — | light, colorlight |
91
+ | `colorStateTopic` | string | — | colorlight |
92
+ | `colorCommandTopic` | string | — | colorlight |
93
+ | `payloadOpen` | string | `OPEN` | contact_sensor |
94
+ | `payloadClosed` | string | `CLOSED` | contact_sensor |
95
+
96
+ ---
97
+
98
+ ## Exemples de configuration
99
+
100
+ ### Config complète
101
+
102
+ ```json
103
+ {
104
+ "name": "matterbridge-mqtt-gateway",
105
+ "host": "mqtt://192.168.1.10",
106
+ "port": 1883,
107
+ "username": "user",
108
+ "password": "secret",
109
+ "debug": false,
110
+ "devices": [
111
+ {
112
+ "id": "plug_salon",
113
+ "name": "Prise Salon",
114
+ "type": "outlet",
115
+ "stateTopic": "home/plug/salon/state",
116
+ "commandTopic": "home/plug/salon/set",
117
+ "payloadOn": "ON",
118
+ "payloadOff": "OFF"
119
+ },
120
+ {
121
+ "id": "light_bureau",
122
+ "name": "Lampe Bureau",
123
+ "type": "light",
124
+ "stateTopic": "home/light/bureau/state",
125
+ "commandTopic": "home/light/bureau/set",
126
+ "brightnessStateTopic": "home/light/bureau/brightness",
127
+ "brightnessCommandTopic": "home/light/bureau/brightness/set"
128
+ },
129
+ {
130
+ "id": "led_salon",
131
+ "name": "LED Salon",
132
+ "type": "colorlight",
133
+ "stateTopic": "home/led/salon/state",
134
+ "commandTopic": "home/led/salon/set",
135
+ "brightnessStateTopic": "home/led/salon/brightness",
136
+ "brightnessCommandTopic": "home/led/salon/brightness/set",
137
+ "colorStateTopic": "home/led/salon/color",
138
+ "colorCommandTopic": "home/led/salon/color/set"
139
+ },
140
+ {
141
+ "id": "temp_salon",
142
+ "name": "Température Salon",
143
+ "type": "temperature",
144
+ "stateTopic": "home/sensor/salon/temperature"
145
+ },
146
+ {
147
+ "id": "hum_salon",
148
+ "name": "Humidité Salon",
149
+ "type": "humidity",
150
+ "stateTopic": "home/sensor/salon/humidity"
151
+ },
152
+ {
153
+ "id": "porte_garage",
154
+ "name": "Porte Garage",
155
+ "type": "contact_sensor",
156
+ "stateTopic": "home/garage/porte",
157
+ "payloadOpen": "OPEN",
158
+ "payloadClosed": "CLOSED"
159
+ },
160
+ {
161
+ "id": "pir_couloir",
162
+ "name": "Présence Couloir",
163
+ "type": "occupancy",
164
+ "stateTopic": "home/pir/couloir"
165
+ }
166
+ ]
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Format des payloads MQTT
173
+
174
+ ### Commande ON/OFF (stateTopic et commandTopic)
175
+
176
+ Le plugin accepte les formats suivants en entrée (stateTopic) :
177
+
178
+ | Format MQTT | Interprétation |
179
+ |---------------------------|----------------|
180
+ | `ON` / `OFF` | Standard |
181
+ | `1` / `0` | Numérique |
182
+ | `true` / `false` | Booléen |
183
+ | `{"state":"ON"}` | JSON |
184
+ | `{"value":1}` | JSON |
185
+ | `{"power":"ON"}` | JSON |
186
+
187
+ En sortie (commandTopic), le plugin publie le `payloadOn` / `payloadOff` tel que configuré (défaut `ON` / `OFF`).
188
+
189
+ ### Température (stateTopic)
190
+
191
+ | Format MQTT | Exemple |
192
+ |---------------------------|----------------|
193
+ | Float en °C | `21.5` |
194
+ | JSON avec clé temperature | `{"temperature":21.5}` |
195
+ | JSON avec clé temp | `{"temp":21.5}` |
196
+ | JSON avec clé value | `{"value":21.5}` |
197
+
198
+ ### Luminosité (brightnessStateTopic / brightnessCommandTopic)
199
+
200
+ - **Entrée** : 0–100 (%) ou 0–254 (Matter level)
201
+ - **Sortie** : 0–100 (%)
202
+
203
+ ### Couleur (colorStateTopic / colorCommandTopic)
204
+
205
+ - **Entrée/Sortie JSON** : `{"hue": 240, "saturation": 100}` (hue 0–360°, sat 0–100%)
206
+ - **Température de couleur JSON** : `{"colorTemp": 370}` (mireds 153–500)
207
+
208
+ ---
209
+
210
+ ## Exemple Node-RED
211
+
212
+ ### Recevoir une commande Matter (ON/OFF) et agir
213
+
214
+ ```json
215
+ [mqtt-in: topic=home/plug/salon/set] → [switch: msg.payload === "ON"] → [action]
216
+ ```
217
+
218
+ ### Mettre à jour l'état Matter depuis Node-RED
219
+
220
+ ```json
221
+ [trigger ou inject] → [function: msg.payload = "ON"] → [mqtt-out: topic=home/plug/salon/state]
222
+ ```
223
+
224
+ ### Remonter la température d'un capteur
225
+
226
+ ```json
227
+ [capteur physique] → [function: msg.payload = temperature_value.toString()] → [mqtt-out: topic=home/sensor/salon/temperature]
228
+ ```
229
+
230
+ ---
231
+
232
+ ## Dépannage
233
+
234
+ | Problème | Solution |
235
+ |----------|----------|
236
+ | L'appareil n'apparaît pas dans Apple Home | Attendre ~30s après le démarrage, ou re-scanner le QR code Matterbridge |
237
+ | L'état ne se met pas à jour | Vérifier le `stateTopic` et le format du payload avec un client MQTT (mosquitto_sub) |
238
+ | La commande ne part pas | Activer `debug: true` dans la config et vérifier les logs Matterbridge |
239
+ | Erreur de connexion MQTT | Vérifier host, port, username, password |
240
+
241
+ ---
242
+
243
+ ## Développement
244
+
245
+ ```bash
246
+ npm run build # Compile TypeScript → dist/
247
+ npm run build:watch # Compilation continue
248
+ ```
249
+
250
+ ---
251
+
252
+ ## Licence
253
+
254
+ MIT
@@ -0,0 +1,3 @@
1
+ import { MqttPlatform } from './platform.js';
2
+ export default function (matterbridge: any, log: any, config: any): MqttPlatform;
3
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { MqttPlatform } from './platform.js';
2
+ export default function (matterbridge, log, config) {
3
+ return new MqttPlatform(matterbridge, log, config);
4
+ }
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * matterbridge-mqtt-gateway — MqttPlatform
3
+ * Compatible Matterbridge v3.x
4
+ */
5
+ import { MatterbridgeDynamicPlatform } from 'matterbridge';
6
+ import type { PlatformMatterbridge, PlatformConfig } from 'matterbridge';
7
+ import { AnsiLogger } from 'node-ansi-logger';
8
+ export declare class MqttPlatform extends MatterbridgeDynamicPlatform {
9
+ private mqttClient;
10
+ private topicHandlers;
11
+ private endpointMap;
12
+ constructor(matterbridge: PlatformMatterbridge, log: AnsiLogger, config: PlatformConfig);
13
+ onStart(reason?: string): Promise<void>;
14
+ onConfigure(): Promise<void>;
15
+ onShutdown(reason?: string): Promise<void>;
16
+ private connectMqtt;
17
+ private subscribe;
18
+ private publish;
19
+ private getAttr;
20
+ private setAttr;
21
+ private initEp;
22
+ private onCmd;
23
+ private createDevice;
24
+ private createOnOff;
25
+ private createDimmable;
26
+ private createColor;
27
+ private createContact;
28
+ private createTemp;
29
+ private createHumidity;
30
+ private createCover;
31
+ private createStove;
32
+ private createOccupancy;
33
+ private parseOnOff;
34
+ }
35
+ //# sourceMappingURL=platform.d.ts.map