Tuya devices to Openhab via MQTT - a working solution (without flashing)!

The script does want itΒ΄s meant to do.
All devices which are paired to the app are listed.

Great! So the basic communication is working! Now… Please take the output from the wizard and manually create the devices.conf - file in the tuya-mqtt folder. Paste the output from the wizard into the file and check if the structure looks like:

[
  {
    name: 'Tuya Device 1',
    id: '86435357d8b123456789',
    key: '8b2a69c9876543210'
  },
  {
    name: 'Tuya Device 2',
    id: 'eb532eea7d12345678abc',
    key: '899810012345678'
  }
]

If it looks ok, please start tuya-mqtt manually:

DEBUG=* node tuya-mqtt.js

Unfortunately the same Error.

Devices file not found!
tuya-mqtt:error SyntaxError: JSON5: invalid character β€˜i’ at 9:5
tuya-mqtt:error at syntaxError (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:1083:17)
tuya-mqtt:error at invalidChar (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:1028:12)
tuya-mqtt:error at Object.afterPropertyValue (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:654:15)
tuya-mqtt:error at Object.default (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:146:37)
tuya-mqtt:error at lex (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:78:42)
tuya-mqtt:error at Object.parse (/usr/tuya-mqtt/node_modules/json5/lib/parse.js:25:17)
tuya-mqtt:error at main (/usr/tuya-mqtt/tuya-mqtt.js:96:31)
tuya-mqtt:error at Object. (/usr/tuya-mqtt/tuya-mqtt.js:178:1)
tuya-mqtt:error at Module._compile (internal/modules/cjs/loader.js:778:30)
tuya-mqtt:error at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10) +0ms
tuya-mqtt:info Exit code: 1 +0ms

Oh hang on… I just tried on my system to rename the devices.conf and the error I get is:

Devices file not found!
  tuya-mqtt:error Error: ENOENT: no such file or directory, open './devices.conf'
  tuya-mqtt:error     at Object.openSync (fs.js:476:3)
  tuya-mqtt:error     at Object.readFileSync (fs.js:377:35)
  tuya-mqtt:error     at main (/srv/openhab2-conf/scripts/tuya-mqtt/tuya-mqtt.js:95:28)
  tuya-mqtt:error     at Object.<anonymous> (/srv/openhab2-conf/scripts/tuya-mqtt/tuya-mqtt.js:178:1)
  tuya-mqtt:error     at Module._compile (internal/modules/cjs/loader.js:1063:30)
  tuya-mqtt:error     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
  tuya-mqtt:error     at Module.load (internal/modules/cjs/loader.js:928:32)
  tuya-mqtt:error     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
  tuya-mqtt:error     at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  tuya-mqtt:error     at internal/main/run_main_module.js:17:47 +0ms
  tuya-mqtt:info Exit code: 1 +0ms

You are getting an invalid character error… Just to verify: Can you please navigate to your tuya-mqtt folder (from your output I guess it’s /usr/tuya-mqtt) and run:

git pull

followed by:

npm install

sudo git pull
Bereits aktuell.
pi@raspberrypi:/usr/tuya-mqtt $ sudo npm install
audited 322 packages in 10.347s

45 packages are looking for funding
run npm fund for details

