Closed lucs7 closed 5 years ago
Hi @lucs7 - I had the same issue and just figured out a fix. It seems the dps property (1) that contains the state is only sent by the device when the state changes. The device is constantly chirping away with various other updates and for each update, the tuya-mqtt.js script tries to get the state and publish it. When it's not there, the state bmap reports OFF. So I think we need a little logic to check if the status is set before publishing it.
@TheAgentK - (thanks very much for your excellent work by the way - great script) - I've made a tweak that resolves the issue for me. Not sure what the etiquette is on sending pull requests, so I've just pasted my suggested fix for tuya-mqtt.js below. I'm only using sockets, so not sure how this affects lightbulbs and whether the existing lightbulb specific IF does the same thing.
TuyaDevice.onAll('data', function (data) {
try {
debugTuya('Data from device ' + this.type + ' :', data);
var status = data.dps['1'];
if (this.type == "lightbulb" && status == undefined) {
status = true;
}
if(status !== undefined){
debugTuya('Status is defined as ' + status);
publishStatus(this, bmap(status));
}
publishDPS(this, data.dps);
} catch (e) {
debugError(e);
}
});
Now i set the status only if it realy exists. If dps[1] does not exist, then nothing happens.
No i set the status only if it realy exists. If dps[1] does not exist, then nothing happens.
I've pulled the latest code to test/sync with your repo & it works for me - thanks for updating so quickly @TheAgentK. @lucs7 - I'm sure this will do the job for you too.
@samlangdon nice to hear my changes solved the problem.
Great project! I tried the wrapper in a small linux test environment and it seems to work and detect device switches correctly. Unfortunately right after the first correct state, i get a constant stream of 'off' state messages from the state topic.
Ubuntu 18.04 Mosquito in a docker 1.5 nodejs v8.10.0
I am using a TECKIN WLAN Smart socket.
Steps to reproduce the behavior:
I would expect the wrapper to send the current status. Maybe I'm understanding mqqt wrong and this is a retained message? Any idea how to solve this? I would attach the debug output, but I don#t have a lot of experience in nodejs and don#t know how to pipe the node console outputin a file.
thanks for any help