Tuya Online Acting Strange Last Week

Hi there!

I am trying to diagnose why the tuya online official integration is loosing contact to the cloud as it seems.

I’ve noticed that sensors wouldn’t update and when that happens, I can’t switch things on or off. The intergration appears to be at running state.

If I reload the integration or reboot my HA instance, sensors go online, but only for a few minutes and they are out again.

I will eventually migrate to localtuya but at least until last week, the online integration was working.

Any1 facing such behavior?

ATM I have 95 IOT tuya based devices. Is there a limit for registered devices or traffic generated by them?

Thanks in advance!

I am facing the exact same issue until now.

Every time I reload the integartion, it works for 1-2 minutes and then it stops.

i’ve heard something related to a backbone change in Tuya and a different timeout that they were enoforcing. Seems like it’s not widesrpead (or we would’ve found more people complaining), but it definitelly affects my case.

I still wasn’t able to find a solution or workaround. Any luck in your end ?

No luck here, Still happening. Sometimes it works for ten minutes, sometimes for 10 hours, couldn’t find a pattern.

In fact I couldnt even find something in the logs in debugging mode that would inidicate a problem.

Days ago, I fed gpt with a part of the log and it said that it found 2 errors and in summary:

" From the logs you provided, the diagnosed cause of the issue is:

The official Tuya integration in Home Assistant is intermittently losing its authentication session with the Tuya Cloud.
This is evidenced by recurring sign invalid and permission deny errors, which indicate the request signature or authentication token has expired or become invalid — often due to clock drift or session timeout.

When this happens, Home Assistant stops receiving device state updates over the Tuya MQTT/WebSocket connection.
Attempts to refresh the device cache then hit a global task timeout, likely worsened by the large number of Tuya devices (~90 in your setup), causing the integration to remain in a “frozen” state until it is manually reloaded."

Problem is, couldn’t find these “sign invalid” and “permission deny” in the logs.

@bernardofortes fyi I am testing an idea: detecting when the tuya integration freezes and restarting it automatically. I am not a yaml expert nor coding wizard, but afaict gpt did a pretty good job helping me setting this up.

Right now I am doing this using this logic:

I have an integral helper that takes a power reading and output a kwh. Since I am monitoring a plug that is always under load, this helper is always increasing, EXCEPT when the tuya integration fails.

So, when the value of the helper won´t change for 15 minutes, it restarts the integration.

If it works, I will post it here.

Hi, I installed a wallbox that I connect to the SmartLife app to manage my car’s charging current.
If possible, I’d like to manage the charging current with a Raspberry Pi script, sending commands via the Tuya cloud. I’ve already connected the wallbox to the app and have all the necessary login credentials.
I tried creating a text script, but it always gives me an error.

import requests
import time
import hashlib
import hmac

CLIENT_ID = “ygx8…”
CLIENT_SECRET = “0b7…”
DEVICE_ID = “bf…”

BASE_URL = “https://openapi.tuyaeu.com

def sign_request(client_id, client_secret, access_token, t, method, path, body=“”):
content_md5 = “” # body vuoto, md5 vuoto
content_type = “”
# Costruisco la stringa da firmare con \n reali
string_to_sign = f"{method}\n{content_md5}\n{content_type}\n{t}\n{path}"
message = client_id + access_token + t + string_to_sign
signature = hmac.new(client_secret.encode(‘utf-8’),
msg=message.encode(‘utf-8’),
digestmod=hashlib.sha256).hexdigest().upper()
return signature, string_to_sign

def get_token():
t = str(int(time.time() * 1000))
path = “/v1.0/token?grant_type=1”
method = “GET”
access_token = “”

sign, string_to_sign = sign_request(CLIENT_ID, CLIENT_SECRET, access_token, t, method, path)

headers = {
    "client_id": CLIENT_ID,
    "sign": sign,
    "t": t,
    "sign_method": "HMAC-SHA256"
}

print("=== TOKEN REQUEST ===")
print("Stringa da firmare:")
print(string_to_sign)
print("Firma calcolata:", sign)

url = BASE_URL + path
response = requests.get(url, headers=headers)
print("Risposta server:", response.text)
data = response.json()
if data.get("success"):
    return data["result"]["access_token"]
else:
    raise Exception(f"Errore token: {data}")

def get_device_status(token):
t = str(int(time.time() * 1000))
path = f"/v1.0/devices/{DEVICE_ID}/status"
method = “GET”
body = “”
sign, string_to_sign = sign_request(CLIENT_ID, CLIENT_SECRET, token, t, method, path, body)

headers = {
    "client_id": CLIENT_ID,
    "access_token": token,
    "sign": sign,
    "t": t,
    "sign_method": "HMAC-SHA256"
}

print("\n=== DEVICE STATUS REQUEST ===")
print("Stringa da firmare:")
print(string_to_sign)
print("Firma calcolata:", sign)

url = BASE_URL + path
response = requests.get(url, headers=headers)
print("Risposta server:", response.text)

if name == “main”:
token = get_token()
get_device_status(token)


here’s the error:

PS C:\Users\remod\Desktop\walbox> python .\walbox_status.py
=== TOKEN REQUEST ===
Stringa da firmare:
GET

