Tuya-mqtt and devices behind a gateway

I am using OH 3.4 on a Orangepi 3 LTS. I have 9 tuya zigbee temperature and humidity sensors around the house behind a Tuya zigbee gateway. tuya-cli reads the subdevices OK, but I have not been able to configure tuya-mqtt’s devices.conf so that tuya-mqtt would read the subdevices properly. I can get it to publish temperature and humidity readings to MQTT, but they are all presented as if the gateway would be the sensor.
If tuya-cli can read individual sensors behind a Tuya gateway one could assume it should be possible also for tuya-mqtt? Has anyone succeeded in getting tuya-mqtt to properly read sensors behind the tuya zigbee gateway? If so, a model devices.conf would be greatly appreciated!

1 Like

I have already answered you on github, but I will duplicate it here so that someone else can use the advice.

Each subdevice has own id called “cid”. But the original code of tuya-mqtt project has no ability to process values from subdevices.

I’ve forked this project and made some changes to fix it.

Please try:

I’m not a developer and fixed the code as best I could. It works for my Zigbee TRV behind Tuya Wireless Gateway.
Also see readme file and openHAB examples. I hope I have explained in an accessible way how to work with subdevices.

Anyway feel free to contact me.


Thanks for the heads up.
It works, but it can not use the friendly names in devices.conf for subdevices but lists the devices under the gateway tree with cid. This is not a major problem, though.

Yes, this was my first attempt to fix the nodejs code. Maybe later I’ll find a way to use friendly names for subdevice too.

I will try your change… And maybe can fix the friendly name thing.

In the end I have no idea how to propagate that then back to the project, without a active maintainer. :see_no_evil:

As well as I hope I can create another fork from yours that u can find me. Or even better, I figure out how to get a change from one fork to another without pull or push it through the main project

1 Like

I was able to port your fork into mine, was not that difficult… I will try to insert resolving the friendly name from a subdevice.
But this will need a while as I am now fighting another shortcoming of openHAB 3, the documentation and some hints from special experienced users :slight_smile:

1 Like

I have two tuya bulbs, that I can control via the Smart Life app. I have been able to get their ID and Key with tuya-cli wizard. However, I can not find them on my router and hence have no IP for them but I still can control them from Smart Life app remotely e.g. at work and the other bulb is even found and recognized by tuya-mqtt.

How is this possible, what am I missing?

You are missing nothing… :slight_smile: You don’t need the IP for the Tuya MQTT Binding, only if you want or have to set the protocoll manually then you would have to have their IP.

But (unless those are Zigbee Devices) they should have an IP which you can see on your routers network page. If they are Zigbee devices they don’t have one, as they all use the IP of the Zigbee gateway.
If unsure, you can identify your devices with the smart life app. In the device in the upper right corner the settings symbol and then Device Info.
There are two options then…

  1. It’s a wifi device, then it states a MAC and a IP… U need that mac to find it clearly identify it on your router… The IP stated in the App is the external IP asigned to your router by your ISP. You could identify the IP of it now with the DHCP table of your router… But u dont need, the ID found by tuya-cli is enough to configure tuya MQTT and make openhab work with it
  2. It’s a Zigbee device, then only a MAC is stated and no IP… Then you are in the right thread here and it doesn’t have a IP at all and you don’t need the IP as it uses the IP of the gateway… (Thats’s the idea behind protocols like ZigBee… Only one IP for all your ZigBee devices and devices do not polute your WLAN channel)

furthermore u need to have lehan’s modified version of tuya-mqtt running, that is able to deal with subdevices… But from your question I would sggest you first start with a real WlAN Tuya device, once u got how that works, you know how to make the zigbee device work with lehans change also.
(and hopefully my addition to promote the “friendly name” of the Zigbee device behind a tuya gateway also).

If you have basic questions to get your device into openHAB feel free to come back here

1 Like


Thank you! I have many. I have 9 Zigbee temperature sensors that indeed are behind a Zigbee gateway and that I can read with tuya-cli using a script I wrote. In addition I have two Tuya WIFI bulbs, that I am currently trying to connect to OpenHAB. So far my attempts have been futile.

I know the local IDs and keys for the bulbs thanks to

tuya-cli wizard

I am currently stuck at how to connect these to OpenHAB. I have a Thing and an associated Channel configured like so:

UID: mqtt:topic:8d0380cfbd:timonYopoytaValo
label: Timon yöpöytävalo
thingTypeUID: mqtt:topic
  payloadNotAvailable: offline
  availabilityTopic: tuya/bfad0c535e2fa*********/b9d4515*********/dps/status
  payloadAvailable: online
bridgeUID: mqtt:broker:8d0380cfbd
location: Vanhempien makuuhuone
  - id: timonYopoytaValonHimmennin
    channelTypeUID: mqtt:dimmer
    label: Timon yöpöytävalon himmennin
    description: ""
      commandTopic: tuya/bfad0c535e2fa*********/b9d4515*********/dps/command
      min: 0
      qos: 2
      stateTopic: tuya/bfad0c535e2fa*********/b9d4515*********/dps/state
      max: 100

I have tried many different variations of the mqtt path:


But the bulb remain “offline”, e.g. unreachable. I can see the bulbs with tuya-mqtt debug, they both show up and provide data. However I have not been able to configure OpenHAB to access them right, yet.

Hmm, my devices identify themselves in the debug as being Version 3.4. Is tuya-mqtt known to support tuya 3.4 devices?

The solution was to use the beta version of the tuya addon from smarthomej


This enabled me to control the bulbs.

1 Like

A year later, I finally managed to add code to use human names for sub-devices!

Now it’s possible to send commands to such topics:


For example:

1 Like