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

Thanks,
I am still a littel confused about few things.

  1. The swtch doesn’t update when changed externally. How do you get it to map back. It works to send from the gui but not when changed externally. I can see the change in the debug mode of tuya-mqtt

  2. How do you configure in an items things/items file instead of Paper UI?

  3. How do you send a value or receive from one of the dps values?

Any help or pointing me to somewhere that explains would be great.

Hello, try with the DPS directly on the state :

tuya/<typeofprotocol>/<tuyaid>/<tuyakey>/dps/1

, or DPS/2 if you want the state of DPS number 2 …

hi how i can controle a wall switch of 3 gangs only turn on 1 gang

Thanks for the tutorial, I’m having some trouble finding the .ssh folder to save my public/private key to. In V 2.4, is is named something like “org.apche.karaf.shell.ssh”?

check here : https://help.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys

Hi. I’ve installed the MQTT Binding (2.4.0) and the things that you said in the tutorial (MQTT Broker, Embedded MQTT and the Generic MQTT). Also, I’ve installed the tuyaaì_mqtt.js and it’s running.

In the other hand, I’ve installed a contact sensor in Tuya App and got the deviceId, the localKey and the local IP, and I’ve added the channel with the state and the command topic like that:

tuya/{deviceId}/{localKey}/{localIP}/

The problem is that OpenHAB doesn’t seem connect with my device.

What’s wrong? Have I forgotten anything?

Regards

what is the version of tuya_mqtt ?

2.0.3

I think it’s the last one, isn’t it?

On the other hand, I’ve installd tuya-cli. And when I execute DEBUG=* tuya-cli get --ip 192.168.100.120 --id YYYYYYYY --key ZZZZZZZZZ --all, I have something like that:

TuyAPI IP and ID are already both resolved. +0ms
TuyAPI Connecting to 192.168.100.120… +2ms
TuyAPI Error event from socket. 192.168.100.120 { Error: connect EHOSTUNREACH 192.168.100.120:6668
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
errno: ‘EHOSTUNREACH’,
code: ‘EHOSTUNREACH’,
syscall: ‘connect’,
address: ‘192.168.100.120’,
port: 6668 } +3s
events.js:183
throw er; // Unhandled ‘error’ event
^

Error: Error from socket
at Socket.client.on.err (/root/.nvm/versions/node/v8.12.0/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:323:30)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at emitErrorNT (internal/streams/destroy.js:66:8)
at _combinedTickCallback (internal/process/next_tick.js:139:11)
at process._tickCallback (internal/process/next_tick.js:181:9)

try this tuya_mqtt : https://github.com/tsightler/tuya-mqtt

1 Like

hi how i can controle a wall switch of 3 gangs only turn on 1 gang

Just a note for everyone in here still trying to include Tuya devices - at the moment the tuya-convert scripts seem to work for (most) all ESP 8266 based Tuya devices.


I can strongly recommend using this setup since after the flash you will have native MQTT devices (as in Tasmota) that you can then easily integrate into your openHAB setup without additional devices or servers despite your MQTT broker.

Cheers
Benjamin

when I type the following message in the channel configuration (Generic MQTT Thing)


everything works fine
However, if you specify a dps equal to 2
That command works fine, but when I but when I switch the outlet from the Smart Life App, the state is not set in the Control panel

Debug log:

TuyAPI Received data: 000055aa00000000000000080000006b00000000332e33000000000000013f00000001abeb50d3d15a1f00d06375a9b0c9f846c39bf6be10695e11d6c7b05eeaf31b0f7f78dee7e24910157a3462d6da664e86ac758ac82c65d74efc1f60da3d3b638e9b0bb31b080300d6ad527cf7d41f99d656aa0f050000aa55 +322ms
TuyAPI Parsed: +0ms
TuyAPI { payload:
TuyAPI { devId: ‘10140263bcddc2599e10’,
TuyAPI dps: { ‘2’: false },
TuyAPI t: 1573035712 },
TuyAPI leftover: false,
TuyAPI commandByte: 8,
TuyAPI sequenceN: 0 } +0ms
TuyAPI:device Data from device: { devId: ‘10140263bcddc2599e10’,
dps: { ‘2’: false },
t: 1573035712 } +8m
TuyAPI:mqtt:device Data from device undefined : { devId: ‘10140263bcddc2599e10’,
dps: { ‘2’: false },
t: 1573035712 } +8m
TuyAPI:mqtt:device mqtt dps updated to:tuya/10140263bcddc2599e10/c3f7b38e0630a74a/192.168.1.14/dps → {“2”:false} +0ms
TuyAPI:mqtt:device mqtt dps updated to:tuya/10140263bcddc2599e10/c3f7b38e0630a74a/192.168.1.14/dps/2 → dps[2] false +0ms
TuyAPI:mqtt receive settings {“topic”:“tuya/10140263bcddc2599e10/c3f7b38e0630a74a/192.168.1.14/dps”,“action”:“dps”,“message”:“{"2":false}”,“options”:{“id”:“10140263bcddc2599e10”,“key”:“c3f7b38e0630a74a”,“ip”:“192.168.1.14”}} +8m
TuyAPI:mqtt receive settings {“topic”:“tuya/10140263bcddc2599e10/c3f7b38e0630a74a/192.168.1.14/dps/2”,“action”:“dps”,“message”:“false”,“options”:{“id”:“10140263bcddc2599e10”,“key”:“c3f7b38e0630a74a”,“ip”:“192.168.1.14”}} +1ms

What am I doing wrong?

As described in a couple of posts, the local-key information is no longer held in preferences_global_key.xml. This is a change from version 3.8+. In my rooted Android I Installed 3.7.0 from an apk mirror. This version does show the keys as indicated in the tutorial

