# Blink with different On/Off time

**URL:** <https://discourse.nodered.org/t/blink-with-different-on-off-time/25304>\
**Category:** General\
**Created:** [22 April 2020 13:11 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304 "2020-04-22T13:11:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LTDS](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@LTDS](https://discourse.nodered.org/u/LTDS)\
**Post date:** [22 April 2020 13:11 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/1 "2020-04-22T13:11:46Z")

</div>

Hi there ! Once again I'm asking for your support !  
I need to trigger an alarm with a blink function but not the typical blink (x sec ON - x sec OFF) but with different On and Off time (x sec ON - y sec OFF)

I've found the "Blinking a LED on Raspberry PI" flow from IgnacioRubio witch work just fine for me with some minors modifications (just to be able to change the blink delay from dashboard using a global variable).  
Now I would like to know if it is possible to do what I need with the function used here or if I need another one?

Flow here : [https://flows.nodered.org/flow/3dbd62dfa8f6db78a598d0c7263f0f97](https://flows.nodered.org/flow/3dbd62dfa8f6db78a598d0c7263f0f97)

Thanks a lot !  
Nico

---

<div class="post-metadata">

**Author:** ![Brew](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brew/32/19776_2.png) [@Brew](https://discourse.nodered.org/u/Brew)\
**Post date:** [22 April 2020 20:12 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/2 "2020-04-22T20:12:08Z")

</div>

Hi Nico,

Here is a what I've built, this is based on a bit of searching around that I found.

```auto
 [{"id":"16c2553d.aac89b","type":"rpi-gpio out","z":"881975da.a3c468","name":"15-Sw1 LED","pin":"15","set":true,"level":"0","freq":"","out":"out","x":1430,"y":360,"wires":[]},{"id":"28425e06.f2483a","type":"inject","z":"881975da.a3c468","name":"On","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":710,"y":340,"wires":[["432530be.b3a9c8","80157a87.0a0ea"]]},{"id":"a03bf585.67a2b8","type":"inject","z":"881975da.a3c468","name":"Off","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":710,"y":420,"wires":[["432530be.b3a9c8","80157a87.0a0ea"]]},{"id":"432530be.b3a9c8","type":"ui_switch","z":"881975da.a3c468","name":"","label":"Sw1 op","tooltip":"","group":"edbefee9.e1a238","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":740,"y":380,"wires":[["80157a87.0a0ea"]]},{"id":"d08c836.194c6","type":"comment","z":"881975da.a3c468","name":"Indicator and manual switch","info":"","x":760,"y":300,"wires":[]},{"id":"52f28ff6.7295","type":"comment","z":"881975da.a3c468","name":"GPO LEDs","info":"LED outputs GPIO 15 and 16","x":1430,"y":300,"wires":[]},{"id":"ff70e0e8.76d36","type":"trigger","z":"881975da.a3c468","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":1220,"y":360,"wires":[["b4d4ce0.4454f3","16c2553d.aac89b"]]},{"id":"b4d4ce0.4454f3","type":"function","z":"881975da.a3c468","name":"","func":"if (msg.payload == \"off\")\n\tcontext.state = 0;\nif (msg.payload == \"on\")\n\tcontext.state = 1;\n\nif (context.state == 1)\n{\n\tif (msg.payload == 0)\n\t\treturn msg;\n\telse\n\t\treturn;\n}\nelse\n\treturn;","outputs":1,"noerr":0,"x":1070,"y":420,"wires":[["5b50bd02.42c0b4"]]},{"id":"80157a87.0a0ea","type":"switch","z":"881975da.a3c468","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":910,"y":380,"wires":[["b4d4ce0.4454f3","ff70e0e8.76d36"],["b4d4ce0.4454f3"]]},{"id":"5b50bd02.42c0b4","type":"delay","z":"881975da.a3c468","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1220,"y":420,"wires":[["ff70e0e8.76d36"]]},{"id":"401354fa.29640c","type":"comment","z":"881975da.a3c468","name":"Blinking LED","info":"","x":1090,"y":300,"wires":[]},{"id":"edbefee9.e1a238","type":"ui_group","z":"","name":"Switch State","tab":"fbc9eb65.e88ff","order":1,"disp":true,"width":4,"collapse":false},{"id":"fbc9eb65.e88ff","type":"ui_tab","z":"","name":"Queue Lane","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

 ![Screenshot 2020-04-22 at 21.11.29](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9fafff47d28fef8d21de6308d01a345ed52fc1de.png)

(edited to fix flow - DCJ)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [22 April 2020 21:19 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/3 "2020-04-22T21:19:45Z")

</div>

You can do this with just two trigger nodes if you like

```auto
[{"id":"c21f81fa.7ccbf","type":"inject","z":"a992b717.c41468","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":900,"wires":[["bb39e73d.60c5b8"]]},{"id":"bb39e73d.60c5b8","type":"trigger","z":"a992b717.c41468","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-3","extend":false,"units":"s","reset":"stop","bytopic":"all","name":"","x":360,"y":860,"wires":[["84390cdd.5cbe9"]]},{"id":"5170e53b.b2070c","type":"inject","z":"a992b717.c41468","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":820,"wires":[["bb39e73d.60c5b8"]]},{"id":"84390cdd.5cbe9","type":"trigger","z":"a992b717.c41468","op1":"1","op2":"0","op1type":"num","op2type":"num","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":540,"y":860,"wires":[["cbd3f15b.a52a3"]]},{"id":"cbd3f15b.a52a3","type":"debug","z":"a992b717.c41468","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":710,"y":860,"wires":[]}]

```

the first set to repeat (until stopped) at the overall time period you want - and the other set to do a trigger for just the on period.

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

---

<div class="post-metadata">

**Author:** ![LTDS](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@LTDS](https://discourse.nodered.org/u/LTDS)\
**Post date:** [23 April 2020 06:57 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/4 "2020-04-23T06:57:39Z")

</div>

Thank you both ! Brew, I can't import your flux... It seems that you have some unknown characters.

dceejay, you flux seems to work quite nicely but is there a way to set the delays from dashboard using a global ? If there is no way that's ok I'll deal with it but that would be nice 🙂

Thank you

---

<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:** [23 April 2020 07:47 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/5 "2020-04-23T07:47:46Z")

</div>

If you would be happy with a fixed total period (on time plus off time) then node-red-contrib-timeprop would do this for you. Set up the total cycle time in the node and then pass it the ratio on/off time you want (between 0 and 1) and it will provide the result you can feed to the LED.

---

<div class="post-metadata">

**Author:** ![Brew](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/brew/32/19776_2.png) [@Brew](https://discourse.nodered.org/u/Brew)\
**Post date:** [23 April 2020 14:38 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/6 "2020-04-23T14:38:11Z")

</div>

Here's the downloaded file, though I think DCJ has fixed the error.  
[flows.json](https://discourse.nodered.org/uploads/short-url/kkXSHWKiEm08MHjweS8fhYSi3l.json) (2.9 KB)

---

<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:** [22 June 2020 14:40 UTC](https://discourse.nodered.org/t/blink-with-different-on-off-time/25304/7 "2020-06-22T14:40:45Z")

</div>

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