Tuya integration: problem with status updates when running 2 instances of HA


  • sometimes you don’t get the correct status of a light
  • digging into the debug logs, you can see that sometimes a POST is done to Tuya with a wrong token, a new token will be generated, but the POST action is not repeated (thus light will not be turned on in my case)

typical log:

2022-09-19 15:32:48.845 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Sending PINGREQ
2022-09-19 15:32:48.873 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Received PINGRESP
2022-09-19 15:33:21.383 DEBUG (SyncWorker_10) [tuya_iot] Request: method = POST,                 url = https://openapi.tuyaeu.com/v1.0/devices/bf9f25b49af00347bf85fj/commands,                params = None,                body = {'commands': [{'code': <DPCode.SWITCH_LED: 'switch_led'>, 'value': True}]},                t = 1663594401383
2022-09-19 15:33:21.625 DEBUG (SyncWorker_10) [tuya_iot] Response: {
  "code": 1010,
  "msg": "token invalid",
  "success": false,
  "t": 1663594400802,
  "tid": "a09b01a3381f11ed81b21613c76f6213"
2022-09-19 15:33:21.626 DEBUG (SyncWorker_10) [tuya_iot] Request: method = POST,                 url = https://openapi.tuyaeu.com/v1.0/iot-01/associated-users/actions/authorized-login,                params = None,                body = {'username': '[email protected]', 'password': '***', 'country_code': '32', 'schema': 'tuyaSmart'},                t = 1663594401626
2022-09-19 15:33:21.788 DEBUG (SyncWorker_10) [tuya_iot] Response: {
  "result": {
    "access_token": "***",
    "expire_time": 7200,
    "platform_url": "https://openapi.tuyaeu.com",
    "refresh_token": "***",
    "uid": "***"
  "success": true,
  "t": 1663594400933,
  "tid": "a0a49990381f11eda6de1a46e4e2cc74"
2022-09-19 15:33:48.943 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Sending PINGREQ
2022-09-19 15:33:48.971 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Received PINGRESP
2022-09-19 15:34:49.048 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Sending PINGREQ
2022-09-19 15:34:49.079 DEBUG (Thread-10 (_thread_main)) [tuya_iot] _on_log: Received PINGRESP

Does anybody experience the same problem with the TUYA Cloud integration?

kind regards,
Bart Plessers

See also

I had the same problem and took me ages to work out the cause was my two HA instances. To fix it, you can create two projects in tuya cloud. You then need to make sure the smartlife app in tuya cloud is linked to each project. You now have client credentials specific to each project and so now you can use per instance when setting up the tuya integration in HA.

1 Like