Smartlife/Tuya switches via MQTT


I have problems to connect my smartlife/tuya simpleswitch to openhab.

I have been reading a lot on this community and other webpages, but I still can’t figure out how to connet my smartlife via mqtt broker.
As I understands it, I don’t have to flash it with tasmota.
I don’t need to connect my switches to mosquitto.
I just need to add generic mqtt thing from openhab (as client) and use my mqtt broker “as a bridge” to my switch (client).

I’m running openhab 3 on ubuntu and mosquitto on my Synology NAS. I have my smartlife switch ID, localkey, local IP.

Openhab has and my mqtt broker is online, generic mqtt is online with bridge.
Synology nas runnig mosqutitto has

I have tried generic mqtt, add channel, on/off switch, mqtt state topic / command


tuya or no text/simpleswitch or switch or no text/#id# bffea3d1258b5fa68xxxxx/#key# 19d1038606axxxx/#IP# or no text/topic
tuya or no text/simpleswitch or switch or nothing/#id# bffea3d1258b5fa68xxxxx/#key# 19d1038606axxxx/#IP# or no text/command

What have I been doing wrong.
Do I need to put id, local key in a file with somewhere (in mosquitto or openhab)?


But you will need your switch to connect to the broker, so I’m not sure what you mean by

I thing that is one off my issues. I can’t figure out how to add my switches to the broker

You don’t. It’s the switches that need to able to run MQTT and need configuring to talk to the broker.
They cannot do that without reflashing.
This post, which you must have seen, tells you how to use Tuya app and an extra script to act as intermediary between Tuya switch and MQTT. The script is the thing that needs configuring to talk to your broker.

I have probably misunderstood some info long then line.

Yes I have read that post. I will go through it again, closely, and test again. Then comeback :blush:

Thanks for your support !

Note : Tuya no longer supports this for accounts created after March 24, 2021. If you created your cloud account after that date, this method will not work.

Neither you need to setup the script that talks between tuya and MQTT.

I would advise getting that working first before even looking at openHAB.

I always work from device to openHAB and you can verify it working in MQTT using another client like MQTT Explorer.

Learn how the device is controlled through a MQTT client before adding it to openHAB.

Thank you for your time

let see, I hope I have made some small steps forward

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

I have got my local key, ID and name from

mqtt server is up and running

● mosquitto.service - Mosquitto MQTT v3.1/v3.1.1 Broker
Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor pr>
Active: active (running) since Thu 2021-04-22 19:06:47 UTC; 1min 20s ago
Docs: man:mosquitto.conf(5)
Main PID: 1116 (mosquitto)
Tasks: 3 (limit: 4481)
Memory: 2.5M
CGroup: /system.slice/mosquitto.service
└─1116 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Apr 22 19:06:47 nuc systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker…
Apr 22 19:06:47 nuc mosquitto[1116]: [ 135.260632]~DLT~ 1116~INFO ~FIFO />
Apr 22 19:06:47 nuc systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
lines 1-14/14 (END)

  1. (must have sudo for this step)
    my config.json

“host”: “”,
“port”: 1883,
“topic”: “tuya/”,
“mqtt_user”: “”,
“mqtt_pass”: “”,
“qos”: 1

my devices.conf
name: ‘Hallen’,
id: ‘bffea3d1258b5faxxxxxxx’,
key: ‘19d1038606xxxxxx’

name: ‘Sovrums TV’,
id: ‘0377748668c6xxxxxxxx’,
key: ‘909200910bxxxxx’

name: ‘Taklampan’,
id: ‘bf7eead468588xxxxxxx’,
key: ‘8460fe3fc95xxxx’

name: ‘lampan sovrummet’,
id: ‘0226785468cxxxxxxxx’,
key: ‘324b5a10xxxxxxx’

name: ‘lampan lilla rummet’,
id: ‘0226785468c6xxxxxxxx’,
key: ‘f6ea462375xxxxxx’


/etc/openhab/scripts/tuya-mqtt/devices$ sudo node tuya-device.js
[sudo] password for nuc:

no errors

Generic MQTT Thing
Channels, add channel
Channel Identifier Hallen
Label Hallen
channel type on/off switch
mqtt state topic
mqtt command topic