# ON and OFF delay timer

**URL:** <https://discourse.nodered.org/t/on-and-off-delay-timer/4405>\
**Category:** General\
**Created:** [30 October 2018 03:20 UTC](https://discourse.nodered.org/t/on-and-off-delay-timer/4405 "2018-10-30T03:20:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpyandy](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@cpyandy](https://discourse.nodered.org/u/cpyandy)\
**Post date:** [30 October 2018 03:20 UTC](https://discourse.nodered.org/t/on-and-off-delay-timer/4405/1 "2018-10-30T03:20:36Z")

</div>

Hey folks, I am building an alarm system logic with dashboard ui, I am looking for ON delay function which I can delay the alarm set for 1 minutes and no delay when alarm system been switched off manually on dashboard.

Anyone got any clue on where to find such node or function?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2018 07:10 UTC](https://discourse.nodered.org/t/on-and-off-delay-timer/4405/2 "2018-10-30T07:10:43Z")

</div>

You could use a Switch node to send On and Off down separate paths then put a delay node in the On path. Then join the paths together again if appropriate.  
You might need to think about the requirement a bit more though. Watch out for things like switching it on then immediately off again and make sure your logic copes with that. So I suggest first making sure you know exactly what you want the system to do. Then work out how to implement it.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [30 October 2018 21:12 UTC](https://discourse.nodered.org/t/on-and-off-delay-timer/4405/3 "2018-10-30T21:12:00Z")

</div>

This would be a good instance in which to use a DSM (State Machine) - but if that is not the way you want to go - then just use a global context variable to hold the state

AlarmState = on/off

When you arm the panel - set the variable to On, when you disarm set the variable to off check in your flow for this with a switch node - if Variable is On - then delay 1 minute and proceed, if Off then go to the next node immediately

Craig

---

<div class="post-metadata">

**Author:** ![cpyandy](https://avatars.discourse-cdn.com/v4/letter/c/c6cbf5/32.png) [@cpyandy](https://discourse.nodered.org/u/cpyandy)\
**Post date:** [1 November 2018 13:07 UTC](https://discourse.nodered.org/t/on-and-off-delay-timer/4405/4 "2018-11-01T13:07:10Z")

</div>

Thanks for your hint Colin, takes me a while to resolve the issue.  
Instead of using a DELAY node after the SWITCH node, I end up using a TRIGGER node (send 0, wait for x amount of time, then send 1, reset the trigger if msg.payload=0). This solves the issue that occurs when 0 is send immediately after 1.
