codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 332 forks source link

Ping/Pong loop GU10 LSC device #353

Closed gewonecolalight closed 3 years ago

gewonecolalight commented 3 years ago

I am pretty new to this, but the few last days I learned a lot from various topics here and support site from Openhab2. I succesfully added a LSC color Lightbulb (E27) from the Action in Holland to Openhab2 and can use it with mqtt. I obtained the deviceID and localKey for this through the Smart Life app (old version). It uses protocol version 3.3.

Now I try to configure the next lamp. It is a GU10 (white only) device als from the Action in Holland. I also obtained the device ID and localKey. I configured it the same as tje Color light bulb. Now from within Openhab2 I could not get it working, so tried to use the tuyapi-cli to figure out was was going wrong.

When I do a 'get' I get the following: ' [14:04:36] root@openHAB:/etc/openhab2/scripts/tuya-mqtt# DEBUG=* tuya-cli get --id 02083685d8f15bbd6601 --key xxxxxxxxxxxxxxxx --ip 10.2.2.151 --protocol-version 3.3 TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 10.2.2.151... +1ms TuyAPI Socket connected. +7ms TuyAPI GET Payload: +0ms TuyAPI { TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI devId: '02083685d8f15bbd6601', TuyAPI t: '1600344773', TuyAPI dps: {}, TuyAPI uid: '02083685d8f15bbd6601' TuyAPI } +0ms TuyAPI GET Payload: +3ms TuyAPI { TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI devId: '02083685d8f15bbd6601', TuyAPI t: '1600344773', TuyAPI dps: {}, TuyAPI uid: '02083685d8f15bbd6601' TuyAPI } +0ms TuyAPI Received data: 000055aa000000010000000a0000009c00000000c2b3f62a2410f7ea441d02dee406ffc9b506c775d916189bc241253c2cd46201121c3de971113f31816f912218656cedce103f7578b503445fd26e1e6f40a7db0bf5c77bf890214e08c8e61b23015804617cefacd108252992f5bb7a5b7e52a8f91b74be279356a98b5b7c033e3647bbf512c2eac02d10fefcaa6a3e7b082eb8780f8bb40d046f229aa5282d007093728bfa5a370000aa55 +38ms TuyAPI Parsed: +1ms TuyAPI { TuyAPI payload: { TuyAPI devId: '02083685d8f15bbd6601', TuyAPI dps: { TuyAPI '20': true, TuyAPI '21': 'white', TuyAPI '22': 1000, TuyAPI '23': 0, TuyAPI '25': '000e0d0000000000000000c80000', TuyAPI '26': 0, TuyAPI '101': true TuyAPI } TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 TuyAPI } +0ms TuyAPI Received data: 000055aa000000020000000a0000009c00000000c2b3f62a2410f7ea441d02dee406ffc9b506c775d916189bc241253c2cd46201121c3de971113f31816f912218656cedce103f7578b503445fd26e1e6f40a7db0bf5c77bf890214e08c8e61b23015804617cefacd108252992f5bb7a5b7e52a8f91b74be279356a98b5b7c033e3647bbf512c2eac02d10fefcaa6a3e7b082eb8780f8bb40d046f229aa5282d00709372190f32fe0000aa55 +41ms TuyAPI Parsed: +0ms TuyAPI { TuyAPI payload: { TuyAPI devId: '02083685d8f15bbd6601', TuyAPI dps: { TuyAPI '20': true, TuyAPI '21': 'white', TuyAPI '22': 1000, TuyAPI '23': 0, TuyAPI '25': '000e0d0000000000000000c80000', TuyAPI '26': 0, TuyAPI '101': true TuyAPI } TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 2 TuyAPI } +0ms TuyAPI Disconnect +1ms undefined TuyAPI Socket closed: 10.2.2.151 +1ms '

