# \[APP\]\[Pro\] Tuya Cloud - This app allows you to connect Homey to the Tuya cloud

**URL:** <https://community.homey.app/t/app-pro-tuya-cloud-this-app-allows-you-to-connect-homey-to-the-tuya-cloud/21313>\
**Category:** Apps\
**Tags:** app, unofficial, wifi, homey-pro\
**Created:** [November 25, 2019, 5:31pm UTC](https://community.homey.app/t/app-pro-tuya-cloud-this-app-allows-you-to-connect-homey-to-the-tuya-cloud/21313 "2019-11-25T17:31:12Z")\
**Posts on this page:** 1\
**Showing post:** 947

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [September 2, 2022, 3:36pm UTC](https://community.homey.app/t/app-pro-tuya-cloud-this-app-allows-you-to-connect-homey-to-the-tuya-cloud/21313/947 "2022-09-02T15:36:34Z")

</div>

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 :

```auto
    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.

---

_[View the full topic](https://community.homey.app/t/app-pro-tuya-cloud-this-app-allows-you-to-connect-homey-to-the-tuya-cloud/21313)._