Hello,

could you please explane how to do it more for a noob?
I never did & just cant find where and how to add to the openhabian ssh folder.
I did create the public key but thats where i got where do i insert?

thanks

Hi
I’m using LSC Smart Connect with Tuya.
This is my config in OH :

Things
    Thing mqtt:topic:TuyaLampe2 "Tuya Lampe 2" @ "RDC"
    {
       Channels:
       Type switch : TuyaLampe2Switch "Tuya Lampe 2" [ stateTopic="tuya/lightbulb/xxxx/yyyyy/discover/state", commandTopic="tuya/lightbulb/xxxxxxx/yyyyyyy/discover/command",on="ON",off="OFF" ]
    }

items
Switch TuyaLampe_2 "Tuya Lampe 2" <light> { channel="mqtt:topic:TuyaLampe2:TuyaLampe2Switch" }

But in the node, I have this issue when I activate the switch on or off in the control panel :

#/usr/bin/node /etc/openhab2/scripts/tuya-mqtt/tuya-mqtt.js

(node:18002) UnhandledPromiseRejectionWarning: Error: bind EADDRINUSE 0.0.0.0:6667
    at state.handle.lookup (dgram.js:242:18)
    at process._tickCallback (internal/process/next_tick.js:63:19)
(node:18002) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:18002) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:18002) UnhandledPromiseRejectionWarning: Error: No connection has been made to the device.
    at TuyaDevice._send (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:224:13)
    at Promise (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:204:14)
    at new Promise (<anonymous>)
    at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:201:12)
    at Promise (/etc/openhab2/scripts/tuya-mqtt/tuya-device.js:158:25)
    at new Promise (<anonymous>)
    at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt/tuya-device.js:157:16)
    at /etc/openhab2/scripts/tuya-mqtt/tuya-mqtt.js:346:33
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:18002) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:18002) UnhandledPromiseRejectionWarning: Error: No connection has been made to the device.
    at TuyaDevice._send (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:224:13)
    at Promise (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:204:14)
    at new Promise (<anonymous>)
    at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:201:12)
    at Promise (/etc/openhab2/scripts/tuya-mqtt/tuya-device.js:158:25)
    at new Promise (<anonymous>)
    at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt/tuya-device.js:157:16)
    at /etc/openhab2/scripts/tuya-mqtt/tuya-mqtt.js:346:33
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:18002) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 5)

Error: No connection has been made to the device
means the discover method doesn’t work ?
I’m on the same network ; on OH 2.4 with MQTT Binding + MQTT Embedded Broker

And or the error :
“Error: bind EADDRINUSE 0.0.0.0:6667”
First : starting node ,no port 6667
After starting OH 2.4, the port is there :

udp6       0      0 :::6667                 :::*                                111        16681      -

Is someone have an idea ?
Thanks for your help !

LSC product used protocole 3.3, so pleaae check in the first my post here : Step-by-Step guide for adding Tuya-bulbs, Wi-Fi smart LED (Smart Life app) to OH2 using tuya-mqtt.js by AgentK

Hi
first Thanks for your help !
I’ve already installed the 3.3 version and I use it.

LOG in openHAB :
2019-12-01 17:29:16.341 [nt.ItemStatePredictedEvent] - TuyaLampe_2 predicted to become OFF
2019-12-01 17:29:16.349 [vent.ItemStateChangedEvent] - TuyaLampe_2 changed from ON to OFF
2019-12-01 17:29:17.311 [ome.event.ItemCommandEvent] - Item ‘TuyaLampe_2’ received command ON
2019-12-01 17:29:17.318 [nt.ItemStatePredictedEvent] - TuyaLampe_2 predicted to become ON
2019-12-01 17:29:17.329 [vent.ItemStateChangedEvent] - TuyaLampe_2 changed from OFF to ON
2019-12-01 17:29:18.367 [ome.event.ItemCommandEvent] - Item ‘TuyaLampe_2’ received command OFF

Service in OS :
tuyaapi-mqtt.service loaded active running tuyaapi-mqtt

Result of my request just after OpenHAB started (without any action done on OH)

#tuya-cli set --set true --id xxxxxxxxxxxx --key yyyyyyyyyyyyy
{ Error: bind EADDRINUSE 0.0.0.0:6667
    at state.handle.lookup (dgram.js:242:18)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
  errno: 'EADDRINUSE',
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: '0.0.0.0',
  port: 6667 }
your code goes here

Netstat :

udp6 0 0 :::6667 :::* 111 74221 -

111 user is openhab

And to identify the programm using it :
#sudo netstat -putan |grep ‘6667’
udp6 0 0 :::6667 :::* 22915/java

Have you an idea ?

try : tuya-cli set --id XXXXXXXXXXXXXXX --key XXXXXXXXXXXXXXX --ip XXX.XXX.XX.X --set true --protocol-version 3.3

tuya-cli set --id xxx --key xxxx --ip xxxx --set true --protocol-version 3.3
Set succeeded.
pi@openhabpi:/home/pi
tuya-cli get --id xxxxx --key xxxxx
{ Error: bind EADDRINUSE 0.0.0.0:6667
    at state.handle.lookup (dgram.js:242:18)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
  errno: 'EADDRINUSE',
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: '0.0.0.0',
  port: 6667 }
^C
 pi@openhabpi:/home/pi
tuya-cli list
{}

So tuya-cli set work with protocol 3.3

please try with “ver3.3”

> tuya/ver3.3/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/state
> tuya/ver3.3/<tuyAPI-id>/<tuyAPI-key>/<tuyAPI-ip>/command

And :

On/open value : { “dps”: 1, “set”: true }
Off/closed value : { “dps”: 1, “set”: false }

2 Likes