1754754603731
/v1.0/token?grant_type=1
Firma calcolata: 010057068742C216387FFF7472E2BD745E69F18C18187BF15E91044359026470
Risposta server: {“code”:1004,“msg”:“sign invalid”,“success”:false,“t”:1754754634144,“tid”:“95dd23bc753811f0884d66005ac75605”}
Traceback (most recent call last):
File “C:\Users\remod\Desktop\walbox\walbox_status.py”, line 77, in
token = get_token()
File “C:\Users\remod\Desktop\walbox\walbox_status.py”, line 50, in get_token
raise Exception(f"Errore token: {data}")
Exception: Errore token: {‘code’: 1004, ‘msg’: ‘sign invalid’, ‘success’: False, ‘t’: 1754754634144, ‘tid’: ‘95dd23bc753811f0884d66005ac75605’}

Ok, I know this is not a solution, but at least it tries to keep things accessible and running.

This automation will detect if an entity has the same value for 15+ minutes.

I am using an integral sensor from a W measurement of a plug that is always under load.

You need to replace the sentinel sensor and your tuya integration entry id.

Considering the /5 trigger and the 15 minutes eval, sometimes I am getting a restart every 20 minutes. Sometimes once an hour.

alias: "Automation Action: Auto-reload Tuya if it stops updating"
description: >-
  Automatically reloads the Tuya integration if the sentinel sensor has not
  updated for more than 15 minutes.
triggers:
  - minutes: /5
    trigger: time_pattern
conditions:
  - condition: template
    value_template: >
      {% set e = states.sensor.REPLACE_WITH_YOUR_SENTINEL_SENSOR %}
      {% if e is not none %}
        {{ (now() - e.last_updated).total_seconds() > 15 * 60 }}
      {% else %}
        false
      {% endif %}
actions:
  - action: homeassistant.reload_config_entry
    data:
      entry_id: REPLACE_WITH_YOUR_TUYA_INTEGRATION_ENTRYID
    enabled: true
  - data:
      message: Tuya integration auto-reload routine triggered!
    action: telegram_bot.send_message
    enabled: false
  - data:
      title: Tuya automatically reloaded
      message: >
        The Tuya integration was reloaded because {{
        states.sensor.REPLACE_WITH_YOUR_SENTINEL_SENSOR }} had not updated for
        more than 15 minutes ({{ now().strftime("%Y-%m-%d %H:%M") }}).
    action: persistent_notification.create
    enabled: false
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
mode: single

The situation is getting worse.

For testing purposes, I disabled the automation to see how much time it would take for the integral to stop updating.

When it stops, I tried to turn a plug on / off just to confirm that the integration is dead.

It is freezing every 5 ~ 8 minutes.

I will try to collect logging and issue a bug report.

Interesting development.

A couple of hours ago, I was setting up Home Assistant for debug logging.

First I enabled it and found lots of errors from other integrations and devices.

So I disabled logging, disabled any integration generating noise that would not be directly related to the tuya integration (making it easier to spot the problem).

After disabling them, enabled logging, reloaded the tuya integration and it is working for 3 hours now.

I will post other findings, but AFAICT tuya cloud connection timeouts might be influenced by other connection attempts made by HA.

update: tuya integration eventually freezes, but only twice since yesterday. Logged an issue on github.Tuya Integration Freezes Randomly · Issue #150438 · home-assistant/core · GitHub

This instability was the push I needed…

I went Full Local. Bought myself a Sonoff zigbee controller and in between TuyaLocal (not LocalTuya) and Zigbee2Mqtt I’ve migrated it all to local connections.

A bit of blood, sweat and tears involved (and sleep deprivation), but it worked out. well (actually, VERY well). It’s far more flexible now and responsive.

and all local.

That´s my goal. As soon as I move to my new house, all new devices will either be replaced by zigbee (plan to use a SLZB-MR1 as controller and 2 or 3 SLZB-06 as routers) or configured as local.

The problem is related to the battery based devices, I think that tuya local has a hard time with them. Also in my initial tests, couldn’t properly configure a circuit breaker (might turn on or off, but won´t read V/A/W correctly).

It is still too early to say whether this is a solution or not, especially because I believe this is a multi factor problem.

I use HA as a guest (VM) in VirtualBox on a Windows 11 host.

On the host, I have Tailscale installed.

I noticed that when Tailscale on the host is connected, Tuya integration failures are more frequent.

I cannot explain the reason, since the VM accesses the network through a bridged interface, and nothing above layer 1 should make a difference to the VM.

However, with Tailscale running on the host, failures occur repeatedly within minutes. With Tailscale disconnected on the host, I can go days without failures.

I will continue to share any new findings here.

Just a recommendation - Reboot your router/modem/AP’s. Maybe it’ll help. Maybe it won’t. Old packets/frames can linger in the cache of these devices that can sometimes cause unexplained network phenomena. You only ever realize things like this can occur when you discover things like APIPA. Craziness…

Other recommendation - invest the time and setup LocalTuya. That’s what I use. Totally worth it. GitHub - xZetsubou/hass-localtuya: 🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"

1 Like

The same thing. Some of the devices get stuck. Only reload helps.