found 2 vulnerabilities (1 low, 1 high)
run npm audit fix to fix them, or npm audit for details
pi@raspberrypi:/usr/tuya-mqtt $ npmaudit
-bash: npmaudit: Kommando nicht gefunden.
pi@raspberrypi:/usr/tuya-mqtt $ nom audit
-bash: nom: Kommando nicht gefunden.
pi@raspberrypi:/usr/tuya-mqtt $ npm audit

                   === npm audit security report ===

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Manual Review β”‚
β”‚ Some vulnerabilities require your attention to resolve β”‚
β”‚ β”‚
β”‚ Visit xxxxxxxxxxxxxxxxxxxxxxxxx β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Low β”‚ Prototype Pollution β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Package β”‚ minimist β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Patched in β”‚ >=0.2.1 <1.0.0 || >=1.2.3 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Dependency of β”‚ @tuyapi/cli β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Path β”‚ @tuyapi/cli > http-mitm-proxy > optimist > minimist β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ More info β”‚ https://npmjs.com/advisories/1179 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ High β”‚ Prototype Pollution in node-forge β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Package β”‚ node-forge β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Patched in β”‚ >= 0.10.0 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Dependency of β”‚ @tuyapi/cli β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Path β”‚ @tuyapi/cli > http-mitm-proxy > node-forge β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ More info β”‚ https://npmjs.com/advisories/1561 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
found 2 vulnerabilities (1 low, 1 high) in 322 scanned packages
2 vulnerabilities require manual review. See the full report for details.

Hm… would you mind if you send me your devices.conf (without id’s and keys) via PM?

And can you please run:

sudo sed -n '9p' < devices.conf

in the tuya-mqtt directory and post the output here? I think I was able to reproduce your issue…

[
{
name: β€˜PB 1’,
id: β€˜27384645f4cfa******’,
key: β€˜6463c15290******’
},
{
name: β€˜Fenster Schlafzimmer’
id: β€˜13600724840d8e******’,
key: β€˜fbfb5b3109******’
}
]

sudo sed -n β€˜9p’ < devices.conf:
id: β€˜13600724840d8e******’,

Ok, there is a comma missing at the end of:

name: 'Fenster Schlafzimmer'

ItΒ΄s running. Just a missing comma.
Thank you very much for your help and patience.

Glad it works now and good to know that I am not the only one who misses a comma from time to time :slight_smile:

Sorry again for the lack of response in the last days/weeks!

Now my devices couldnΒ΄t be find. IΒ΄m going insane.

Did you open the app on your smartphone after you started tuya-mqtt?

Yes. Through the App i’m able to control the device.

Edit: One device has been found.

Please note that Tuya’s API supports only 1 active connection. So if you open the app whilst tuya-mqtt is running, tuya-mqtt will lose the connection… I only used the app to install the devices and since then I never openend it.

Can you please share which device has been found and which ones are missing?

Hi,
What changes are required to the above installation notes for OH3.
Example being, are the folder locations the same?

I havenβ€˜t tried it but it should work the same way. You can install tuya-mqtt wherever you want as the communication between OH and tuya-mqtt is done via the mqtt binding (which connects to mosquito).

Hi,
I’m trying to run β€œtuya-cli wizard” but I’m getting the below debug response.
How do you give access to the API on a Pi?

sudo DEBUG=* tuya-cli wizard
Followed by putting in the three required codes

[
Error: you don’t have access to this API
at OpenAPI._client.got_1.default.extend.hooks.afterResponse (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/openapi/dist/api.js:73:31)
at EventEmitter. (/usr/lib/node_modules/@tuyapi/cli/node_modules/got/dist/source/as-promise.js:87:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5),
Error: you don’t have access to this API
at OpenAPI._client.got_1.default.extend.hooks.afterResponse (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/openapi/dist/api.js:73:31)
at EventEmitter. (/usr/lib/node_modules/@tuyapi/cli/node_modules/got/dist/source/as-promise.js:87:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5),
Error: you don’t have access to this API
at OpenAPI._client.got_1.default.extend.hooks.afterResponse (/usr/lib/node_modules/@tuyapi/cli/node_modules/@tuyapi/openapi/dist/api.js:73:31)
at EventEmitter. (/usr/lib/node_modules/@tuyapi/cli/node_modules/got/dist/source/as-promise.js:87:38)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
]

This happens most likely if you forgot to run

npm install

within the tuya-mqtt - directory. Can you please check?

Hi Flip,
The issue was in that I had not turned on the API’s in the Tuya website. After doing this, the discovery worked.