rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.87k stars 554 forks source link

PIR/Motion Detector cant be added #1058

Open Dtrotmw opened 2 years ago

Dtrotmw commented 2 years ago

Please forgive a new Home Assistant user for any errors in formatting or addressing this! I'm trying to add a Tuya supported PIR (branded Hey!, wi-fi connected). It's set-up correctly in the Tuya iot web page from where I got its local key & id. I got the local IP address from my router in the brief period it connects after detecting motion. I then fill all this in under Add New Device in LocalTuya and hit submit either when the PIR is flashing or shortly after (I've tried this countless times at different moments after motion detection, during times the router can see the PIR). Every time I get "unknown error" and the log says: 2022-10-02 13:44:39.562 ERROR (MainThread) [custom_components.localtuya.config_flow] Unexpected exception Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 580, in async_step_configure_device self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 245, in validate_input interface = await pytuya.connect( File "/config/customcomponents/localtuya/pytuya/init.py", line 704, in connect , protocol = await loop.create_connection( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1025, in create_connection infos = await self._ensure_resolved( File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1404, in _ensure_resolved return await loop.getaddrinfo(host, port, family=family, type=type, File "/usr/local/lib/python3.10/asyncio/base_events.py", line 860, in getaddrinfo return await self.run_in_executor( File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name does not resolve

FYI I have another localtuya device added the same way that is working just fine. Thanks for any help provided!

Environment

Configuration configuration.yaml or config_flow

Loads default set of integrations. Do not remove.

default_config:

Text to speech

tts:

automation: !include automations.yaml script: !include scripts.yaml scene: !include scenes.yaml

DP dump

Provide Home Assistant taceback/logs

Additional information

ingoratsdorf commented 2 years ago

Looks like you have a PIR that goes online only after detecting motion, then goes offline again. And once it's offline, well, nothing will be able to connect to it, hence the above error, trying to connect to the IP you've given it. Have no clue really but maybe this new zombie state DP setting and a polling frequency might help. You may need wireshark or another IP packet sniffer to find out that the SmartLife app send to the PIR to check it's state.

remlei commented 1 year ago

if that motion sensor is battery powered, well, you only have 10 second to add it to localtuya and even if you manged to add it, its not going to work, you will be using the official tuya integration for these stuff and unfortunately that's how it works.... unless that PIR sensor is USB powered (which majority of these tuya wifi based sensors have), then the device is always available over the network and you can add the sensors without issue, not to mention that reaction time of the sensor is very fast 1-2 seconds after it detects a motion vs around 10-20seconds in battery power.