jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
951 stars 172 forks source link

Local battery motion sensor PIR question #426

Closed illUkc closed 9 months ago

illUkc commented 10 months ago

How to obtain the local status of a Tuya motion WiFi PIR sensor when it is triggered? I've tried everything, but I always receive the following:

Received Payload: {'Error': 'Network Error: Device Unreachable', 'Err': '905', 'Payload': None}

I am using OutletDevice device?

Any idea with some code example?

Thanks

uzlonewolf commented 10 months ago

Short version: you can't.

Long version: Battery-powered devices do not remain connected to WiFi. When they have something to report they connect, transmit the data, and then immediately disconnect. This is because WiFi uses a lot of power and battery life would be measured in hours if they remained connected. There are a few tricks you could do, such as watching for broadcast packets from the device or chain an unused smart plug to it as a follower and watch that instead, but in my experience it's just not reliable. Most devices also only transmit the very first activation and will queue up further activations for 10-30 minutes before reporting them all at once. Pulling device logs from the cloud will get you a list of past activations, but it's not real-time. If you need reliable real-time reporting then you need either a wired sensor or a Zigbee sensor connected to an always-on gateway.

uzlonewolf commented 9 months ago

Since we haven't heard anything in 3 weeks I'm going to go ahead and close this. Feel free to re-open it if you still need help.