# Tuya MQTT Bridge using Homie convention

**URL:** <https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185>\
**Category:** Bindings\
**Tags:** mqtt, tuya, tuya-mqtt\
**Created:** [July 30, 2023, 1:10pm UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185 "2023-07-30T13:10:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [July 30, 2023, 1:10pm UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/1 "2023-07-30T13:10:43Z")

</div>

I’ve created an experimental bridge to automatically publish all updates on all Tuya devices on local network to MQTT using the [Homie convention](https://homieiot.github.io/).

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:

> **[GitHub - spinza/tuya\_mqtt](https://github.com/spinza/tuya_mqtt)**
>
> Contribute to spinza/tuya\_mqtt development by creating an account on GitHub.

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

---

<div class="post-metadata">

**Author:** ![Ltty](https://community.openhab.org/user_avatar/community.openhab.org/ltty/32/110937_2.png) [@Ltty](https://community.openhab.org/u/Ltty)\
**Post date:** [August 8, 2023, 2:57pm UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/2 "2023-08-08T14:57:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [August 9, 2023, 10:47am UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/3 "2023-08-09T10:47:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [August 9, 2023, 11:19am UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/4 "2023-08-09T11:19:17Z")

</div>

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

> <https://github.com/spinza/tuya_mqtt/commit/0893acf3464731bdaa07fcfccf303ce46c5e0c2f>

---

<div class="post-metadata">

**Author:** ![Ltty](https://community.openhab.org/user_avatar/community.openhab.org/ltty/32/110937_2.png) [@Ltty](https://community.openhab.org/u/Ltty)\
**Post date:** [August 10, 2023, 7:41am UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/5 "2023-08-10T07:41:14Z")

</div>

Hi @lrossouw,

works like a charm. Thank you.

Best,  
Florian

---

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [August 10, 2023, 11:00am UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/6 "2023-08-10T11:00:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [August 20, 2023, 12:31pm UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/7 "2023-08-20T12:31:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lrossouw](https://community.openhab.org/user_avatar/community.openhab.org/lrossouw/32/96006_2.png) [@lrossouw](https://community.openhab.org/u/lrossouw)\
**Post date:** [August 25, 2023, 8:32am UTC](https://community.openhab.org/t/tuya-mqtt-bridge-using-homie-convention/148185/8 "2023-08-25T08:32:20Z")

</div>

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).
