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

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.

Glad it works now! I was just wondering why your @tuyapi is installed in /usr/lib/node_modules/@tuyapi

No idea, I just followed the instructions.

// switch to opt directory

cd /opt

// clone this project

sudo git clone GitHub - TheAgentK/tuya-mqtt: Nodejs-Script to combine tuyaapi and openhab via mqtt

// change directory to the project directory

cd tuya-mqtt

//installs this project along with codetheweb/tuyapi project

sudo npm install
cp config.json.sample config.json
sudo nano config.json

// This should be all that is required for the tuya-MQTT software.

//==================================================================

// For the wizard software, perform the following

sudo npm i @tuyapi/cli -g

sudo tuya-cli wizard

// If your having issues, with the above, use the below.

sudo DEBUG=* tuya-cli wizard

sudo nano devices.conf

sudo node tuya-mqtt.js

Whilst I’m in this area, I will make a contribution:

The Wizard generated the following:
image

For the Thing/Channel configuration of my new Tuya SmartPlug, I needed to setup the device like this:
Note the different MQTT structure.

The YAML code looks like this.
UID: mqtt:topic:genio_adaptor
label: Genio Adaptor
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:f44b9520f1
channels:

  • id: relay
    channelTypeUID: mqtt:switch
    label: Relay
    description: “”
    configuration:
    commandTopic: tuya/genio_adaptor/dps/1/command
    stateTopic: tuya/genio_adaptor/dps/1/state
    off: “false”
    on: “true”

I do have the problem in that OH does nothing when I turn the Switch Off via OH3. Turn the Switch On via OH3 and there are tail logs and MQTT commands and the actual switch turns On.
Off. Nuthin. It’s like I haven’t touch the screen at all ???
Ideas on this one?

1 Like

JFYI - I got warnings when installing because I had NodeJS version 10.21.0 but it seems to be working. I also had to “sudo” the install for permission reasons (I know - naughty).

1 Like

hello,

is there a way to discover dps topics?
i have a tuya pet wifi feeder, and if i send a manuel feeding with the app its: tuya/harvey_feeder/dps/105/state “Number of parts” but if i want to send a command to it its not 105 but tuya/harvey_feeder/dps/101/command , please dont ask me how i get the 101 because its was just guessing and little luck,
so is there a way to discover the dps commands?

So if I understood correctly, you want a list of all possible dps topics right?

Unfortunately, I don’t know any other way than using a tool like “MQTT Explorer” to reverse engineer the topics…

Maybe @tsightler knows a better way?

1 Like

Yes that’s what i mean.

Because:
dps 105 is state
dps 101 is commando

But 101 never exposes itself so i was Just tyring Them all

So what I would do is to monitor the MQTT-Explorer output while controlling the pet feeder (I guess normally via a mobile app?). Then you should see all dps topics used and it should give a picture how the device gets controlled…

Yes like i said in my first post,

If start mqtt Explorer and send a commando with the app then dps 105 changes and i see the value, but i cant send a commando to it because its a Read only. If i send a commando to dps 101 then Will the device receive the command and 105 changes to the new value, but how expose the command channels? Because i had to gues.

Ah ok, now I got it! So what you can try:

  1. Login to https://iot.tuya.com
  2. On the left pane click on “Product”
  3. Click “Create”
  4. Choose your product (on top right there is a search bar)
  5. Enter a “Product Name” (this can be any name you want) and select
  6. Click on “Create Product”
  7. Now you should see a window “Create Standard Functions” - click on “All” and then “Confirm”

Then you should see the DP ID’s and the description…

I hope that helps!

1 Like

Hi, thanks for think about this,
I did this yesterday but the dps id’s are around 1 TM 20 and the device at home is around 100, i wil make a gif when i am at home

That’s strange cause I just created a “test” product and the DP’s starts with 101:

You can capture the traffic between the app and your tuya device and then use tuyadump to decode it:

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.