TheAgentK / tuya-mqtt

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

Added the capability to set multiple dps values, added the ability to get the Status of all current dps values, and added the ability to get the Status of ONE dps value that the user specifies(STATE topic will reflect the STATUS) via MQTT channel COMMAND; Also fixed the following so they work again (ON,OFF,Toggle) #16

Closed GadgetAngel closed 5 years ago

GadgetAngel commented 5 years ago

This new update allows the user to set multiple dps' or force a status update of all dps values via MQTT messages or topics

tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/state tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command

the latest change: I got ride of the additional topic, I use the COMMAND topic. where the command topic can be followed by the JSON string for the dps settings or the message string(on="" or off="") can hold the JSON string of dps settings. The JSON string can also be for multiple dps settings. The JSON string can also force a request for all dps settings to be returned.

the "on" or "ON" or "off" or "OFF" or "1" or "0" can also follow the command topic or appear in the message area (on="" or off=""). IT all works now.

the three JSON strings are as follows:

  1. dps settings: { "dps": 1, "set": true } ----- this only sets on dps value
  2. multiple dps settings: { "multiple": true, "data": { "1": true, "7": true }
  3. this get the current state of the device: { "schema": true }

So to put this all together, the dps topic still returns the status of the device.

the state topic : tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/state

the command topic: tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command

to set one dps the command topic can look like the following: tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/ON tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/OFF tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/1 tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/0 tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/ { "dps": 1, "set": true } tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/ { "multiple": true, "data": { "1": true, "7": true } tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command/ { "schema": true }

OR command topic: tuya/tuyaAPI-type/tuyaAPI-id/tuyaAPI-key/tuyaAPI-ip/command with the on="" or off="" being used as follows: 1 0 ON OFF { "dps": 1, "set": true } { "multiple": true, "data": { "1": true, "7": true } { "schema": true }

NOTE: During my tests, i noticed that when the tuya-mqtt.exe program is first started (initial boot up) the program gets a unhandledpromise rejection warning. I found a way to suppress the error message so that the user will not see these errors in the openhab2 error log.

If you are not aware the error message only shows up on initial boot or initial communication with a tuya device. After the first communication has been establish by sending the first command twice in a row then as long as the tuya-mqtt server is up and running and have talked to the device, the error will not return until reboot of the tuya-mqtt server.

Therefore, users should be made aware of openhab2 that if they use tuya-mqtt.exe they should upon reboot send two state commands to each device they plan to talk to ( { "schema": true } ).

I believe this is a TCP/IP problem. These tuya devices use a TCP and that protocol is not considered to be deterministic. The error message is coming from a routine outside the scope of tuya-mqtt code.

Here is the output of the init error (this is all the debug statements -TuyAPI debugs from sending one command topic:

================================================

TuyAPI-device switch -> OFF +1ms (node:2104) UnhandledPromiseRejectionWarning: Error: No connection has been made to the device. at TuyaDevice._send (C:\Users\joann\WebstormProjects\tuya-mqtt\node_modules\tuyapi\index.js:245:13) at Promise (C:\Users\joann\WebstormProjects\tuya-mqtt\node_modules\tuyapi\index.js:105:14) at new Promise () at TuyaDevice.get (C:\Users\joann\WebstormProjects\tuya-mqtt\node_modules\tuyapi\index.js:102:12) at TuyaDevice.get (C:\Users\joann\WebstormProjects\tuya-mqtt\tuya-device.js:114:28) at TuyaDevice.switchOff (C:\Users\joann\WebstormProjects\tuya-mqtt\tuya-device.js:190:16) at TuyaDevice.switch (C:\Users\joann\WebstormProjects\tuya-mqtt\tuya-device.js:160:18) at MqttClient. (C:\Users\joann\WebstormProjects\tuya-mqtt\tuya-mqtt.js:120:34) at MqttClient.emit (events.js:189:13) at MqttClient._handlePublish (C:\Users\joann\WebstormProjects\tuya-mqtt\node_modules\mqtt\lib\client.js:987:12) (node:2104) 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: 4) TuyAPI-device Connected to device. +99ms TuyAPI-device Data from device: { devId: '5846055184f3eb20bfaf', dps: { '1': true, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +15ms tuyAPI-Events Data from device lightbulb : { devId: '5846055184f3eb20bfaf', dps: { '1': true, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +45s tuyAPI-Events mqtt status updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state -> ON +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps -> {"1":true,"2":"colour","3":27,"4":255,"5":"ffc400002effff","6":"c479000025ffc3","7":"ffff320100ff00","8":"ffff2003ff000000ff000000ff","9":"ffff2001ff0000","10":"ffff3205ff000000ff00ffff00ff00ff0000ff"} +4ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/1 -> dps[1] true +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/2 -> dps[2] "colour" +2ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/3 -> dps[3] 27 +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/4 -> dps[4] 255 +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/5 -> dps[5] "ffc400002effff" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/6 -> dps[6] "c479000025ffc3" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/7 -> dps[7] "ffff320100ff00" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/8 -> dps[8] "ffff2003ff000000ff000000ff" +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/9 -> dps[9] "ffff2001ff0000" +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/10 -> dps[10] "ffff3205ff000000ff00ffff00ff00ff0000ff" +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +141ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +4ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +4ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +8s tuya-mqtt message off +4ms TuyAPI-device switch: off +8s TuyAPI-device switch -> OFF +1ms TuyAPI-device Data from device: { devId: '5846055184f3eb20bfaf', dps: { '1': true, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +9ms tuyAPI-Events Data from device lightbulb : { devId: '5846055184f3eb20bfaf', dps: { '1': true, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +8s tuyAPI-Events mqtt status updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state -> ON +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps -> {"1":true,"2":"colour","3":27,"4":255,"5":"ffc400002effff","6":"c479000025ffc3","7":"ffff320100ff00","8":"ffff2003ff000000ff000000ff","9":"ffff2001ff0000","10":"ffff3205ff000000ff00ffff00ff00ff0000ff"} +4ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/1 -> dps[1] true +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/2 -> dps[2] "colour" +2ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/3 -> dps[3] 27 +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/4 -> dps[4] 255 +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/5 -> dps[5] "ffc400002effff" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/6 -> dps[6] "c479000025ffc3" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/7 -> dps[7] "ffff320100ff00" +2ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/8 -> dps[8] "ffff2003ff000000ff000000ff" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/9 -> dps[9] "ffff2001ff0000" +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/10 -> dps[10] "ffff3205ff000000ff00ffff00ff00ff0000ff" +4ms TuyAPI-device From .set routine: Setting status: { set: false } +28ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +44ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +5ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +4ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms TuyAPI-device Data from device: { devId: '5846055184f3eb20bfaf', dps: { '1': false }, t: 1554360569, s: 256 } +79ms tuyAPI-Events Data from device lightbulb : { devId: '5846055184f3eb20bfaf', dps: { '1': false }, t: 1554360569, s: 256 } +82ms tuyAPI-Events mqtt status updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state -> OFF +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps -> {"1":false} +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/1 -> dps[1] false +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +57ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +4ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms TuyAPI-device Data from device: { devId: '5846055184f3eb20bfaf', dps: { '1': false, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +22ms tuyAPI-Events Data from device lightbulb : { devId: '5846055184f3eb20bfaf', dps: { '1': false, '2': 'colour', '3': 27, '4': 255, '5': 'ffc400002effff', '6': 'c479000025ffc3', '7': 'ffff320100ff00', '8': 'ffff2003ff000000ff000000ff', '9': 'ffff2001ff0000', '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +18ms tuyAPI-Events mqtt status updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/state -> OFF +5ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps -> {"1":false,"2":"colour","3":27,"4":255,"5":"ffc400002effff","6":"c479000025ffc3","7":"ffff320100ff00","8":"ffff2003ff000000ff000000ff","9":"ffff2001ff0000","10":"ffff3205ff000000ff00ffff00ff00ff0000ff"} +3ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/1 -> dps[1] false +2ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/2 -> dps[2] "colour" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/3 -> dps[3] 27 +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/4 -> dps[4] 255 +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/5 -> dps[5] "ffc400002effff" +2ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/6 -> dps[6] "c479000025ffc3" +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/7 -> dps[7] "ffff320100ff00" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/8 -> dps[8] "ffff2003ff000000ff000000ff" +0ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/9 -> dps[9] "ffff2001ff0000" +1ms tuyAPI-Events mqtt dps updated to:tuya/lightbulb/5846055184f3eb20bfaf/afb9b013346054e6/192.168.0.30/dps/10 -> dps[10] "ffff3205ff000000ff00ffff00ff00ff0000ff" +1ms TuyAPI-device From .set routine: Result of setting status to false +21ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +33ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +3ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +4ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +2ms tuya-mqtt device { type: 'lightbulb', id: '5846055184f3eb20bfaf', key: 'afb9b013346054e6', ip: '192.168.0.30' } +1ms

=========================================================

i hope this helps.

GadgetAngel commented 5 years ago

I updated my branch again. This time I incorporated the ability of the user to request or query the tuya device on one of its dps States. The MQTT topic STATE will reflect the value of that dps until the next command is sent.

Usually MQTT Topic only displays the STATE of DPS=1 but if the user uses the following JSON string it can the server will display the STATE of the specified DPS in the STATE TOPIC

The JSON string: { "dps": 7 }

I got the update pushed to you. Have fun.

TheAgentK commented 5 years ago

Hey @GadgetAngel,

I've finally seen through your pull request.

The implemented functions are as follows:

  1. error during start (fixed by using domain)
  2. set multiple dps values over /command topic
  3. custom dps value for /state topic
  4. README updated

Have I forgotten another function?

I looked through your code and think that feature 2 (set multiple dps values ) really needs to be integrated. That's why I integrated it on the DEV branch.

The bug during startup is already fixed with the latest version of TuyAPI and all changes on the DEV branch. Thus the use of "domain" is not necessary.

I don't think it makes sense to define your own DPS value for the /state-topic, because the topic /dpsor /dps/<tuya-dps-id> can be used to read all DPS values. I thought about deleting the /state topic completely in the future.

I'll also look through your updated readme, and take parts of it for sure.

Maybe you take a look at my DEV-branch and give me your feedback.

EDIT: Reusing Topic's is, to my knowledge, not really MQTT-like and to send commands as part of the Topic is not the best way to use MQTT.

In the future you could maybe open single pull requests for each feature.

Reference: https://github.com/TheAgentK/tuya-mqtt/tree/dev

GadgetAngel commented 5 years ago

I can live with your decision. BTW, I will continue to test it. I still get the error, I think its because my machine is really fast. When running this on a raspberry pi, there is not a lot of memory and speed on a raspberry pi. I think some of the problem is due to the fact that we are dealing with a non-deterministic approach to talking to these devices. Do you know how much of the TCP/IP protocol was implemented?? I really have not look that deeply into the index.js file of the TuyAPI code yet.