I checked again in debuger. The API returns a “invalid token” result with code 1010 although the token should have a longer lifetime based on the token expirer timestamp.
I changed the API code a bit to solve this error code :
async sendCommand(deviceID, params) {
this.log.log("TuyaSHOpenAPI: sendCommand()");
let res = await this.post(`/v1.0/devices/${deviceID}/commands`, params);
this.log.log("TuyaSHOpenAPI: sendCommand result:");
this.log.log(res);
if (res.success == false && res.code == 1010){
// force re-auth
this.tokenInfo.expire = 0;
this.log.log("Error on sendCommand, force re-auth.")
res = await this.post(`/v1.0/devices/${deviceID}/commands`, params);
this.log.log("TuyaSHOpenAPI: sendCommand result:");
this.log.log(res);
}
return res.result;
}
I added some log lines and the IF statement which cleares the token expire timestamp and calls the POST function again, which is refreshing the token.
That’s working fine now. I will check it today and if all if ok, I will create a PR - if fou prefer this change, too.