xZetsubou / hass-localtuya

🔹 A Home Assistant integration to handle Tuya devices locally "fork from localtuya"
https://xzetsubou.github.io/hass-localtuya/
GNU General Public License v3.0
423 stars 54 forks source link

Wifi Devices becomes unavailable after adding them into localtuya. It works but gets disconnected once HA is restarted #72

Closed JQLove2023 closed 11 months ago

JQLove2023 commented 11 months ago

Hi, sorry to disturb again. I have 3 wifi curtain roller that I have added into tuya smart app. All are working within tuya app.

I can add them into localtuya but the entities will become unavailable and I have no idea how to solve this.

home-assistant_2023-11-25T06-15-57.770Z.log Not sure if this can help but pls help me to look through or let me know what you need to see to diagnose further. Thank you! :)

xZetsubou commented 11 months ago

They becomes unavailable after restart? that's weird, these logs doesn't help because you haven't enabled localtuya debug :)

Add this into you configuretion.yaml then restart homeassistant

logger:
  default: warning
  logs:
    custom_components.localtuya: debug
    custom_components.localtuya.pytuya: debug

OR Enable from UI then reload localtuya

JQLove2023 commented 11 months ago

sorry, for some reason, localtuya can't find my wifi devices as i have tried removing and re adding :( Is there any way to help on this?

codyc1515 commented 11 months ago

Facing this same issue. Will see if I can get some more details.

xZetsubou commented 11 months ago

You mean like it's doesn't shows in discovered devices list? if yes try adding it manually. You can get device data from IOT or can download entry diagnostics and search for your curtain name and copy device id. When choosing add new device choose add device manually fill device id and insert anything in host, localkey and name it will give you an error but will fill correct wrong fields for you. then try again

for logs: https://github.com/xZetsubou/hass-localtuya/issues/72#issuecomment-1826239058 enable debug from configuration yaml and restart HA wait a minute then go to settings -> system -> logs search for localtuya open full logs copy everything.

I haven't bumped into this issue so without logs no way for me to know what causing it. note ensure devices aren't added in different local integration, <- this one of many reasons why it doesn't discovered.

JQLove2023 commented 11 months ago

home-assistant_2023-11-25T17-14-32.230Z.log Hope this helps! :)

JQLove2023 commented 11 months ago

home-assistant_2023-11-25T17-31-20.262Z.log

JQLove2023 commented 11 months ago

home-assistant_2023-11-25T17-44-05.684Z.log

xZetsubou commented 11 months ago

There is a some issues.

  1. The device protocol version shouldn't stored as auto protocol this is probably bug
  2. Are you using manual dps in order to setup curtain entities? this won't works due to localtuya entity availability logic

And if you are using manual dps, Delete the device an re-add it manually with auto but don't use manual dps. If auto didn't works try protocol 3.1. If it didn't works sharing diagnostics may help as well :)

JQLove2023 commented 11 months ago

When I didn't use manual dps, it will have error saying that it has successful connection but there is no data point.

I try protocol 3.1 first and see if it works :)

JQLove2023 commented 11 months ago
image

Sorry, but it still didn't work

JQLove2023 commented 11 months ago

[Uploading config_entry-localtuya-a95ff077dd4fa67e28453abe49ccdddb.json.txt…]() This is the diagnostic file that you have requested. :)

xZetsubou commented 11 months ago

Uploading config_entry-localtuya-a95ff077dd4fa67e28453abe49ccdddb.json.txt… This is the diagnostic file that you have requested. :)

The link is broke you probably clicked comment before upload complete :)

JQLove2023 commented 11 months ago

config_entry-localtuya-a95ff077dd4fa67e28453abe49ccdddb.json.txt Thanks!

xZetsubou commented 11 months ago

Did you try connect to the device all protocols one by one instead of auto ?

JQLove2023 commented 11 months ago

i didn't use auto protocol. I tried 3.1 and auto only. let me try the rest

xZetsubou commented 11 months ago

When you connect to the curtain enable device debug image After it fails check the logs it should reports the connect process for you you can use auto for this test.

JQLove2023 commented 11 months ago

This error originated from a custom integration.

Logger: custom_components.localtuya.core.pytuya Source: custom_components/localtuya/core/pytuya/init.py:1092 Integration: LocalTuya (documentation, issues) First occurred: 1:29:52 AM (23 occurrences) Last logged: 2:45:22 PM

