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 :
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
Now working !
I was needed to force in this config only :
Type switch : TuyaLampe2Switch “Tuya Lampe 2” [ stateTopic=“tuya/ver3.3/xxxxx/yyyyyy/ip/state”, commandTopic=“tuya/ver3.3/xxxxxxxx/yyyyyyyyyy/ip/command”,on=“1”,off=“0” ]
I don’t know why it was not working with “discover”
Thanks ! You’re the best !
Hello,
I have MQTT running well with zigbee2mqtt and Openhab but I am struggling to add MQTT for Tuya devices.
I have followed the first steps described above:
I have got the device ID and Key.
I have tuya-mqtt.js running ok (version 2.0.1) using the default configuration
I could read in DEBUG mode mqtt messages coming up from human actions on the Tuya switch.
The format of these messages have no reference to a tuyaAPI-type
Typically messages are in the following format: tuya/device id/device key/device ip/action payload
When I send messages in the same format using mqtt.fx they are parsed by tuya-mqtt with no error but no action is taken as you could see below where I try to set up brightness from 50 to 60:
C:\Users\regis\openhab2\conf\scripts\tuya-mqtt>set DEBUG=* & node tuya-mqtt.js
TuyAPI:mqtt MQTT-Server nicht verbunden. +0ms
TuyAPI:mqtt Verbindung mit MQTT-Server hergestellt +13ms
TuyAPI:mqtt receive settings {"topic":"tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps","action":"dps","message":"{\"2\":60}","options":{"id":"62564885840d8e9127b6","key":"39ca69b7e7c6a479","ip":"192.168.1.79"}} +20s
TuyAPI:device Search device in network +0ms
TuyAPI IP and ID are already both resolved. +0ms
TuyAPI:device Device found in network +1ms
TuyAPI Connecting to 192.168.1.79... +1ms
TuyAPI Socket connected. +4ms
TuyAPI:device Connected to device. undefined (192.168.1.79, 62564885840d8e9127b6, 39ca69b7e7c6a479) +10ms
TuyAPI:device GET Payload: +1ms
TuyAPI:device { gwId: '62564885840d8e9127b6', devId: '62564885840d8e9127b6' } +0ms
TuyAPI Received response +14ms
TuyAPI 000055aa000000000000000a00000044000000007b226465764964223a223632353634383835383430643865393132376236222c22647073223a7b2231223a747275652c2232223a35307d7db47ec3e00000aa55 +2ms
TuyAPI Parsed response data: +1ms
TuyAPI { devId: '62564885840d8e9127b6', dps: { '1': true, '2': 50 } } +0ms
TuyAPI:device Data from device: { devId: '62564885840d8e9127b6', dps: { '1': true, '2': 50 } } +12ms
TuyAPI:mqtt:device Data from device undefined : { devId: '62564885840d8e9127b6', dps: { '1': true, '2': 50 } } +0ms
TuyAPI:mqtt:device mqtt status updated to:tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/state -> ON +1ms
TuyAPI:mqtt:device mqtt dps updated to:tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps -> {"1":true,"2":50} +0ms
TuyAPI:mqtt:device mqtt dps updated to:tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps/1 -> dps[1] true +1ms
TuyAPI:mqtt:device mqtt dps updated to:tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps/2 -> dps[2] 50 +0ms
TuyAPI:mqtt receive settings {"topic":"tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/state","action":"state","message":"ON","options":{"id":"62564885840d8e9127b6","key":"39ca69b7e7c6a479","ip":"192.168.1.79"}} +75ms
TuyAPI:mqtt receive settings {"topic":"tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps","action":"dps","message":"{\"1\":true,\"2\":50}","options":{"id":"62564885840d8e9127b6","key":"39ca69b7e7c6a479","ip":"192.168.1.79"}} +4ms
TuyAPI:mqtt receive settings {"topic":"tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps/1","action":"dps","message":"true","options":{"id":"62564885840d8e9127b6","key":"39ca69b7e7c6a479","ip":"192.168.1.79"}} +1ms
TuyAPI:mqtt receive settings {"topic":"tuya/62564885840d8e9127b6/39ca69b7e7c6a479/192.168.1.79/dps/2","action":"dps","message":"50","options":{"id":"62564885840d8e9127b6","key":"39ca69b7e7c6a479","ip":"192.168.1.79"}} +1ms
TuyAPI Pinging 192.168.1.79 +10s
TuyAPI Received response +17ms
TuyAPI 000055aa00000000000000090000000c00000000b051ab030000aa55 +0ms
TuyAPI Pong 192.168.1.79 +1ms
TuyAPI Pinging 192.168.1.79 +10s
TuyAPI Received response +12ms
TuyAPI 000055aa00000000000000090000000c00000000b051ab030000aa55 +1ms
My first question is to know what tuyaAPI-type is referring to?
I also thank you in advance for helping me identifying what’s wrong in my setup
I had to read the full thread to understand that I needed first to update to tsightler/tuya-mqtt. It will be great if Holgi could update his original post with a reference to the tsightler version.
Also in your example below the “quotes” are not the right ones (“ or ” must be "). The issue seems to come from this editor that forces the wrong quotes.
Now I am trying to set the Tuya thing as a dimmer in PaperU.
I have tried to set a new channel in PaperUI with the following MQTT command topic:
tuya/device ID/Device Key/Device IP/command with a min of 0, a max of 255 and the Outgoing value format set to { “dps”: 2, “set”: %s}.
The mqtt message is properly received (“action”:“command”,“message”:“{ "dps": 2, "set":28.05}”) except that the dimmer value is not an integer and therefor not processed
I have tried to set the Outgoing value format to { “dps”: 2, “set”: %d} but in that case the mqtt message is truncated (and still not an integer) “action”:“command”,“message”:“28.05”
Any advice on how to properly send the dimmer value as an integer?
the proper solution to control the tuya brightness should be to add { “dps”: 2, “set”: %d} to the Outgoing Value Format (OVF) but it seems that the %d is not properly processed by OVF at that stage.
The temporary workaround is to not use OVF but to add the following Javascript transform
(function(brightness) {
var tuyaobj = {"dps": 2, "set": Math.floor(brightness)};
var data = JSON.stringify(tuyaobj);
return data;
})(input)
JSONPATH:$.2 must also be added to the channel “Incoming value transformations” to process properly the dimmer state.
The complete channel set up is:
Has anything changed in terms of obtaining LocalKey?
I have 2 rooted devices. In the file preferences_global_key_ some chars and numbers.xml
there is no information besides:
<? xml version = '1.0' encoding = 'utf-8' standalone = 'yes'?>
<map />
Identical result for 2 applications: Smart Live - Smart Living and Tuya Smart.
I checked the solution given in # 31 post “Install” Package Capture “from play store …”
I used the Pocket Capture application by Gray Sh. as a result, I’ve got captures (mostly without data) Several of them contain some RAW data that totally doesn’t match the pattern.
You will need to download old version of the SmartApp however the key you will see is wrong and will not work…
I followed this guide and find the real key
I sort of successfully set up these bulbs from Amazon:
I was able to get the bulbs to turn on and off but when I added a separate MQTT color channel, the bulb would shut off and the local key would change. I can get the new key (again) and restore on/off functionality. I then tried again, except completely deleting the Smart Life app from my phone (thinking they still had a cloud connection through the app) but experienced the same result. The bulb would stop functioning and the key would change if I tried to change the color using a color channel.
Has anyone else seen these devices change their local key like that, and if so, any suggested work around?
Hi there, I have the same issue as some of you guys.
I am not able to obtain ther Key, because the preferences-file is nearly empty and all other methods I try do not work (proxy, paket capture).
Is there a way to get the Key I dont know yet?
I have an rooted Android Phone with the latest Tuya App installed.
Or is there an other way to get Tuya work with openhab2?
Even the Power Consumption information is available. The Plugs are not connected anymore to the Tuya-Cloud and MQTT works well to have them switched via Openhab.