Blink with different On/Off time

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

Thanks a lot !
Nico

Hi Nico,

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

 [{"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}]

(edited to fix flow - DCJ)

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

[{"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.

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 :slight_smile:

Thank you

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.

Here's the downloaded file, though I think DCJ has fixed the error.
flows.json (2.9 KB)

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