tinytuya icon indicating copy to clipboard operation
tinytuya copied to clipboard

How to do something when the door opens?

Open anar4732 opened this issue 2 years ago • 8 comments

I want to do something instantly when the door opens. so the idea of checking the status every minute not works. Since the device disconnects from the network on sleep mode I think should do something with the cloud.

anar4732 avatar Jan 18 '23 18:01 anar4732

I do not know of any good way of doing this, either via the cloud or locally. You might be able to either have your router trigger something on a DHCP request or have a python script listening for said DHCP broadcasts, however that will miss events if the door opens and then closes too fast.

If you don't care about using Tuya's app then loading a non-cloud firmware onto the device would be a better option.

Do you have a link for the door sensors you have?

uzlonewolf avatar Jan 18 '23 19:01 uzlonewolf

@uzlonewolf here

anar4732 avatar Jan 18 '23 19:01 anar4732

Some time ago I implemented a solution for fire sensors which work the same way - they only go online on alarm. I tried every 15s an async connect request with a timeout of 15s. I couldn't test it myself but users reported that it worked.

fhempy avatar Jan 18 '23 21:01 fhempy

Nice idea! Thank you!

anar4732 avatar Jan 18 '23 21:01 anar4732

https://github.com/fhempy/fhempy/blob/v0.1.491/FHEM/bindings/python/fhempy/lib/tuya/tuya.py#L400

Here is the code, I used pytuya in that case.

fhempy avatar Jan 18 '23 21:01 fhempy

Well here's an idea I just had. What if you took an extra smart plug, configured scene linkage/automation to turn it on when the door opens and turn it off when the door closes, and had tinytuya monitor the socket status? Would that work? I guess I'll find out tomorrow when my door sensors get here.

uzlonewolf avatar Jan 18 '23 22:01 uzlonewolf

And I totally forgot to post an update with my results. It... kinda/sorta works. The biggest issue is the door sensor does not always report immediately, more than 1 open/close action causes it to queue up the events and report them all at once after about a minute. Also, if the door is open for less than 1 second the smart plug reports 2 off events instead of the expected on+off. Beyond that it actually works pretty well.

uzlonewolf avatar Feb 01 '23 01:02 uzlonewolf

In case anyone is interested, I have been able to use the (UDP) 6667 port broadcast capture approach (check main.py)

rlm96 avatar Feb 25 '23 23:02 rlm96