TheAgentK / tuya-mqtt

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

ECONNREFUSED Error when trying to change lightbulb state #37

Closed MTXgames closed 3 years ago

MTXgames commented 3 years ago

Hello! So, I posted this issue to tuyapi, and from the way thy saw this it looked like this could potentially be an error within the tuya-mqtt script, so I'll post my issue here below.

Currently, I've been working on getting my tuya wifi bulbs from feit electric to connect to my openhab system. I feel like I'm VERY close to getting it all good to go, but this is my last hurdle I'm not sure how to get working properly. When I start up tuya-mqtt.js, things seem relatively fine, however when i try to switch the lightbulb on/off using the basicUI from the items and sitemap i configured, this is the debug error I get from tuya-mqtt.js: TuyAPI:mqtt MQTT-Server nicht verbunden. +0ms TuyAPI:mqtt Verbindung mit MQTT-Server hergestellt +12ms TuyAPI:mqtt receive settings {"topic":"tuya/lightbulb/XXX/XXX/XXX/command","action":"command","message":"OFF","options":{"id":"XXX","key":"XXX","ip":"XXX","type":"lightbulb"}} +8s TuyAPI:device Search device in network +0ms TuyAPI IP and ID are already both resolved. +0ms TuyAPI:device Device found in network +9ms TuyAPI Connecting to XXX... +14ms TuyAPI Error event from socket. XXX { Error: connect ECONNREFUSEDXXX:6668 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14) errno: 'ECONNREFUSED', code: 'ECONNREFUSED', syscall: 'connect', address: 'XXX', port: 6668 } +10ms TuyAPI:device:error Error: Error from socket TuyAPI:device:error at Socket.client.on.err (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:365:30) TuyAPI:device:error at Socket.emit (events.js:198:13) TuyAPI:device:error at emitErrorNT (internal/streams/destroy.js:91:8) TuyAPI:device:error at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) TuyAPI:device:error at process._tickCallback (internal/process/next_tick.js:63:19) +0ms TuyAPI:mqtt:error { error: TuyAPI:mqtt:error Error: Error from socket TuyAPI:mqtt:error at Socket.client.on.err (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:365:30) TuyAPI:mqtt:error at Socket.emit (events.js:198:13) TuyAPI:mqtt:error at emitErrorNT (internal/streams/destroy.js:91:8) TuyAPI:mqtt:error at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) TuyAPI:mqtt:error at process._tickCallback (internal/process/next_tick.js:63:19), TuyAPI:mqtt:error device: TuyAPI:mqtt:error TuyaDevice { TuyAPI:mqtt:error type: 'lightbulb', TuyAPI:mqtt:error options: TuyAPI:mqtt:error { id: 'XXX', TuyAPI:mqtt:error key: 'XXX', TuyAPI:mqtt:error ip: 'XXX', TuyAPI:mqtt:error type: 'lightbulb' } } } +0ms TuyAPI Socket closed: XXX +24ms TuyAPI:device Disconnected from device. lightbulb (XXX,XXX, XXX) +41ms TuyAPI:device delete Device lightbulb (XXX, XXX, XXX) +0ms I changed the tuyapi to the most current version in package.json, or at least i think i did, but this error still pops up. From what this looks like, I think the bulb is refusing a connection with the tuya-mqtt for some reason? all my bulbs are no longer configured to any tuya-related app. I had to do tuya-cli link along with the tuya developer instructions to get the localkeys. They seem to be connected to my wifi fine i believe since they're not blinking... I did have to specifically run that on a seperate computer from the machine OpenHAB is currently running on, as it's important to note my system has ethernet connection only. does the tuya-mqtt script only function proerly on wifi?

If there's any other details you need I'm happy to provide them! I'm still brand new at all of this, and new to linux as well, so there's a lot i'm trying to learn on the fly, and I wouldn't be surprised if this was caused by some mistake down the line. I think I Xed out all the private info, but if i missed something let me know as well. Regardless, thank you for your patience!

Current Specs that is running the processes: Linux Mint 20 v.4.6.6 intel core 2 duo CPU E6400 @ 2.13Ghz x 2 3.8GB RAM 1TB HDD intel corp. 82q963/q965 integrated graphics controller

tsightler commented 3 years ago

Are you able to control it with tuya-cli? If so, can you post the command used to do so?

Unfortunately I would consider this project mostly unmaintained at this point. I had hoped to maintain it when TheAgentK stopped, but, honestly, as Tuya has continued to make it more and more difficult to get the key for each device, especially for newer, encrypted devices, I just gave up and flashed all of my Tuya devices with Tasmota. As far as I know, it should still work, as long as you have to correct key, but I haven't used the script myself of >6 months.

MTXgames commented 3 years ago

Yeah, I was trying to avoid jumping the firmware unless it was absolutely necessary, and unfortunately it might be getting to that point. I got a wifi adapter to see if that would do anything, and re-setup the one lightbulb with tuya-cli link. everything was fine there, i successfully got the updated localkey and everything. tuya-cli is acting weird for me though; no matter what parameters i try to pass with tuya-cli get, it send me the help options (unless i'm missing something if i type, for example, tuya-cli get --all or tuya-cli get --key XXXX), and when i do tuya-cli list it returns absolutely nothing. and this was immediately after a successful tuya-cli link. I still get the same error as posted. I really appreciate your help, especially if this api is consdired unmaintained. If I can't get the problem resolved htough, i might just try out Tasmota.

tsightler commented 3 years ago

You should run tuya-cli get --id XXXX optionally with --all. Or you can try a specifying all options with debug:

DEBUG=* tuya-cli get --ip 192.168.8.109 --id xxxxxxxxxxxxxxxxxx --key xxxxxxxxxxx --all

If you can get the device to work with tuya-cli, then it should work with this script. I wouldn't say it's totally, 100% unmaintained, I'm trying to at least keep it working with the devices it's known to support, but as I've converted almost all of my devices, save one I keep around for testing, it's not likely to get any new enhancement unless somebody comes along starts contributing.

Honestly, with tuya-convert it's become so easy to flash Tasmota OTA on most of these devices, and Tasmota is so much easier to deal with, that the use of this project has simply fallen to nearly non-existent levels from what I can tell.

tsightler commented 3 years ago

BTW, you should definitely make sure you are using the latest version of this script which is at https://github.com/tsightler/tuya-mqtt. That branch was modified to work with at least the 5.1.2 tuyapi code and also supports newer 3.3 protocol devices that use encryption. I'll try to at least update the API to the latest 5.3 version and merge the code here.