[116...3f2] Failed to get status: [116...c79] Failed to get status: Traceback (most recent call last): File "/usr/local/lib/python3.11/asyncio/tasks.py", line 500, in wait_for return fut.result() ^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/locks.py", line 387, in acquire await fut asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/config/custom_components/localtuya/core/pytuya/init.py", line 1092, in detect_available_dps data = await self.status(cid=cid) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/localtuya/core/pytuya/init.py", line 1011, in status status: dict = await self.exchange(command=DP_QUERY, nodeID=cid) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/localtuya/core/pytuya/init.py", line 985, in exchange msg = await self.dispatcher.wait_for(seqno, payload.cmd) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/localtuya/core/pytuya/init.py", line 606, in wait_for await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout) File "/usr/local/lib/python3.11/asyncio/tasks.py", line 502, in wait_for raise exceptions.TimeoutError() from exc TimeoutError

JQLove2023 commented 11 months ago

home-assistant_2023-11-26T07-58-46.783Z.log Hope this will help more ;)

JQLove2023 commented 11 months ago

home-assistant_2023-11-26T08-19-50.095Z.log Sorry, i tried another time round. hopefully can give you more info :)

xZetsubou commented 11 months ago

From logs to be honest i'm not 100% sure this is related to localtuya, the device it self doesn't response or return the status. there's a many reason can cause this issue so I don't know to be honest and most of this reason in devices it self. I want to say re-add device to smart life might help but I don't know for sure 👀

However if you want to make sure if this issue only happen to localtuya or not try add the same device using different local tools if the device works on of different local tool then it's most likely localtuya issue.

JQLove2023 commented 11 months ago

Can I check which other local tools i can try with?

xZetsubou commented 11 months ago

Edit: you can try any other local integration like tuya local

However you can use tuyadebug to test tinytuya now. from terminal copy and paste

wget https://github.com/xZetsubou/hass-localtuya/raw/master/tuyadebug.tgz
tar -zxvf tuyadebug.tgz && cd tuyadebug

Then override device data with yours before start the test.

python test_tinytuya.py "device_id" "host" "localkey" "protocol_version" 

Example: tinytuya test

python test_tinytuya.py "bfb7475dbdef49284eu4xe" "192.168.1.204" "K]~fFzELZHDQP<H!" "3.5" 

localtuya test

python test.py "bfb7475dbdef49284eu4xe" "192.168.1.204" "K]~fFzELZHDQP<H!" "3.5" 

It should print the device status. you can try all protocols if you want

feene commented 11 months ago

I am having the same issue with a costco light strip. LocalTuya works great when internet and dns is allowed to Tuya's Cloud. Shortly after I block DNS and Internet Access the device goes unresponsive.

Internet Active

READING TEST: Status Response {'dps': {'20': True, '21': 'colour', '24': '0009029f03e8', '26': 0, '46': 1200, '47': 48, '53': 48}}

Internet and DNS Blocked

No response from plug XXXXXXXX[172.16.xxx.xxx] after 2 attempts

This device is on my IOT VLAN. HA is on a different VLAN. Command run from HA VLAN.

xZetsubou commented 11 months ago

I am having the same issue with a costco light strip

This is a different issue it has nothing to do with this one. Tho I don't know what happened in your specific situation but did also block DNS requests to DNS Server? reading the note mentioned in upstream may help.

NOTE 2: If you plan to integrate these devices on a network that has internet and blocking their internet access, you must also block DNS requests (to the local DNS server, e.g. 192.168.1.1). If you only block outbound internet, then the device will sit in a zombie state; it will refuse / not respond to any connections with the localkey. Therefore, you must first connect the devices with an active internet connection, grab each device localkey, and implement the block

Note the test above is tinytuya if you want to test localtuya replace python test_tinytuya.py to python test.py same args

feene commented 11 months ago

Will try that. Yes DNS and Network was blocked at my Firewall. DNS Servers are in another subnet/vlan. Local router to IOT subnet does not resolve DNS.

JQLove2023 commented 11 months ago

Sorry to disturb. I tried re adding the blind into tuya app then it can be added to localtuya. However, once HA restart, the blinds got disconnected. Is there possibility that you can have a solution for this? 😅

xZetsubou commented 11 months ago

You mean the device connection successes to localtuya and reported DPS without an issues then once HA restarts, the device is no longer responses? Then there should be an error or warning messages in the logs if not then open full logs and make sure there is a message similar to this Success: connected to 192.168.2.234. otherwise this doesn't make sense :),

The reason I asked you to to make test above https://github.com/xZetsubou/hass-localtuya/issues/72#issuecomment-1826753526 is to make sure before anything if this is related to localtuya integration or not ^^ connection issues are mostly related to the devices and network. You mentioned above that your device not getting discovered in add new device step I would understand if your device isn't related to tuya smart app or smart life app, but your device is probably based on Tuya app this is what confusing me what it didn't get discovered. This probably means your device itself doesn't broadcast to the network, perhaps?, still this is my guesses I may be completely wrong :)