# Node to trigger if a state is certain amount of time

**URL:** <https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860>\
**Category:** General\
**Created:** [29 July 2024 20:12 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860 "2024-07-29T20:12:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [29 July 2024 20:12 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/1 "2024-07-29T20:12:07Z")

</div>

Hi, I have a ESP presence sensor I'm wanting to monitor the state. If the state is "Clearance" for at least 3 minutes I want it too send a payload to turn off the lights. Is there a node anyone knows of that can do that?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0be823840a11d1b5285786435e4a683e731f382b.png)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 July 2024 20:17 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/2 "2024-07-29T20:17:59Z")

</div>

Trigger Node.

You can also cancel it at will

 ![Screenshot 2024-07-29 at 21.17.40](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/806992059e9eab10de7c6d7bb0ea14642f105108.png)

---

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [29 July 2024 20:24 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/3 "2024-07-29T20:24:13Z")

</div>

@marcus-j-davies thank you for the suggestion, but I was trying to test this out and it might not work for my scenario. Sorry forgot to include this, but the state flips between "Movement" and "Occupancy" I need a way for it too check that state "Clearance" has been 3 minutes and not changed to "Movement" or "Occupancy".

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 July 2024 20:27 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/4 "2024-07-29T20:27:58Z")

</div>

Still, its all there.

You can cancel the trigger (`msg.reset = true`) the moment it moves away from `Clearance`

 ![Screenshot 2024-07-29 at 21.27.13](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/fa62136e70425423f79b2d04762dcb8d2cfbcec0.png)

```auto
[{"id":"95e74b90d287852b","type":"trigger","z":"82a9dc95c5200a1f","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"3","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":240,"wires":[[]]},{"id":"da419234bfad6199","type":"function","z":"82a9dc95c5200a1f","name":"My Sensor","func":"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":110,"y":280,"wires":[["6aa4fabf26512a04"]]},{"id":"6aa4fabf26512a04","type":"switch","z":"82a9dc95c5200a1f","name":"Clearance?","property":"payload.myState","propertyType":"msg","rules":[{"t":"eq","v":"Clearance","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":310,"y":280,"wires":[["2fd84c1bfd59066c"],["a82d85be702edaa6"]]},{"id":"a82d85be702edaa6","type":"change","z":"82a9dc95c5200a1f","name":"msg.reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":340,"wires":[["95e74b90d287852b"]]},{"id":"2fd84c1bfd59066c","type":"junction","z":"82a9dc95c5200a1f","x":440,"y":240,"wires":[["95e74b90d287852b"]]}]

```

---

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [29 July 2024 20:32 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/5 "2024-07-29T20:32:23Z")

</div>

@marcus-j-davies genius! I see what your doing now. Thank you very much!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 August 2024 20:32 UTC](https://discourse.nodered.org/t/node-to-trigger-if-a-state-is-certain-amount-of-time/89860/6 "2024-08-12T20:32:27Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
