Variable motion trigger reset

I'm playing with a simple routine that varies the length of a motion timeout based on activity. I thought I would share it here in case anybody is interested. It has been a fun experiment.

Currently I have a number of rules that will turn on a light with motion and turn it off a set time after motion stops. The idea is to have a long enough delay so that the light doesn't go out if you are in the area but not so long that it is on for an extended time after you leave.

For example, the kitchen will currently turn off 20 minutes after motion stops. This gives plenty of time to retrigger the timer if you are working in the kitchen. It also leaves the light on for 20 minutes if you just walk through the kitchen which is a bit excessive.

So I came up with this simple rule.

You can see that I also use variables for the color temp and level but those aren't important for this exercise.

When the rule runs:

  1. Counter is incremented by 1. The counter is limited to 5 so that the value doesn't runaway.
  2. Rule waits for the motion sensor to go inactive.
  3. Delay variable is set to the value of the counter multiplied by the interval (5 and 4 minutes in this example).
  4. Rule waits for this length of time (20 minutes in example).
  5. Lights are turned off and the counter is reset to 0.

So the first time the rule is run the counter is set to 1 and the rule sets up a 4 minute wait. If the motion sensor is triggered again in this time frame the wait is reset when the rule runs again. This time the counter is 2 and the wait is 8 minutes. With these settings the wait maxes out at 20 minutes.

So if you just walk through the kitchen or get something out of the fridge the light will stay on for the minimum of 4 minutes. If you are working in the kitchen it is more likely you will trigger the rule multiple times increment the counter. If you stand in front of the stove for a while stirring for several minutes you might not trip a sensor but the delay would in theory be set higher so the lights won't cut out on you.

It isn't true presence detection but it does track what's going on to some extent. I use the Iris v2 motion sensors that have a 30 second reset so it is pretty good at incrementing the counter if you are actively working in a room. For my bedtime routine the delay is set to 0 so the lights turn off immediately after the sensor resets.

I know there are some apps that do similar things. I wanted to explore my own version because this will grow into more customized routines that are unique to my environment.

1 Like

Download the Hubitat app