When I do a 'set' I get the following: ' [13:58:43] root@openHAB:/etc/openhab2/scripts/tuya-mqtt# DEBUG=* tuya-cli set --id 02083685d8f15bbd6601 --key xxxxxxxxxxxxxxxx --ip 10.2.2.151 --protocol-version 3.3 --set OFF TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 10.2.2.151... +1ms TuyAPI Socket connected. +21ms TuyAPI GET Payload: +1ms TuyAPI { TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI devId: '02083685d8f15bbd6601', TuyAPI t: '1600343960', TuyAPI dps: {}, TuyAPI uid: '02083685d8f15bbd6601' TuyAPI } +0ms TuyAPI SET Payload: +2ms TuyAPI { TuyAPI devId: '02083685d8f15bbd6601', TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI uid: '', TuyAPI t: 1600343959, TuyAPI dps: { '1': 'OFF' } TuyAPI } +1ms TuyAPI Received data: 000055aa000000010000000a0000009c00000000c2b3f62a2410f7ea441d02dee406ffc9b506c775d916189bc241253c2cd46201121c3de971113f31816f912218656cedce103f75 78b503445fd26e1e6f40a7db0bf5c77bf890214e08c8e61b23015804617cefacd108252992f5bb7a5b7e52a8f91b74be279356a98b5b7c033e3647bbf512c2eac02d10fefcaa6a3e7b082eb8780f8bb40d046f22 9aa5282d007093728bfa5a370000aa55 +36ms TuyAPI Parsed: +1ms TuyAPI { TuyAPI payload: { TuyAPI devId: '02083685d8f15bbd6601', TuyAPI dps: { TuyAPI '20': true, TuyAPI '21': 'white', TuyAPI '22': 1000, TuyAPI '23': 0, TuyAPI '25': '000e0d0000000000000000c80000', TuyAPI '26': 0, TuyAPI '101': true TuyAPI } TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 TuyAPI } +0ms TuyAPI Received data: 000055aa00000002000000070000000c0000000018cfc5da0000aa55 +24ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 2 } +0ms TuyAPI Got SET ack. +0ms TuyAPI Pinging 10.2.2.151 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +14ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 10.2.2.151 +0ms TuyAPI Pinging 10.2.2.151 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +10ms TuyAPI Parsed: +1ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 10.2.2.151 +0ms TuyAPI Pinging 10.2.2.151 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +13ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 10.2.2.151 +0ms TuyAPI Pinging 10.2.2.151 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +11ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms TuyAPI Pong from 10.2.2.151 +0ms '

It then hangs in a loop untill I end it.

Also when I once try to use mqtt from Openhab2, and then I do a 'get', I get the following: ' [14:16:46] root@openHAB:/etc/openhab2/scripts/tuya-mqtt# DEBUG=* tuya-cli get --id 02083685d8f15bbd6601 --key xxxxxxxxxxxxxxxx --ip 10.2.2.151 --protocol-version 3.3 TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 10.2.2.151... +2ms TuyAPI Socket connected. +10ms TuyAPI GET Payload: +0ms TuyAPI { TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI devId: '02083685d8f15bbd6601', TuyAPI t: '1600345140', TuyAPI dps: {}, TuyAPI uid: '02083685d8f15bbd6601' TuyAPI } +0ms TuyAPI GET Payload: +3ms TuyAPI { TuyAPI gwId: '02083685d8f15bbd6601', TuyAPI devId: '02083685d8f15bbd6601', TuyAPI t: '1600345140', TuyAPI dps: {}, TuyAPI uid: '02083685d8f15bbd6601' TuyAPI } +1ms TuyAPI Error event from socket. 10.2.2.151 Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:205:27) { errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } +10ms events.js:292 throw er; // Unhandled 'error' event ^

Error: Error from socket at Socket. (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:350:30) at Socket.emit (events.js:315:20) at emitErrorNT (internal/streams/destroy.js:92:8) at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) at processTicksAndRejections (internal/process/task_queues.js:84:21) Emitted 'error' event on TuyaDevice instance at: at Socket. (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:350:16) at Socket.emit (events.js:315:20) [... lines matching original stack trace ...] at processTicksAndRejections (internal/process/task_queues.js:84:21) '

After that, I need to power down the lamp and back on before I can do a normal 'get' from the cli. Is it possible that this device is much differtent then the other one and needs a different configuration or something?

codetheweb commented 3 years ago

For tuya-cli, the device returns this for GET:

TuyAPI dps: {
TuyAPI '20': true,
TuyAPI '21': 'white',
TuyAPI '22': 1000,
TuyAPI '23': 0,
TuyAPI '25': '000e0d0000000000000000c80000',
TuyAPI '26': 0,
TuyAPI '101': true
TuyAPI }

However, you try to set it with

TuyAPI dps: { '1': 'OFF' }

Instead, try tuya-cli set ... --dps [20|101] --set [false|true].

gewonecolalight commented 3 years ago

Ok tnx!. That makes sense. Now I can manage the lamp from Openhab without problems. However when I do that and show the DEBUG logging, it still throws me the ECONNRESET error (probably after the action). Don't know if that is a problem.

Anyway. I am a step further now. Thank you!

codetheweb commented 3 years ago

Inconsistent ECONNRESET errors usually are caused by something else trying to control your device at the same time.

gewonecolalight commented 3 years ago

Ok tnx again. Will figure that out.