Step-by-Step guide for adding Tuya-bulbs, Wi-Fi smart LED (Smart Life app) to OH2 using tuya-mqtt.js by AgentK

Tuyaapi does not support sensors. At least not sensors which sleep the most time as door sensors.

1 Like

Dear OH-community, i’m going to be crazy! couple of days on this problem:

I succeeded in integrating my Zemismart vertical shutter motor in openhab thanks to the AgentK binding, -I found my secret key etc …,
-I have configured my broker correctly,-configured my MQTT thing like this:

,with a rollershutter ID channel type

  • created my articles like this:
    Dimmer Direction "Store sam" {channel="mqtt:topic:0f66ae51:direction"}

-and create a basic rule like this:

`rule “rule name”
Item Direction received command OFF

rule “rule name”
Item Direction received command ON

-I noticed while running MQTT fix that the topics of my device were tuya / “name” / dps / 2 / state, this one returns a number value.

My problem is the following, when I activate my roller shutter via the tuya application, I see the change of values ​​of my MQTT fix topic, on my sitemap I also see that the switch opens and closes, however I can’t send a shutter command from openhab to my roller shutter, what am I doing wrong with my rule?

i also tried this one reading the binding documentation
MQTT binding doc
`rule “Toggle Tuya light/switch on/off via MQTT”
Item Direction received command
val mqttActions = getActions(“mqtt”,“mqtt:systemBroker:embedded-mqtt-broker”)

 switch(receivedCommand) {
 case ON : mqttActions.publishMQTT("tuya/store_de_la_salle_a_manger/dps/2/state/","40",true)
 case OFF : mqttActions.publishMQTT("tuya/store_de_la_salle_a_manger/dps/2/state/","100",true)

Sorry for the layout firefox doesn’t help me

I did not understand how I run the test, can you explain?

to see if it installed it globally try out the command at the C:\ power shell prompt:

tuya-cli help

Solved like a dummy i check "is command " in the state status of the MQTT things, to trigger my roller shutter i use the “tuya/store_de_la_salle_a_manger/dps/2/command” set in like a dimmer

In the end I got it working. But it is terribly unreliable and requires several triggers on the sensor to result in a status update via MQTT. So I just gave up. As soon as I can I’ll replace the sensors with something that’s actually supported.

Is there any way to ping the device and check if it is online or not ? I have id and key, but can’t find topic which would trigger such action

Needed to restart tuya mqtt server and send command “get-states” to “tuya/< ID >/command” topic

1 Like

Hey all,

Is this method still valid? cause I followed the step and installed Bluestack but Smarlife App keeps crashing when trying to enter any device inside the App in Bluestack. And I am not able to find the file where i can see the Keys of the devices noting that Bluestack is rooted properly.


I have 2 smart sockets and 1 smart bulb added in Tuya app on my android phone, and this method still working great. I can control all of them in both Tuya app and openHAB-3.
You should try Tuya and get device’s ID from, then get key with tuya-cli wizard

is this repository available somewhere?

I have a problem with the tuya-cli get command.
It returns: “undefined”

tuya-cli get --ip --id bf5dda5b30a1xxxxxxxxxx --key 69c46byyyyyyyyyyy

Any hints? run under win10. I will add that during the polling, the openhab server and tuya app from my mobile were turned off

Sorry, i no longer use OpenHAB.

Okay, I was able to start the floodlight lamp (by LSC) working with all possible settings (on/off, brightness, white temp, mode: sensor/manual, all settings of sensor)

The problem is that it only works in ONENHAB when I have the script running manually
(putty session on my raspberry)

cd /etc/openhab2/scripts/tuya-mqtt
DEBUG=* node tuya-mqtt.js

I added script as a service to systemd (as well as in tutorial)

HELP !!!

which direction? HA?

I modified a version of LSC Smart App that actually shows the local key in the device properties. It is an older version since the latest versions dont really play nice with apktool. Uninstall the app first before installing this (it has a differrent signature).
Download here: 51.97 MB file on MEGA

The latest version supports v3.3. Just config your devices.conf like this:
name: ‘LSC-A60-RGB-CCT 1’,
id: ‘xxx’,
key: ‘xxx’,
version: ‘3.3’

My adventures with openhab and LSC Smart Connect lightbulb:

Install openhab3

sudo apt-get install openjdk
wget -qO - '' | sudo apt-key add -
sudo apt-get install apt-transport-https
echo 'deb stable main' | sudo tee /etc/apt/sources.list.d/openhab.list
sudo apt-get update && sudo apt-get install openhab
sudo apt-get install openhab-addons
Navigate with a web browser to http://<ip-address>:8080

Install mosquitto
sudo opt-get install mosquitto
sudo systemctl mosquitto restart

Install node/npm
sudo apt-get install nodejs
sudo apt-get install npm

Install tuya-mqtt
cd /opt
sudo git clone
sudo cd tuya-mqtt
sudo npm install
sudo cp config.json.sample config.json
nano devices.conf (see next step)


    name: 'LSC-A60-RGB-CCT 1',
    id: 'bfa4875da7d3c05f459aof',
    key: '7cdbc8a0c742715b',
    version: '3.3'

Install modfied lsc app

Login, select a device, press menu, Device info, get device id and localkey
Add to devices.conf

Install MQQT Binding
Open openhab
Add thing, install binding MQQT Binding
Add a MQQT Broker, set ip to (mosquitto)

Run tuya-mqtt in debug
cd /opt/tuya-mqtt
DEBUG=tuya-mqtt:* node tuya-mqtt.js
You can now use the app and see the commands + payload

Add a Generic MQQT Thing eg. LSC-A60-RGB-CCT 1, select MQQT Broker as bridge.
Add folowing channels:

• On/Off (switch)

  State: tuya/lsc-a60-rgb-cct_1/dps/20/state
  Command: tuya/lsc-a60-rgb-cct_1/dps/20/command 
  On value: true
  Off value: false
• Brightness (number)
  State: tuya/lsc-a60-rgb-cct_1/dps/22/state
  Command: tuya/lsc-a60-rgb-cct_1/dps/22/command 
  Min value: 10
  Max value: 1000
• Whiteness (number)
  State: tuya/lsc-a60-rgb-cct_1/dps/23/state
  Command: tuya/lsc-a60-rgb-cct_1/dps/23/command 
  Min value: 10
  Max value: 1000
• Color (string)
   First copy RGBToColorString.js and ColorStringToRGB.js to /etc/openhab/transform


(function(i) {
    var re = /.*([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{4}).*/i;
	var r = i.match(re);
	if (r === null||r.length===0)
	return i;
	var one = Number('0x' + r[1]);
	var two = Number('0x' + r[2]) / 10;
	var three = Number('0x' + r[3]) / 10;
	return one+','+two+','+three;


function pad(num, size) {
    num = num.toString();
    while (num.length < size) num = "0" + num;
    return num;

(function(i) {
    var r = i.split(',');
	if (r === null||r.length!==3)
	return i;
	var one = Number(r[0]) ;
	var two = Number(r[1]) * 10;
	var three = Number(r[2]) * 10;
	return pad(one.toString(16), 4) + pad(two.toString(16), 4) + pad(three.toString(16), 4);

   State: tuya/lsc-a60-rgb-cct_1/dps/24/state
   Command: tuya/lsc-a60-rgb-cct_1/dps/24/command
   Transformation Out: JS:RGBToColorString.js
   Transformation In: JS:colorStringToRGB.js

• Mode (switch)
   Command: tuya/lsc-a60-rgb-cct_1/dps/21/command
   State: tuya/lsc-a60-rgb-cct_1/dps/21/state
   Off value: colour
   On value: white
   Has another value: scene

• Scene (string)
  State: tuya/lsc-a60-rgb-cct_1/dps/25/state
  Command: tuya/lsc-a60-rgb-cct_1/dps/25/command 

Install tuya-mqtt as service

cd /lib/systemd/system/
sudo touch tuyaapi-mqtt.service
echo [Unit] | sudo tee -a tuyaapi-mqtt.service
echo Description=tuyaapi-mqtt | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo [Service] | sudo tee -a tuyaapi-mqtt.service
echo ExecStart=/usr/bin/node /opt/tuya-mqtt/tuya-mqtt.js | sudo tee -a tuyaapi-mqtt.service
echo Restart=always | sudo tee -a tuyaapi-mqtt.service
echo User=openhab | sudo tee -a tuyaapi-mqtt.service
echo Group=openhab | sudo tee -a tuyaapi-mqtt.service
echo Environment=PATH=/usr/bin/ | sudo tee -a tuyaapi-mqtt.service
echo Environment=NODE_ENV=production | sudo tee -a tuyaapi-mqtt.service
echo WorkingDirectory=/opt/tuya-mqtt | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo [Install] | sudo tee -a tuyaapi-mqtt.service
echo | sudo tee -a tuyaapi-mqtt.service
echo Alias=tuyaapi-mqtt.service | sudo tee -a tuyaapi-mqtt.service
sudo chmod 644 /lib/systemd/system/tuyaapi-mqtt.service
sudo systemctl daemon-reload
sudo systemctl enable tuyaapi-mqtt.service
sudo systemctl start tuyaapi-mqtt.service
1 Like

THX for that. Now it works like a charm

1 Like

Hi @worstenbrood nice writing… I use textual config and an external mqtt broker, but have managed to get everything configured so far… I only have one question maybe you can answer this?!
in your guide you add two channels:

• Mode (switch)
   Command: tuya/lsc-a60-rgb-cct_1/dps/21/command
   State: tuya/lsc-a60-rgb-cct_1/dps/21/state
   Off value: colour
   On value: white
   Has another value: scene

• Scene (string)
  State: tuya/lsc-a60-rgb-cct_1/dps/25/state
  Command: tuya/lsc-a60-rgb-cct_1/dps/25/command 

this looks like this in my textual config:

            Type switch : mode "Mode" [
            Type string : scene "Color Scene" [

but what is missing is the linking to the scene channel…

   Has another value: scene

any idea how this would look like in textual config?

I had a look at the Documentation but this doesn’t seem to cover how to link these channels in text files.

Is this neccesary at all? Would be nice to get my tuya bulbs controlled by openhab :wink:


Ok, I got everything running without the channel linking… no problem for me because I don’t use these preconfigured tuya lightscenes at all.

Hi All, new to this thread but not to Openhab. Just trying to integrate Tuya into my system - and this is the 3rd method I’ve tried :wink:

I’m so close with this one! But I think my issue is that I have all my devices behind a Tuya hub. So the only device with wifi is the hub itself, my other devices need the hub to access wifi.

Anyone know of a way to get to those sub-devices using this method. I’ve tried accessing them directly, and also most recently found a potential protocol for referencing sub-devices via the gateway for another API tuyaDAEMOM global.alldevices · msillano/tuyaDAEMON Wiki · GitHub

So I was trying…

    name: 'Zigbee Hub',
    id: 'hhhhhhhhh',
    key: 'kkkkkkkkkk1',
    subDevices: [
        name: 'Pool Blind 2',
        id: 'bbbbbbbbbbbb',
        gateway: 'hhhhhhhhh',
        cid: 'id1ididididididid'
        name: 'LED Strip',
        id: 'bf78XXXXXXXXXtws',
        gateway: 'hhhhhhhhh',
        cid: 'id2ididididididididi'

The hub is connecting fine, but the sub-devices just time-out. Should i just give up on this one? Next step i think is to Flash the Zigbee devices!

Are these actually Tuya or Zigbee devices? I know there are Tuya devices out there which aditionally use the Zigbee standard. If that is the case, aren’t you able to use a Zigbee-Bridge and get rid of that Tuya crap?? I thought if devices (even tuya) are able to use the Zigbee standard you don’t have to use the Smartlife App.

…btw, never heard of a tuya-bridge, are you sure you’re not using a Zigbee-bridge?

Just a guess but if this is the case you should be able to use it with the Zigbee-Binding if I’m not mistaking…

I’m not sure if this works