Tracking motion active time?


#1

I have a motion sensor with a 15 second re-trigger time.

I’m trying to write a piston that does:

  • if time in triggered state > 45 seconds over last 60 seconds then turn off outlet
  • if time in triggered state == 0 over last 120 seconds then turn on outlet.

The second case is easy. Is there an easy way to handle that first case in WebCore?


#2

You could do it with 4 variables, just call them split1, 2, 3, and 4 or something. Each time your piston runs, you set a variable. If motion is present in the first run, set split1 to 1. If no motion n is detected in the second run set split2 to 0. After you set variable 4, you loop back to 1.

Then simply adding the 4 variables gives you a “rolling window” of the past 60 seconds. If the sum of the variables is greater than 2, turn off the outlet… Else turn the outlet on.


#3

That could work, I’ll have to see if the motion sensor re-trigger actually triggers a new event every 15s that the sensor is on.


#4

You should be able to write a condition that says “if motion was active in the last 15 seconds”.


#5

You’re the OPer. So, how do you not know? You’re the one that asked the question. When a motion sensor says it has a 15 second timeout, that means it will hold the trigger for 15 seconds after motion is detected. So, if you are still moving, the timeout hasn’t started yet.


#6

If sensor motion stays active in the last 45 seconds, then with outlet, turn off.

If sensor stay motion stays inactive in the last 120 seconds AND plug switch is off, then with plug, turn on.

Just curious, what are you using this for?


#7

Wow, a little harsh there Ryan? I think the sensor I’m using re-sends the motion event every 15s while active, I haven’t had a chance to sit down and test/verify that yet.

I don’t want to trigger “active for last 45s” I . want “active for 45s out of the last 60s” which could look like 15s on, 15s off, 30s on.

I have a dehumidifier in a room that I want to turn off when the room is occupied. My experience so far is the motion sensor is a little noisy (triggering false events every once in a while, having pauses of no motion with a person in the room, etc) so I was looking to see if there are existing patterns for smoothing event/sensor data in WebCore before I go build my own.

I probably won’t get back to hacking at it until next week, life is busy :slight_smile:


#8

I’m always pushing for something simpler, so I would probably turn it off on any motion and turn it back on with 2 minutes of no activity.

Can you change the cooldown time in the sensor settings? I can change it for individual sensors for my Aqara sensors. I had to change one that we’re using to notify us of cats on the toilet (we’re toilet training them) but I didn’t want a notification every minute. I changed it to a 10-minute cooldown.


#9

I’ll increase the sensor reset time and see how it behaves with pauses in motion. I’m not clear if the “no motion” event is “since first motion” or “since last motion”. If it is “since last motion” increasing the timeout would be perfect, thanks for the idea.

Part of the reason I want the smoothing is I don’t want to hard-cycle the compressor too much. In normal operation the unit turns off the compressor but keeps the fan running for ~1 minute to normalize the coil temps. When I turn it off via the outlet the whole thing just powers off which is not ideal.


#10

No motion in the last xx minutes/seconds is since the LAST motion. Every time there is new motion, the timer is reset.


#11

That worked, I updated the re-trigger time to 45s and now the motion sensor doesn’t send an “inactive” trigger until 45s after the last motion. This is enough smoothing for me assuming false-triggers are not an issue.