Trouble with Stoptimer flow - not sure I have it set up correctly in Node-Red

I have a Wyze PIR that controls the light in my bathroom. This flow was a bit complicated bc I needed to prevent the light from going off when someone is in the shower.

When the PIR goes ON/detected, it stays in that state for about 45 seconds, then flips back to OFF/clear. The ON side of this flow is working pretty well - it’s the OFF side where I’m failing.

When the OFF state fires, it passes to a 3 minute Stoptimer before passing through to the turn_off node. However…if the PIR gets tripped (within that 3 minute timer) it doesn’t come through and reset the timer - so no matter what, the light turns off at the end of the timer.

It’ll turn right back on if you’re in there and the PIR trips again, but having the light go off…then back on is not pleasing to my wife :slight_smile:

I’ve only been messing with Node-REd for about 10 days, so I’ve kind of exhausted my knowledge. How can this be modified to avoid this OFF/ON cycle?

Here is an export of this flow: https://pastebin.com/sH9ZaPtM

Edit: Version #2 here - maybe better? https://pastebin.com/cjEjWc5L

Having looked at #2, when your PIR turns on the switch node, sends “on” as a payload to all subsequent flows. However, the stoptimer node needs a “STOP” in order to stop (!). So, between the switch node and the stoptimer node you can insert a “change” node where you put STOP in the msg.payload. It should do the trick.
GV

Awesome, thanks - does this look right? Do I need to do anything with the
“Additional Payload” output? https://pastebin.com/6vgYWBYK

So…is this right?

  1. When the PIR sends OFF, it should go to the 3 min timer.
  2. If that timer expires before the PIR is tripped again, the light should go off.
  3. If the PIR gets tripped ON again, the change node will kill the timer.
  4. When the PIR sends OFF again (45 secs later) it should start the timer again.

I think it is correct. Yes.
Just try;
Worse case scenario your light will goes on and off and your wife will ask what you are doing. Like mine does :slight_smile:
GV