matterbridge-open-tuya 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Matterbridge Open Tuya changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.1.0] - 2026-11-01
8
+
9
+ ### Added
10
+
11
+ - [devices]: Control Tuya switches, plugs, power strips and sensors from Matter, built on open-tuya 0.3.1 and its device catalog: each outlet, the power and the energy of a device that measures them, the temperature, humidity, light, motion, contact and water leak sensors, the battery, and optional switches for settings such as the child lock and the light of the buttons.
12
+ - [devices]: Reach each device on the LAN first, found by the discovery or at a host given, and through the Tuya cloud otherwise, and the devices behind a gateway through the gateway.
13
+ - [setup]: Sign in by scanning a QR code with the Smart Life app, or with a cloud project of the Tuya developer platform.
14
+ - [setup]: Add the guided setup page: find the devices of the account, check each one, and choose its name and how it appears in Matter.
15
+ - [setup]: Name the controls of a sensor whose product the catalog does not list by the Tuya cloud's model of the device, before matching the catalog by its data points alone, which took a motion sensor for a water leak sensor.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,176 @@
1
- # Temporary Holding Version
1
+ # Matterbridge Open Tuya
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
+ [![npm version](https://img.shields.io/npm/v/matterbridge-open-tuya.svg)](https://www.npmjs.com/package/matterbridge-open-tuya)
4
+ [![npm downloads](https://img.shields.io/npm/dt/matterbridge-open-tuya.svg)](https://www.npmjs.com/package/matterbridge-open-tuya)
5
+ [![Node.js CI](https://github.com/cheziyi/matterbridge-open-tuya/actions/workflows/build.yml/badge.svg)](https://github.com/cheziyi/matterbridge-open-tuya/actions/workflows/build.yml)
6
+ [![CodeQL](https://github.com/cheziyi/matterbridge-open-tuya/actions/workflows/codeql.yml/badge.svg)](https://github.com/cheziyi/matterbridge-open-tuya/actions/workflows/codeql.yml)
7
+ [![codecov](https://codecov.io/gh/cheziyi/matterbridge-open-tuya/branch/main/graph/badge.svg)](https://codecov.io/gh/cheziyi/matterbridge-open-tuya)
8
+ [![license](https://img.shields.io/npm/l/matterbridge-open-tuya.svg)](./LICENSE)
9
+
10
+ [![powered by](https://img.shields.io/badge/powered%20by-matterbridge-blue)](https://www.npmjs.com/package/matterbridge)
11
+ [![powered by](https://img.shields.io/badge/powered%20by-open--tuya-blue)](https://www.npmjs.com/package/open-tuya)
12
+
13
+ Control your Tuya smart plugs, power strips, wall switches and sensors from Apple Home, Google Home, Alexa, Home Assistant and other Matter apps.
14
+
15
+ It is a [Matterbridge](https://matterbridge.io) plugin built on [open-tuya](https://www.npmjs.com/package/open-tuya), which reaches each device on your local network first, and through the Tuya cloud when it does not answer there. It names what each device does from open-tuya's catalog of over 1,700 devices converted from [tuya-local](https://github.com/make-all/tuya-local): see its [coverage and limitations](https://github.com/cheziyi/open-tuya#coverage-and-limitations).
16
+
17
+ ## Why this plugin
18
+
19
+ - **It finds your devices for you.** Sign in once in the setup page, by scanning a QR code with the Smart Life app or with a cloud project of the Tuya developer platform, and it lists every device of your account, with whether it can control each one. There is no local key, device ID or configuration file to look up: see [Guided setup](#guided-setup).
20
+ - **It talks to your devices on your network.** Each device is reached on the local network first, with the local key the cloud gives for it, which answers quicker and keeps working while the Tuya cloud or the internet is down, and through the Tuya cloud when it does not answer there: see [Connection](#connection).
21
+ - **It reaches the devices behind a gateway.** A Zigbee or Bluetooth device behind a Tuya gateway is reached through the gateway on your network, and through the cloud otherwise.
22
+ - **It offers only what your device can do.** The plugin reads what each device does from its catalog entry: each outlet of a power strip, the power and the energy of a plug that measures them, the temperature, the humidity, the light, the motion, the contact or the water leak of a sensor, its battery, and settings such as its child lock or the light of its buttons.
23
+ - **It says when a device stops answering.** After two reads in a row fail, as they do while the Tuya cloud lists a device reached through it as offline, your Matter app shows the device as unreachable, and it comes back by itself as soon as the device answers again.
24
+ - **Almost nothing needs a restart.** Sign in, add, rename, reconnect and remove devices while Matterbridge keeps running. Only a change of how a device appears in Matter waits for the next restart, which the setup page and Matterbridge ask for.
25
+
26
+ ## Requirements
27
+
28
+ - Matterbridge 3.10.10 or later.
29
+ - Node.js 22.13 or later (22, 24 or 26).
30
+ - Your devices added to the Smart Life or Tuya Smart app, and one of:
31
+ - **The Smart Life or Tuya Smart app**, to sign in by scanning a QR code. Nothing else is needed.
32
+ - **A cloud project of the [Tuya developer platform](https://platform.tuya.com)**, with your app account linked to it under Devices > Link App Account, and its Access ID and Access Secret. Its IoT Core trial expires and has to be extended now and then.
33
+ - A route to the internet, to sign in and read the device list of the account. A device on the same network as Matterbridge is reached there, and through the Tuya cloud otherwise.
34
+
35
+ ## Installation
36
+
37
+ In the Matterbridge frontend, type `matterbridge-open-tuya` in the **Install plugins** field and click **Install**, then restart Matterbridge.
38
+
39
+ From the command line instead:
40
+
41
+ ```bash
42
+ npm install -g matterbridge-open-tuya
43
+ matterbridge --add matterbridge-open-tuya
44
+ ```
45
+
46
+ Then set up your devices in the plugin's own page: see [Guided setup](#guided-setup).
47
+
48
+ ## Guided setup
49
+
50
+ Open the plugin frontend from the plugin's row on the Matterbridge home page. The first time, it asks you to sign in, one of two ways:
51
+
52
+ - **With the Smart Life app.** Enter the User Code the app shows under Me > Settings > Account and Security > User Code. The page shows a QR code: scan it with the app, from the scan button of its home tab, and confirm the sign in there. The QR code lasts a few minutes, and the page asks for a new one once it expires. The plugin signs in with the client ID of Home Assistant's Tuya integration, the only one known to work.
53
+ - **With the Tuya developer platform.** Enter the Access ID and the Access Secret of your cloud project, and the data center it is in. The plugin lists the devices of the project before it stores it.
54
+
55
+ Then it walks through three steps:
56
+
57
+ 1. **Find.** The page lists the devices of your account and marks those already set up. It says why it cannot control one: a kind of device it does not control yet, such as a light or a fan, or a gateway, whose devices are listed on their own. A device whose product the catalog does not list can still be picked: the next step reads what the Tuya cloud says of it.
58
+ 2. **Connect.** For each device you picked, the plugin reads it, on your network first and through the Tuya cloud otherwise, and finds what its data points do: from the catalog entry of its product, else from the Tuya cloud's model of a motion, presence, contact, water leak or temperature and humidity sensor, which names each data point by Tuya's standard codes, such as `temp_current`, else from the catalog entry that names most of the data points it reports. The model comes before that last match, which cannot tell apart two devices that report the same data points, such as a motion sensor and a water leak sensor.
59
+ 3. **Options.** The name the device gets in Matter, starting from its name in the Smart Life app, which of its outlets, its sensors, its meter and its setting switches appear in Matter, and whether they are one device or several. Last, whether it is reached on your network first or through the Tuya cloud only, and, only for a network the plugin does not hear it on, a host and a protocol version, which most devices leave empty: see [Connection](#connection).
60
+
61
+ Afterwards the same page lists your devices with their status: online on your network or through the Tuya cloud, connecting, not answering, or not started, and what they last reported. From there you can add more, change the options of one, reconnect one that stopped answering, remove one, switch to another account, sign in again when the Tuya cloud no longer accepts the sign in, or sign out. Matterbridge's own list of devices shows a device added or removed here once you reload its page, named after its device ID, such as `Tuya bf1234567890abcdefgh`: the name you give it is what the Matter apps show.
62
+
63
+ ## How a device appears in Matter
64
+
65
+ The plugin controls the devices whose catalog entry is a switch, a plug, a power strip or a sensor, with the lights of their buttons or their display. A light, a fan, a thermostat, a cover, a lock, a vacuum and the other kinds of the catalog are not controlled yet.
66
+
67
+ | In Matter | From the device |
68
+ | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------- |
69
+ | Outlet | Each switch of its main function: the plug, each outlet of a power strip, each gang of a wall switch, its USB ports |
70
+ | Electrical power and energy | The power, the voltage, the current and the energy used so far, on the first outlet of a device that measures them |
71
+ | Temperature sensor | Its temperature, in °C or °F |
72
+ | Humidity sensor | Its relative humidity |
73
+ | Light sensor | Its illuminance |
74
+ | Occupancy sensor | The motion or the presence it detects |
75
+ | Contact sensor | Whether its door or window is open |
76
+ | Water leak detector | Whether it detects water |
77
+ | Battery | The charge of its battery, as the power source of the device |
78
+ | Outlet, for a setting, when chosen | Each on/off setting, such as the child lock or the light of its buttons or its display |
79
+
80
+ The first outlet, or the first sensor of a device without one, is the device itself: it is always there. Every other outlet and sensor, and the meter, can be left out in the options. A setting switch is left out unless you choose it.
81
+
82
+ ### How it is built in Matter
83
+
84
+ Matter describes a device as endpoints. Each endpoint has one or more device types, which say what it is, and clusters, which hold its attributes and commands. Each device is one device: an endpoint for its first outlet or its first sensor, with every other outlet, sensor or setting switch as a part of it, on an endpoint of its own:
85
+
86
+ ```mermaid
87
+ flowchart TD
88
+ bridge["Matterbridge<br/>Aggregator"]
89
+ subgraph device["One device in a Matter app"]
90
+ main["<b>Desk Plug</b><br/>On/Off Plug-in Unit, or the sensor of a device without an outlet, Bridged Node, Power Source<br/>On/Off, and Electrical Sensor with Power Topology, Electrical Power and Electrical Energy Measurement on a device that measures them<br/>Power Source wired, or with the charge of its battery"]
91
+ outlets["On/Off Plug-in Unit, one for each other outlet and each setting switch<br/>tagged 1 Outlet 2, 2 Outlet 3 and so on<br/>On/Off"]
92
+ sensors["Temperature, Humidity, Light, Occupancy, Contact Sensor or Water Leak Detector, one for each other reading<br/>Temperature, Relative Humidity, Illuminance Measurement, Occupancy Sensing or Boolean State"]
93
+ end
94
+ bridge --> main
95
+ main -.-> outlets
96
+ main -.-> sensors
97
+ ```
98
+
99
+ ### One device or several
100
+
101
+ The setup page makes each of a device's other outlets, sensors and switches a device of its own by default, named after the device and what it is, such as `Desk Strip Outlet 2`, since a Matter app may show the parts of a device poorly. Tick **Show it as one device** in its options to make them parts of the device instead, what Matter calls a composed device: they move between the rooms of a Matter app with it, and are unreachable when it is.
102
+
103
+ ## Connection
104
+
105
+ Each device runs a server of its own on your network, which the Smart Life app talks to when it is on the same network. The plugin connects to it first, and to the Tuya cloud when it does not answer, as [open-tuya](https://github.com/cheziyi/open-tuya#reaching-a-device) does:
106
+
107
+ - **The discovery.** A device broadcasts its address and its protocol version every few seconds on UDP ports 6666, 6667 and 7000. The plugin listens there all the time, and follows a device its router gives a new address. It hears only the broadcasts of its own subnets: a Docker container on the default bridge network hears none, so run Matterbridge with `--network host`, or enter the host and the protocol version of the device in its options, ideally an address your router keeps for it. Another program that holds one of the ports without sharing it, such as an old tinytuya, stops the discovery: the setup page says so.
108
+ - **The local key.** The device list of the account gives the local key of each device, which encrypts its traffic on your network. It is stored with the device, never shown in the setup page, and read again from the cloud every 15 minutes, so that a device paired again in the app gets its new one.
109
+ - **The address.** The address each device was last heard at is kept across restarts, so a device is reached on your network as soon as Matterbridge starts. A device heard for the first time after it started gets its route on your network then, without a restart.
110
+ - **The fallback.** Each read and each command tries your network first, while the device is connected there, and the Tuya cloud otherwise. A command that may have reached the device, such as one that timed out, is not sent again through the cloud. A read through the cloud of a device the cloud lists as offline fails rather than answer with what the device last reported, so an unplugged device shows as unreachable through the cloud too: at once when the cloud pushes that it went offline, or at the next read of the device list, every 15 minutes.
111
+ - **The gateway.** A device behind a gateway, such as a Zigbee sensor, is reached through the gateway on your network, with the gateway's local key, and through the cloud otherwise. One connection to the gateway serves every device behind it, and the gateway itself when it is a device of its own, such as one with a switch. Where the plugin does not hear the gateway, enter the host and the protocol version of the gateway in the options of a device behind it. Every device behind the gateway then uses that address, and where several give one, the first in the list decides.
112
+ - **The cloud only.** A device can be set to the Tuya cloud alone in its options, for a device that is never on the network of Matterbridge.
113
+ - **Without an account.** A device keeps working on your network when you sign out, or when the Tuya cloud is down, with the local key stored for it. It needs an account again for the cloud, and to get a new local key.
114
+
115
+ The setup page shows whether each device is online on your network or through the Tuya cloud, and the log says which one it answers through when that changes.
116
+
117
+ ## How devices are stored
118
+
119
+ The plugin stores the account and the devices in its own storage, apart from the configuration Matterbridge's config editor shows, so that no secret reaches that editor. The account is the session of the Smart Life sign in, which the plugin refreshes and stores again as the cloud asks, or the Access ID, the Access Secret and the data center of a cloud project. Each device is stored with its device ID, its product key, the catalog entry its controls are named by, or the Tuya cloud's model of it with its category, its local key and its options. A device stored with its model starts without the cloud. The setup page never sees the session, the secret or a local key. A second copy is written after each save, so that a crash during a save leaves one to read: the log says when the plugin falls back on it.
120
+
121
+ A device stored by this version stays as it is when the plugin is updated: a setting added later falls back to what the plugin did before it existed. A device the plugin cannot read, such as one edited by hand, is kept in the storage as it is, and logged.
122
+
123
+ ## Configuration
124
+
125
+ The account and the devices are set up in the setup page alone. The Matterbridge config editor of the plugin has:
126
+
127
+ | Setting | What it does |
128
+ | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
129
+ | Poll Interval | How often, in seconds, each device is read, from 10 to 3600: 30 by default. A device sends a change of its state by itself, so this mostly sets how soon one that is unplugged shows as unreachable |
130
+ | Enable Debug | Logs more, for debugging |
131
+ | Unregister On Shutdown | Removes every device from Matter when Matterbridge stops, for debugging |
132
+
133
+ ## Good to know
134
+
135
+ - **The Smart Life session serves one program.** Two programs signed in with the same session, such as this plugin and Home Assistant with a copy of its configuration, end it for both: sign each in by a QR code of its own.
136
+ - **A device on protocol 3.1 reads under a wrong local key.** A command that times out on one is the sign that its key is wrong: read the device list again from the setup page.
137
+ - **The meter shows the first phase.** A device that measures three phases shows the readings the catalog gives for the device as a whole, or none.
138
+ - **A device that refuses a read.** Some 3.2 and 3.3 devices answer every read with an error. open-tuya can read them by writing null to their data points, which this plugin does not do, since a null write changes some devices: they are reached through the cloud instead.
139
+
140
+ ## Development
141
+
142
+ The plugin is developed from the [Matterbridge plugin template](https://github.com/Luligu/matterbridge-plugin-template); see its README for the dev container and the toolchain, and [STYLEGUIDE.md](./STYLEGUIDE.md) and [AGENTS.md](./AGENTS.md) for the conventions.
143
+
144
+ ```bash
145
+ npm install
146
+ npm link matterbridge # with matterbridge installed globally
147
+ npm run build # the plugin, into dist
148
+ npm run build:frontend # the setup page, into apps/frontend/build (run npm install in apps/frontend and npm run build first)
149
+ npm run test:coverage
150
+ npm run lint
151
+ ```
152
+
153
+ The plugin's source is in [src](./src), and its tests follow the same layout under [vitest](./vitest):
154
+
155
+ | Path | What it holds |
156
+ | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
157
+ | [module.ts](./src/module.ts) | The platform: the Matterbridge entry point, the account, the discovery, the gateways, the stored device list and the devices that run from it. |
158
+ | [config.ts](./src/config.ts) | The stored configuration: its model, its validation and its comparisons. |
159
+ | [features.ts](./src/features.ts) | What a catalog entry lets a device show in Matter: its outlets, its setting switches, its sensors, its meter and its battery. |
160
+ | [mapping.ts](./src/mapping.ts) | The conversions between the values of a device and the Matter clusters. |
161
+ | [errors.ts](./src/errors.ts) | The helpers that describe errors. |
162
+ | [accessory/](./src/accessory) | One device in Matter: its layout, its endpoints, what the controllers ask of it and what the device reports. |
163
+ | [platform/](./src/platform) | What the platform keeps between restarts, and the route to a device through the cloud. |
164
+ | [setup/](./src/setup) | The guided setup: the checks of a device and the REST API of the setup page. |
165
+
166
+ The setup page is a small TypeScript page without a framework, in [apps/frontend](./apps/frontend), which esbuild bundles into one `app.js`. Matterbridge serves `apps/frontend/build` at `/plugins/matterbridge-open-tuya/`, and the page calls the plugin through `onFetch`: see [src/setup/setupApi.ts](./src/setup/setupApi.ts). The page takes the types of what the plugin sends from the plugin itself, through a TypeScript project reference to the plugin's build, which is why the plugin is built first.
167
+
168
+ ## Legal disclaimer
169
+
170
+ An independent, community project for interoperability and home automation. It is not affiliated with, authorized, or endorsed by Tuya. All product names and trademarks are the property of their respective owners.
171
+
172
+ The plugin talks to the Tuya cloud with the account you sign in with, as an ordinary client of the cloud's own endpoints, and to each device on your network with the local key the cloud gives for it. Its use may be subject to Tuya's terms of service.
173
+
174
+ ## License
175
+
176
+ [Apache-2.0](./LICENSE)