Tuya MQTT Bridge using Homie convention

I’ve created an experimental bridge to automatically publish all updates on all Tuya devices on local network to MQTT using the Homie convention.

This allows the following:

  • All Tuya devices are automatically discovered by Openhab MQTT binding as Things.
  • Channels for these Things are setup appropriately.
  • This is dependent on you linking your Tuya devices to their cloud at least once (if not for a couple of days until all the properties populate).
  • Once you bind these channels to items those items can also push back to Tuya. I.e. if a Tuya property allows updates flicking your switch in Openhab will send that instruction to Tuya.
  • Units are supported (well the ones I tested anyway).
  • Updates to Tuya work for everything except for Tuya bitmaps (I don’t have a device with settable bitmaps, so not sure if this is even possible).
  • It also publishes Home Assistant config topics now so should be compatible with that too.
  • It should be noted that the $name property (i.e. the user friendly name) is populated off what is brought in from the Tuya API, so dependent on the quality of that. Sometimes their “friendly” names are not that great (guessing it depends on the device manufacturer). Can’t fix that but you can just override these in your item configuration.

It’s a python script that can be setup as a service. It uses the tinytua python package. It is currently dependent on an PR to that package that’s still in development.

The project is available here:

In addition to the instructions above you need to setup an MQTT broker, and also connect Openhab MQTT binding to the same broker.

1 Like

Hi @lrossouw,

great stuff. I’ve installed the binding, everything seems to be working, however OH4 does not recognize the tuya device.

I figured that there’s no way to set a username and a password for the MQTT broker. Could that be the issue? My Mosquitto instance uses authentication.

Thanks,
Florian

Yep that would probably be it. I should add user/password functionality. My use case everything is on the same machine.

A bit embarrasing but the config for MQTT was completely ignored. Fixed that as well as added user/pass settings.

1 Like

Hi @lrossouw,

works like a charm. Thank you.

Best,
Florian

I made further improvements yesterday to improve reliability on when the MQTT broker becomes unreachable and then returns later or if the broker is not up when the service starts.

Made a few fixes to better handle connection failures to particular devices and to be more conformant to Homie standard.

I’ve made further enhancements to the above:

  • It also publishes Home Assistant config topics so is compatible with Home Assistant too.
  • Improved the naming of items derived from bitmaps.

It should be noted that the naming of devices is taken straight off what is brought in from the Tuya API, so dependent on that. Sometimes their friendly names are not that great (guessing it depends on the device manufacturer).