Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intermittent failures in Home Assistant - "error while get mqtt config" #50

Open
alexanv1 opened this issue Dec 15, 2021 · 7 comments · May be fixed by #59
Open

Intermittent failures in Home Assistant - "error while get mqtt config" #50

alexanv1 opened this issue Dec 15, 2021 · 7 comments · May be fixed by #59

Comments

@alexanv1
Copy link

I am seeing intermittent issues in Home Assistant that started 2-3 days ago.
The logs show the following errors:

2021-12-15` 07:39:57 ERROR (Thread-5411) [tuya_iot] Unexpected disconnection.7
2021-12-15 07:40:01 ERROR (Thread-5411) [tuya_iot] Unexpected disconnection.5
2021-12-15 07:49:04 ERROR (Thread-5411) [tuya_iot] Unexpected disconnection.7
2021-12-15 11:37:53 ERROR (Thread-34) [tuya_iot] error while get mqtt config

Once this occurs, devices no longer reflect their current state in Home Assistant and changing the state (turning on\off\etc) does not work either.
Reloading the integration in Home Assistant works fine for a few hours which implies that the issue is intermittent but seems to put tuya_iot in a bad state until reloaded.

I've already checked the project on Tuya IoT to ensure all needed APIs are enabled as per instructions (also it was working fine for many weeks until the issues started a couple of days ago).

Given that the integration reload in Home Assistant fixes the issue, it seems that tuya_iot should be able to handle this as well by retrying\reconnecting\etc.

@sharoltd
Copy link

Many people with such problem last few days, but no way to fix it ((

@vdbosch
Copy link

vdbosch commented Dec 16, 2021

Same issues here. All devices seems to lose connection, after restarting Tuya integrations it works again for some time (a few hours). It's absolutely not stable at this moment. Problem with 11.5 and with 2021.1.12. It looks that there are problems with the Tuya API/ Tuya Cloud and has nothing to do with the version of Home Assistant nor OS-version. I have same problems with my test-box (used old version and new version and different versions of OS).

@bpfoster
Copy link

I'm also having the same issue all of a sudden. Added in some logging to the openmqtt method _get_mqtt_config() to see what the error from the API is:

{'code': 1010, 'msg': 'token is expired', 'success': False, 't': 1639929045868}

So it would appear the auth token is expiring and not being correctly refreshed by the client.

@sharoltd
Copy link

I'm also having the same issue all of a sudden. Added in some logging to the openmqtt method _get_mqtt_config() to see what the error from the API is:

{'code': 1010, 'msg': 'token is expired', 'success': False, 't': 1639929045868}

So it would appear the auth token is expiring and not being correctly refreshed by the client.

I asked IOT.tuya support about this, they ask me "Where did you see the API you called,Could you please provide the address you saw" ;)))

bpfoster added a commit to bpfoster/tuya-iot-python-sdk that referenced this issue Dec 20, 2021
@bpfoster
Copy link

This was fixed in tuya-iot-python-sdk v0.6.6 which was included in Home Assistant 2021.12.6.

@coolnetworks
Copy link

it is still happening here 17 March 2022 fully patched

helldog136 added a commit to helldog136/tuya-iot-python-sdk that referenced this issue May 15, 2022
@helldog136
Copy link

Looks like the url to refresh mqtt config is wrong : https://developer.tuya.com/en/docs/cloud/c2c2630d7c?id=Kb68mozbi3foh
Or am I mistaken here?
The code seems to make requests to (openmq.py - l25-26)

TO_C_CUSTOM_MQTT_CONFIG_API = "/v1.0/iot-03/open-hub/access-config"
TO_C_SMART_HOME_MQTT_CONFIG_API = "/v1.0/open-hub/access/config"

These URLS are used at lines 62-81:

    def _get_mqtt_config(self) -> Optional[TuyaMQConfig]:
        response = self.api.post(
            TO_C_CUSTOM_MQTT_CONFIG_API
            if (self.api.auth_type == AuthType.CUSTOM)
            else TO_C_SMART_HOME_MQTT_CONFIG_API,
            {
                "uid": self.api.token_info.uid,
                "link_id": LINK_ID,
                "link_type": "mqtt",
                "topics": "device",
                "msg_encrypted_version": "2.0"
                if (self.api.auth_type == AuthType.CUSTOM)
                else "1.0",
            },
        )

        if response.get("success", False) is False:
            return None

        return TuyaMQConfig(response)

This code doesn't match the actual documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants