Run rule only when motion is detected over a period

Hi There,

I'm new to home automation and trying to get the below working. I have explored the apps however from my understand i may need to use Rule Machine to get this done. In the toilet i have a motion sensor which turns on a switch which has an exhaust fan connected to it.

If the motion sensor detects activity over two minutes, turn on switch for 10 minutes
If the motion sensor detects activity however its less then two minutes, switch does not need to be on

Use Case: Individuals many enter the toilet to wash hands etc and there is no necessity to turn on the exhaust fan. Only during shower or other extended activities is the exhaust required.

you could use a private boolean and conditionals. if the private boolean is false, make it true. then make it false after 2 minutes.

I think that logic presumes that the motion sensor remains active throughout the entire time that someone is in the toilet; if the motion sensor is showing as inactive when the rule is evaluated after 2 minutes then it wont trigger. Please do correct me if I've misread it.

I do something slightly differently in my dining room, to have the lights turn on dim if the motion is temporary (i.e just passing through - our house is open plan) but to go to full brightness if the motion persists (i.e. someone is actually using the dining room). I use a global variable with a rule which increments the value of the variable by 1 each second whenever the motion is active. I then have a separate rule for the lights; if there's motion and the counter value is below 19 then the lights come on dim. If it's 19 or above, they light bright. The global variable is then reset to zero when there is no motion for 3 minutes.

A similar rule could work for you, with appropriate timers - although it's not the most elegant approach.

Thank you Furom and all who replied! Furom i replicated your script and it works as intended, thank you so much! I may like to add the below two functionalities if possible, please advise

  1. Right now once the switch turns on it switches off after 10 minutes regardless if an individual is still in the toilet. How do i modify the script such that after switching on, only switch off 10 minutes after no more motion activity.

  2. The motion sensor is a little finicky, too avoid the switch being on indefinitely can it be forced to switch off after 30 minutes regardless if motion is detected.

Thank you everyone who is reviewing this

1 Like