make-all / tuya-local

Local support for Tuya devices in Home Assistant
MIT License
1.1k stars 446 forks source link

Devices going into "unavailable" state #653

Closed elninosi closed 1 year ago

elninosi commented 1 year ago

I noticed that my Tuya devices go into "unavailable" state. After reloading, integration is restored for some period.

Diagnostic for device that goes to unavailable state most often:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2023.4.6",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.10",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/Vienna",
    "os_name": "Linux",
    "os_version": "6.1.24",
    "supervisor": "2023.04.1",
    "host_os": "Home Assistant OS 10.0",
    "docker_version": "23.0.3",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "alarmo": {
      "version": "v1.9.9",
      "requirements": []
    },
    "hacs": {
      "version": "1.32.1",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    },
    "multiscrape": {
      "version": "6.5.0",
      "requirements": [
        "lxml==4.9.1",
        "beautifulsoup4==4.11.1"
      ]
    },
    "panasonic_cc": {
      "version": "1.0.32",
      "requirements": []
    },
    "powercalc": {
      "version": "v1.5.1",
      "requirements": [
        "numpy>=1.21.1"
      ]
    },
    "tuya_local": {
      "version": "2022.4.1",
      "requirements": [
        "pycryptodome~=3.17",
        "tinytuya==1.12.4"
      ]
    },
    "webrtc": {
      "version": "v3.1.0",
      "requirements": []
    },
    "roborock": {
      "version": "0.1.2",
      "requirements": [
        "python-roborock==0.1.7"
      ]
    },
    "browser_mod": {
      "version": "2.2.1",
      "requirements": []
    },
    "scheduler": {
      "version": "v0.0.0",
      "requirements": []
    },
    "watchman": {
      "version": "0.5.1",
      "requirements": [
        "prettytable==3.0.0"
      ]
    }
  },
  "integration_manifest": {
    "domain": "tuya_local",
    "name": "Tuya Local",
    "codeowners": [
      "@make-all"
    ],
    "config_flow": true,
    "dependencies": [],
    "documentation": "https://github.com/make-all/tuya-local",
    "integration_type": "device",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/make-all/tuya-local/issues",
    "requirements": [
      "pycryptodome~=3.17",
      "tinytuya==1.12.4"
    ],
    "version": "2022.4.1",
    "is_built_in": false
  },
  "data": {
    "name": "Beok TOL47 Main thermostat",
    "type": "beok_tol47_thermostat",
    "device_id": "**REDACTED**",
    "local_key": "**REDACTED**",
    "host": "**REDACTED**",
    "protocol_version": "auto",
    "api_version_set": 3.3,
    "api_version_used": 3.3,
    "api_working": true,
    "status": {},
    "cached_state": {
      "updated_at": 1682549760.0076742,
      "1": false,
      "2": 150,
      "3": 217,
      "4": "cold",
      "5": "0",
      "8": false,
      "13": true,
      "16": 0,
      "20": -18,
      "21": 30,
      "25": "1",
      "26": false,
      "31": false,
      "41": "1",
      "42": "1",
      "101": false,
      "105": 5,
      "107": 5
    },
    "pending_state": {},
    "connected": true,
    "force_dps": [],
    "home_assistant": {
      "name": "Beok TOL47 Main thermostat",
      "name_by_user": "Main Thermostat",
      "disabled": false,
      "disabled_by": null,
      "entities": [
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": null,
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "climate.main_thermostat",
            "state": "off",
            "attributes": {
              "hvac_modes": [
                "auto",
                "off",
                "heat"
              ],
              "min_temp": 5.0,
              "max_temp": 95.0,
              "target_temp_step": 0.5,
              "preset_modes": [
                "Program",
                "Temporary",
                "Manual"
              ],
              "current_temperature": 21.7,
              "temperature": 15.0,
              "hvac_action": "off",
              "preset_mode": "Manual",
              "fault_code": 0,
              "icon": "mdi:radiator-off",
              "friendly_name": "Main Thermostat",
              "supported_features": 17
            },
            "last_changed": "2023-04-26T09:56:54.371840+00:00",
            "last_updated": "2023-04-26T09:56:54.371840+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "switch",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "switch.main_thermostat_anti_frost",
            "state": "off",
            "attributes": {
              "device_class": "switch",
              "icon": "mdi:snowflake-melt",
              "friendly_name": "Main Thermostat Anti-frost"
            },
            "last_changed": "2023-04-26T09:56:54.370657+00:00",
            "last_updated": "2023-04-26T09:56:54.370657+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "select.main_thermostat_backlight_brightness",
            "state": "Low",
            "attributes": {
              "options": [
                "High",
                "Low",
                "None",
                "Middle"
              ],
              "icon": "mdi:lightbulb-on-40",
              "friendly_name": "Main Thermostat Backlight brightness"
            },
            "last_changed": "2023-04-26T09:56:54.372413+00:00",
            "last_updated": "2023-04-26T09:56:54.372413+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "\u00b0C",
          "state": {
            "entity_id": "number.main_thermostat_calibration_offset",
            "state": "-1.8",
            "attributes": {
              "min": -9.0,
              "max": 9.0,
              "step": 0.1,
              "mode": "auto",
              "unit_of_measurement": "\u00b0C",
              "icon": "mdi:arrow-collapse-up",
              "friendly_name": "Main Thermostat Calibration offset"
            },
            "last_changed": "2023-04-26T09:56:54.372816+00:00",
            "last_updated": "2023-04-26T09:56:54.372816+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "lock.main_thermostat_child_lock",
            "state": "unlocked",
            "attributes": {
              "icon": "mdi:hand-back-right",
              "friendly_name": "Main Thermostat Child lock",
              "supported_features": 0
            },
            "last_changed": "2023-04-26T09:56:54.371102+00:00",
            "last_updated": "2023-04-26T09:56:54.371102+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "temperature",
          "icon": null,
          "unit_of_measurement": "\u00b0C",
          "state": {
            "entity_id": "number.main_thermostat_external_sensor_temperature_limit",
            "state": "5",
            "attributes": {
              "min": 5,
              "max": 60,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "\u00b0C",
              "device_class": "temperature",
              "icon": "mdi:arrow-collapse-up",
              "friendly_name": "Main Thermostat External sensor temperature limit"
            },
            "last_changed": "2023-04-26T09:56:54.373413+00:00",
            "last_updated": "2023-04-26T09:56:54.373413+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "diagnostic",
          "device_class": null,
          "original_device_class": "problem",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "binary_sensor.main_thermostat_fault_alarm",
            "state": "off",
            "attributes": {
              "device_class": "problem",
              "friendly_name": "Main Thermostat Fault alarm"
            },
            "last_changed": "2023-04-26T09:56:54.370950+00:00",
            "last_updated": "2023-04-26T09:56:54.370950+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "temperature",
          "icon": null,
          "unit_of_measurement": "\u00b0C",
          "state": {
            "entity_id": "number.main_thermostat_high_temperature_limit",
            "state": "30",
            "attributes": {
              "min": 15,
              "max": 95,
              "step": 1.0,
              "mode": "auto",
              "unit_of_measurement": "\u00b0C",
              "device_class": "temperature",
              "icon": "mdi:thermometer-chevron-up",
              "friendly_name": "Main Thermostat High temperature limit"
            },
            "last_changed": "2023-04-26T09:56:54.373007+00:00",
            "last_updated": "2023-04-26T09:56:54.373007+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "switch",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "switch.main_thermostat_output_main_reverse",
            "state": "off",
            "attributes": {
              "device_class": "switch",
              "icon": "mdi:swap-horizontal",
              "friendly_name": "Main Thermostat Output main reverse"
            },
            "last_changed": "2023-04-26T09:56:54.370792+00:00",
            "last_updated": "2023-04-26T09:56:54.370792+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "select.main_thermostat_schedule",
            "state": "Weekday+Weekend",
            "attributes": {
              "options": [
                "Weekday+Weekend",
                "Mon-Sat+Sun",
                "Daily"
              ],
              "icon": "mdi:calendar-clock",
              "friendly_name": "Main Thermostat Schedule"
            },
            "last_changed": "2023-04-26T09:56:54.372593+00:00",
            "last_updated": "2023-04-26T09:56:54.372593+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "select.main_thermostat_sensor_selection",
            "state": "Internal",
            "attributes": {
              "options": [
                "Both",
                "External",
                "Internal"
              ],
              "icon": "mdi:home-thermometer",
              "friendly_name": "Main Thermostat Sensor selection"
            },
            "last_changed": "2023-04-26T09:56:54.372069+00:00",
            "last_updated": "2023-04-26T09:56:54.372069+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": "switch",
          "icon": null,
          "unit_of_measurement": null,
          "state": {
            "entity_id": "switch.main_thermostat_sound",
            "state": "on",
            "attributes": {
              "device_class": "switch",
              "icon": "mdi:music-note",
              "friendly_name": "Main Thermostat Sound"
            },
            "last_changed": "2023-04-26T09:56:54.370347+00:00",
            "last_updated": "2023-04-26T09:56:54.370347+00:00"
          }
        },
        {
          "disabled": false,
          "disabled_by": null,
          "entity_category": "config",
          "device_class": null,
          "original_device_class": null,
          "icon": null,
          "unit_of_measurement": "\u00b0C",
          "state": {
            "entity_id": "number.main_thermostat_temperature_control_switch_difference",
            "state": "0.5",
            "attributes": {
              "min": 0.5,
              "max": 9.5,
              "step": 0.1,
              "mode": "auto",
              "unit_of_measurement": "\u00b0C",
              "icon": "mdi:thermometer-plus",
              "friendly_name": "Main Thermostat Temperature control switch difference"
            },
            "last_changed": "2023-04-26T09:56:54.373224+00:00",
            "last_updated": "2023-04-26T09:56:54.373224+00:00"
          }
        }
      ]
    }
  }
}
fldc commented 1 year ago

Same here, started some time ago.

Nikolay-Ch commented 1 year ago

I have six smart plugs and two thermostats, all of them have now state "unavailable". State returns to normal to short time, if I changing state of plug by using SmartLife application. But after short time state goes to unavailable too

Cloud tuya integration works normally...

Drummingman commented 1 year ago

I also have the same issue

tm1981 commented 1 year ago

i also have the same issue, the device randomly changes status to unknown and then to unavailable, restarting temporally fix the issue

make-all commented 1 year ago

I think there may be a limit in the number of threads Home Assistant is letting an integration start. Because the underlying tinytuya library is not async, this integration starts a thread per device to receive updates asynchronously from the device.

bezigebever commented 1 year ago

@make-all I only have 1 device, the pool heatpump. Can we activate any additional logging ?

Nikolay-Ch commented 1 year ago

Is any suggestions about this bug? I have stopped all automations... :(

adamkoch commented 1 year ago

I see this as well, it only started happening recently (last few days), likely related to upgrading tuya-local to latest.

I only have a single pool heater connected and HA shows it as offline - using the Tuya app (Cloud) to change the pool heater state makes the entity in HA come online again but then shortly after it will go offline again.

chrisghu commented 1 year ago

I have the same issue with just one pool heat pump. @adamkoch which version you have used before (which was stable for you)? I have switched from local tuya to tuya local due to the device is supported out of the box but if it is not working reliable it will not be that useful. Is there any idea what we can try to log? I'm experiencing this behavior just after a while. The wifi connection to the pump is not the best so my guess is, that it has something to do with a reconnect of the pump. Perhaps the loss of connection is bringing the integration somehow to the limit?

make-all commented 1 year ago

If your protocol version is set to auto, you will get faster recovery times after a network disconnection if you set the protocol version to the version actually used by your device. If you don't know what that is, download Diagnostics for the device when it is working, and the version detected will be in the diagnostics file.

adamkoch commented 1 year ago

I have the same issue with just one pool heat pump. @adamkoch which version you have used before (which was stable for you)?

It may have been a red herring. I had never seen the device go "unavailable" for 1+ years and then I upgraded to the latest version and it went unavailable constantly all day. However, for whatever reason, it seems to be stable again today and no longer going offline. I will report back in case I see more issues going forward.

peregrines2 commented 1 year ago

Same problem here. Tonight all my 16 devices went unavailable :( Only restarting HA did bring them back to live :(

bezigebever commented 1 year ago

If your protocol version is set to auto, you will get faster recovery times after a network disconnection if you set the protocol version to the version actually used by your device. If you don't know what that is, download Diagnostics for the device when it is working, and the version detected will be in the diagnostics file.

I've tried to set protocol to version 3.3 and this is much more stable. I still sometimes get an unavailable state, but it comes back very quick...

ceinmart commented 1 year ago

I'm new to HA and started to use tuya-local a few weeks ago and already "became" with this behave, which is very annoying, my automation fails constantly. However, my devices are set with protocol = auto. Changing to the correct protocol and crossing my fingers to reduce this behavior.

To identify the correctly version, I'm using tinytuya , which works very well.

Krispkiwi commented 1 year ago

I noticed this as well, restarting home assistant seems to fix it until it happens again after a period of time.

ceinmart commented 1 year ago

@make-all , just a note.

I'm trying since yesterday to change thru the interface the protocol version of my devices. They are working and available, however, when I go to the configuration and change the protocol from "auto" to the correct version they give an error that aren't able to connect, the problem should be interment... I restarted my HA, my S.O. and the problem persists... To force the protocol I was forced to shutdown my HA and change manually the core.config_entries file.

georgef333 commented 1 year ago

Same issue here, Slowly, all my devices becomes "unavailable", I might corelate this behavior with the upgrade of HA to 2023.5

chrisghu commented 1 year ago

@georgef333 I have the issue for home assistant 2023.4.6 as well. Before 2023.4 I have not used the integration so I cannot say to much.

fldc commented 1 year ago

The workaround is as @make-all suggested, figure out the protocol and configure it directly, haven't had a device going unavailable in over a week.

Krispkiwi commented 1 year ago

The workaround is as @make-all suggested, figure out the protocol and configure it directly, haven't had a device going unavailable in over a week.

Can confirm my devices aren't going offline with this

georgef333 commented 1 year ago

Confirm working after updating tinytuya to 1.12.7, Thanks!

antoweb commented 1 year ago

Confirm working after updating tinytuya to 1.12.7, Thanks!

Hallo how to uodate tintuya? Whats tintuya?

make-all commented 1 year ago

If you use HACS, tinytuya is automatically updated to match the version specified in the manifest when you upgrade to the latest version of this integration.

If you install manually, you should understand how to also install the dependency libraries.

ceinmart commented 1 year ago

Hi, I'm using the last version of Tuya Local, the last HA, devices set with the IP and Protocol on their settings, and still with considerable frequency devices getting unavailable at the point to fail few automation. Happens again last night when a smart socket became unavailable, however, I was able to turn it on thru SmartLive without issue at the same moment.

@make-all, please, can you give some tip on how to enable logs or how I could debug this situation to try to identify where is the problem?

Just to illustrate, this occur at this dawn when the heater should turn on and didn't. Then I turned it on manually thru Smart Life app because appear as unavailable at HA.

image

image

make-all commented 1 year ago

The logger documentation is here: https://www.home-assistant.io/integrations/logger/ Tuya local is under custom_components.tuya_local, for communication issues, probably just enabling debug on custom_components.tuya_local.device is enough. The low level communication is handled by tinytuya, and you should be able to enable debug logging for that also if you cannot spot anything at the tuya-local level.

Vesa62 commented 7 months ago

This issue is closed, but the problem still exists. Why is this closed? I do not find duplicate etc.

Please open and fix.