# Timer to turn switch On/Off

**URL:** <https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849>\
**Category:** General\
**Created:** [27 October 2021 19:44 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849 "2021-10-27T19:44:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpatel2016](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpatel2016/32/33730_2.png) [@dpatel2016](https://discourse.nodered.org/u/dpatel2016)\
**Post date:** [27 October 2021 19:44 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/1 "2021-10-27T19:44:47Z")

</div>

I want to turn on the switch for an hour and then keep it off for an hour. Then this repeats as long as I want it.  
Basically, on for a set time and then off for a set time, then on for a set time, and off for a set time. It's like a loop.  
What type of timer or flow would do this?

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [27 October 2021 19:57 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/2 "2021-10-27T19:57:39Z")

</div>

Two conditions. The "if I wont it" means most probably manual override. Any other case it should switch in every hour change.

The inject node can be set to fire message hourly. Your wish will be gate to allow the hourly message to do the switching, So called the "gate". And the switching is just turn over the current state. To know the current state,it takes to know the state so it should be even stored in some context or can be asked from device.

So - to give a good advice - it takes to know related aspects of your setup.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [27 October 2021 19:59 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/3 "2021-10-27T19:59:29Z")

</div>

A simple solution...

![oppo](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0a2e0f5ebc44646f5540ae23ff79d7ac1a13804.jpeg)

```auto
[{"id":"a7d157913092ce7b","type":"inject","z":"f8cf7ea5344d6287","name":"every 2 mins","props":[{"p":"payload"}],"repeat":"120","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":115,"y":920,"wires":[["2d960bb3aacbf37d"]]},{"id":"2d960bb3aacbf37d","type":"trigger","z":"f8cf7ea5344d6287","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":285,"y":920,"wires":[["5afc656133b343b3"]]},{"id":"5afc656133b343b3","type":"debug","z":"f8cf7ea5344d6287","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":455,"y":920,"wires":[]}]

```

Edit - just seen @hotNipi 's post (cross post), it's good advice 👍

---

<div class="post-metadata">

**Author:** ![iiot2k](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@iiot2k](https://discourse.nodered.org/u/iiot2k)\
**Post date:** [27 October 2021 20:07 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/4 "2021-10-27T20:07:50Z")

</div>

Which hardware do you use for control timer and output (relay) ?

---

<div class="post-metadata">

**Author:** ![dpatel2016](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dpatel2016/32/33730_2.png) [@dpatel2016](https://discourse.nodered.org/u/dpatel2016)\
**Post date:** [28 October 2021 16:58 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/5 "2021-10-28T16:58:51Z")

</div>

Thank you for the suggestions. I am still a little confused because I am trying to turn on 6 relays, but 2 at a time. I want to fire two relays for an hour and then turn them off to fire the other two for an hour and so on.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [28 October 2021 18:42 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/6 "2021-10-28T18:42:30Z")

</div>

You didn't say that in your first post... (this point was highlighted in **hotnipi**'s comment above)

But...

 ![delays](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/37a67200161b18136903ef057cba7b4a23e8f8c2.jpeg)

```auto
[{"id":"a7d157913092ce7b","type":"inject","z":"b3b413d1.05b1b","name":"every 3 mins","props":[{"p":"payload"}],"repeat":"180","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":130,"y":1545,"wires":[["2d960bb3aacbf37d","27324a9eeb602acf"]]},{"id":"2d960bb3aacbf37d","type":"trigger","z":"b3b413d1.05b1b","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":300,"y":1545,"wires":[["5afc656133b343b3"]]},{"id":"5afc656133b343b3","type":"debug","z":"b3b413d1.05b1b","name":"Relay 1 & 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":460,"y":1545,"wires":[]},{"id":"999c7d6c257117f1","type":"trigger","z":"b3b413d1.05b1b","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":445,"y":1590,"wires":[["4e234c73842104f0"]]},{"id":"4e234c73842104f0","type":"debug","z":"b3b413d1.05b1b","name":"Relay 3 & 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":605,"y":1590,"wires":[]},{"id":"6e168a4613cf85ce","type":"trigger","z":"b3b413d1.05b1b","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"1","extend":false,"overrideDelay":false,"units":"min","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":1635,"wires":[["39b7760d58873fee"]]},{"id":"39b7760d58873fee","type":"debug","z":"b3b413d1.05b1b","name":"Relay 4 & 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":735,"y":1635,"wires":[]},{"id":"27324a9eeb602acf","type":"delay","z":"b3b413d1.05b1b","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":290,"y":1590,"wires":[["5f521392ac381917","999c7d6c257117f1"]]},{"id":"5f521392ac381917","type":"delay","z":"b3b413d1.05b1b","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":435,"y":1635,"wires":[["6e168a4613cf85ce"]]}]

```

---

<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:** [27 December 2021 18:42 UTC](https://discourse.nodered.org/t/timer-to-turn-switch-on-off/52849/7 "2021-12-27T18:42:38Z")

</div>

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