Template Sensor On No Motion

Is is possible to create a template sensor based on another sensors state, that turns on when that entity been inactive for x minutes?

I’m basically trying to get a sensor that turns on when there’s been no motion detected for x minutes and cant for the life figure it out from all my copy pasta code.

There are perfect examples in the HA docs/templates

My feeble mind… goes straight to thinking how this would be trivial to do in node red.

How would you do this in node red? I’ve recently switched and have one automation I can’t get right. This template sensor was going to be a band aid to use in a flow.

I’m trying to turn everything off at night after no motion is detected for 40 minutes. I’ve used the method of checking the state for motion, delaying it and then checking again. The problem is my motion sensors reset after 10 seconds, making the delay useless.

Is there a way to query if a sensor has been off for X minutes, not just the basic flow I have of check, delay 40 minutes and then check again?

I’d do it with a PIR event node, which fires to the second output when the PIR turns off. That feeds into a delay timer, that delays the message until 40min without input. The delay then feeds into the service call to turn off the devices in question (I included 2 examples in this case, 1 turns off the all_lights group, another turns off a plug if it is on). This automation would run any time of day. Inserting a time range node before the delay node, you can make sure it only functions when it is bed time.

Thank you! Does this mean if the sensor updates a second time the timer starts over again and waits another 40 minutes?

Say the PIR just turned off, the timer is now going. If the PIR turns on, nothing happens yet, but when it returns to off, the timer is reset to 0. I suppose this could lead to bad behavior if say, the PIR turns on for 40min straight (stuff turns off when motion is on over 40min).

Here’s another flow that won’t do that:

In this flow, we also use the PIR on state to continuously reset the timer until the PIR actually goes off. That way even if the PIR is on for 45min, the timer won’t elapse. I added in that time range node I mentioned earlier; it makes sure it’s ‘bed time’ for the automation to work.

I’ve set my motion sensors to reset after ten seconds so this shouldn’t be a problem, thanks for your help.

Welcome, and good luck!