TheAgentK / tuya-mqtt

Nodejs-Script to combine tuyaapi and openhab via mqtt
MIT License
173 stars 80 forks source link

Roller Shutter doesn't work #29

Closed RobsonW70 closed 3 years ago

RobsonW70 commented 4 years ago

HI

I have problem with RollerShutter When I use command from NJSTuya - is no problem node Njstuja -id xxxxxxxxx -keyxxxxxxxxxxxxx -ipxxxxxxxxxxxxx -set '{"set":"1"}' \But I can't use in similar way tuya-mqtt Whhn I setup "Open" as a {"set":"1") close {"set":"2"} or stop {"set":"3"} I can't manage it ;( for Rollershutter But when I use "Switch" object I can setup using on-{"set":"1") off-{"set":"2"} but I have no third otpion to stop it;( May i ak you where is the problem I have OpenHab2.4 and MQtt broker 2.4 I testes on tuya-mqtt from TheAgentK and from tsightler on both the same error (if u want Received data in details - let me know I can generate it but i don't want any data on the portal ;)

12:34:01] openhabian@openhab:/etc/openhab2/scripts/tuya-mqtt3$ DEBUG=* node tuya-mqtt.js TuyAPI:mqtt Connection established to MQTT server +0ms TuyAPI:mqtt receive settings {"topic":"tuya/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx/192.168.x.xxx/command","action":"command","message":"100","options":{"id":"xxxxxxxxxxxxxxxxxxxx","key":"xxxxxxxxxxxxxxxxxxxx","ip":"192.168.x.xxx"}} +4s TuyAPI:device Search device in network +0ms TuyAPI IP and ID are already both resolved. +0ms TuyAPI:device Device found in network +7ms TuyAPI Connecting to 192.168.x.xxx... +10ms TuyAPI Socket connected. +8ms TuyAPI:device Connected to device. (192.168.x.xxx, xxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxx) +14ms TuyAPI GET Payload: +3ms TuyAPI { gwId: 'xxxxxxxxxxxxxxxxxxxx', devId: 'xxxxxxxxxxxxxxxxxxxx' } +1ms TuyAPI:mqtt command is JSON +55ms TuyAPI:mqtt receive command 100 +0ms TuyAPI:device set: 100 +29ms (node:31548) UnhandledPromiseRejectionWarning: TypeError: No arguments were passed. at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt3/node_modules/tuyapi/index.js:158:13) at Promise (/etc/openhab2/scripts/tuya-mqtt3/tuya-device.js:158:25) at new Promise () at TuyaDevice.set (/etc/openhab2/scripts/tuya-mqtt3/tuya-device.js:157:16) at /etc/openhab2/scripts/tuya-mqtt3/tuya-mqtt.js:346:33 at process._tickCallback (internal/process/next_tick.js:68:7) (node:31548) 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: 2) (node:31548) [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. TuyAPI Received data: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +35ms TuyAPI Parsed: +7ms TuyAPI { payload: 'json obj data unvalid', TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 } +0ms TuyAPI:device:error Data from device not encrypted: json obj data unvalid +0ms (node:31548) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of undefined at _send.then.data (/etc/openhab2/scripts/tuya-mqtt3/node_modules/tuyapi/index.js:122:29) at process._tickCallback (internal/process/next_tick.js:68:7) (node:31548) 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) TuyAPI Pinging 192.168.x.xxx +10s TuyAPI Received data: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx+5ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms

tsightler commented 4 years ago

To me the telling part of this is here:

{"topic":"tuya/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx/192.168.x.xxx/command","action":"command", "message":"100","options":{"id":"xxxxxxxxxxxxxxxxxxxx","key":"xxxxxxxxxxxxxxxxxxxx","ip":"192.168.x.xxx"}}

and here:

TuyAPI:device set: 100 +29ms

The "message" should be the set command {"set":"1"}, but instead it is 100, which is absolutely an invalid message and certainly not JSON. Now, I'm not sure why OpenHab is sending that, but it's obviously not the correct JSON data being sent.

I would suggest trying it with mosquitto_pub from command line:

mosquitto_pub -t tuya/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx/192.168.x.xxx/command -m '{"set": 1}'

There does seem to be a bug in the handling of quotes in the value string, but the command above works for me and I'm going to guess it will work for you and show that tuya-mqtt works fine if it receives the correct message.

RobsonW70 commented 4 years ago

I know that the number is set as a percentage of the roller shutter process closing How can i do remove is from the MQTT object image I can't use 100 or 0 for opening or closing - just open, close , stop

RobsonW70 commented 4 years ago

mosquitto_pub -t tuya/xxxxxxxxxxxxxxxxxxxx/xxxxxxxxxxxxxxxxxxxx/192.168.x.xxx/command -m '{"set": 1}'

Works \NJStuya as well when I do it form the hand but I need to have object in Openhab with 3 butttons; Open, stop, close I can;t find any object exept Roller shutter which uses percentage as well ;(

tsightler commented 3 years ago

This should works, tuya-mqtt can set any DPS value, just a matter of getting the transforms correct in OpenHAB. I don't use OpenHAB but the community there should be able to help. If you work out the ways to set the DPS values and the transforms it should be no issue.