Set delay with slider

Hello everyone,
I tried multiple nodes to get this idea done, but nothing works (delay, eztimer, timer switch...). I need something like a loop with a start/stop function. One button start and stop, or a toggle switch to activate the loop. The loop should be controlled with sliders. One slider to set the time for each delay. The loop should send MQTT commands. On after x seconds and of after y seconds, again and again until you turn it off. Is there a simple way to make this work? In my example I didn't change msg.payload to msg.delay. I also tried this but it didn't work.

[{"id":"4efd39c4.508638","type":"ui_slider","z":"8f6a5894.b4277","name":"","label":"PAUSE","tooltip":"","group":"5c0aca13.e51a04","order":4,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":"30","max":"220","step":1,"x":1060,"y":280,"wires":[["f68e5dc5.1ce718"]]},{"id":"39e2a30.4055cde","type":"ui_slider","z":"8f6a5894.b4277","name":"","label":"ACTIVE","tooltip":"","group":"5c0aca13.e51a04","order":5,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":"5","max":"60","step":1,"x":990,"y":580,"wires":[["c733c4be.b6a09"]]},{"id":"f68e5dc5.1ce718","type":"delay","z":"8f6a5894.b4277","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1160,"y":380,"wires":[["c733c4be.b6a09","8530a299.37"]]},{"id":"c733c4be.b6a09","type":"delay","z":"8f6a5894.b4277","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1160,"y":500,"wires":[["5a126c55.3e620c","ce1c2e0e.92332"]]},{"id":"ce1c2e0e.92332","type":"ui_switch","z":"8f6a5894.b4277","name":"","label":"switch","tooltip":"","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":true,"onvalueType":"bool","onicon":"","oncolor":"","offvalue":false,"offvalueType":"bool","officon":"","offcolor":"","x":670,"y":420,"wires":[["8e537ffc.046e68"]]},{"id":"8530a299.37","type":"change","z":"8f6a5894.b4277","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1360,"y":320,"wires":[["7c790ef3.8ac768"]]},{"id":"5a126c55.3e620c","type":"change","z":"8f6a5894.b4277","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":580,"wires":[["7c790ef3.8ac768"]]},{"id":"8e537ffc.046e68","type":"switch","z":"8f6a5894.b4277","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":840,"y":420,"wires":[["5c765e20.1eb06"],["f68e5dc5.1ce718"]]},{"id":"5c765e20.1eb06","type":"change","z":"8f6a5894.b4277","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":440,"wires":[["7c790ef3.8ac768"]]},{"id":"7c790ef3.8ac768","type":"mqtt out","z":"8f6a5894.b4277","name":"","topic":"","qos":"","retain":"","x":1630,"y":440,"wires":[]},{"id":"5c0aca13.e51a04","type":"ui_group","z":"","name":"BONDAGE","tab":"d3d32d16.52e25","order":7,"disp":true,"width":"6","collapse":false},{"id":"d3d32d16.52e25","type":"ui_tab","z":"","name":"DRONE X005","icon":"dashboard","disabled":false,"hidden":false}]

The first thing I notice is that the ui_switch is configured to output boolean true/false but the Switch node it feeds into is testing for string 0 an 1, that may or may not work, I don't know, but best to correct that.

[Edit] However I think the fundamental problem is that setting msg.delay for a delay node changes the delay for just that message, plus each time you move the slider you will be adding another message into the loop, so you will get more and more messages going round the loop. The simplest solution might be to use the sliders to set flow context variables and then put change nodes in your loop that add in msg.delay from the context variables.
I would probably use Trigger rather than Delay nodes because delay nodes could be a bit confusing if you somehow get more than one message in the loop (possibly when re-deploying for example). I think Trigger nodes would be less susceptible to that.

Try this. The Go and Stop inject nodes simulate your switch, which should send number 1 and 0. The Slider On inject nodes simulate your On time slider sending 1 and 5 (seconds) and similarly the Slider Off simulate the Off time slider 5 or 10 seconds.

[{"id":"3a09c2e7.b8e12e","type":"inject","z":"6d810db7.640bf4","name":"Slider on 5","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":360,"y":540,"wires":[["b62ecb25.1b22a8"]]},{"id":"aef44c63.affcc","type":"inject","z":"6d810db7.640bf4","name":"Slider on 1","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":360,"y":500,"wires":[["b62ecb25.1b22a8"]]},{"id":"f53927b.e7c5458","type":"inject","z":"6d810db7.640bf4","name":"Slider off 5","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":360,"y":600,"wires":[["9ed25c31.2c3fd"]]},{"id":"4e1ba04b.1bc128","type":"inject","z":"6d810db7.640bf4","name":"Slider off 10","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":370,"y":640,"wires":[["9ed25c31.2c3fd"]]},{"id":"9a72ebb9.9ed268","type":"trigger","z":"6d810db7.640bf4","name":"On","op1":"1","op2":"0","op1type":"num","op2type":"str","duration":"1","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":710,"y":160,"wires":[["669596f0.624a1"],["1518de66.ca97da"]]},{"id":"3cbf52b7.fb014e","type":"trigger","z":"6d810db7.640bf4","name":"Off","op1":"0","op2":"1","op1type":"num","op2type":"num","duration":"5","extend":false,"overrideDelay":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":730,"y":280,"wires":[["669596f0.624a1"],["d329941e.0e5fd"]]},{"id":"669596f0.624a1","type":"debug","z":"6d810db7.640bf4","name":"To GPIO","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":320,"wires":[]},{"id":"b62ecb25.1b22a8","type":"change","z":"6d810db7.640bf4","name":"","rules":[{"t":"set","p":"onDelay","pt":"flow","to":"payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":520,"wires":[[]]},{"id":"9ed25c31.2c3fd","type":"change","z":"6d810db7.640bf4","name":"","rules":[{"t":"set","p":"offDelay","pt":"flow","to":"payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":600,"wires":[[]]},{"id":"17184947.0b3fcf","type":"change","z":"6d810db7.640bf4","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"onDelay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":160,"wires":[["9a72ebb9.9ed268"]]},{"id":"1518de66.ca97da","type":"change","z":"6d810db7.640bf4","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"offDelay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":220,"wires":[["3cbf52b7.fb014e"]]},{"id":"d329941e.0e5fd","type":"link out","z":"6d810db7.640bf4","name":"","links":["f55c4c59.72a628"],"x":795,"y":340,"wires":[]},{"id":"f55c4c59.72a628","type":"link in","z":"6d810db7.640bf4","name":"","links":["d329941e.0e5fd"],"x":375,"y":240,"wires":[["17184947.0b3fcf"]]},{"id":"fe1a9f6e.9f431","type":"inject","z":"6d810db7.640bf4","name":"Go","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":330,"y":300,"wires":[["2d17b00.2facc5"]]},{"id":"4948e48b.78fa74","type":"inject","z":"6d810db7.640bf4","name":"Stop","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":330,"y":340,"wires":[["2d17b00.2facc5"]]},{"id":"2d17b00.2facc5","type":"switch","z":"6d810db7.640bf4","name":"stop/go","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":480,"y":300,"wires":[["17184947.0b3fcf"],["a7d6a518.a37d5"]]},{"id":"a7d6a518.a37d5","type":"change","z":"6d810db7.640bf4","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":400,"wires":[["9a72ebb9.9ed268","3cbf52b7.fb014e","5e21fc41.aa6efc"]]},{"id":"5e21fc41.aa6efc","type":"change","z":"6d810db7.640bf4","name":"switch off","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":400,"wires":[["669596f0.624a1"]]}]

Thank you Colin, I tried it but it didn't work. It turn it on for one second like in the trigger node and of again. So no real loop. Maybe the set msg.delay doesn't work?

Did you import my flow and run it as it is? It works for me.

If you have modified it to use the slider etc then export it here and I will take a look.

Yes, I imported it and there where just 2 msg in debug. Heres what i tried to update.

[{"id":"9374daa3.2ffa08","type":"inject","z":"4eca52a7.d332ec","name":"Slider on 5","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":3540,"wires":[["1ec5c42.cd3e5bc"]]},{"id":"c1016fdc.6b2508","type":"inject","z":"4eca52a7.d332ec","name":"Slider on 1","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":3500,"wires":[["1ec5c42.cd3e5bc"]]},{"id":"5752a99a.e124b","type":"inject","z":"4eca52a7.d332ec","name":"Slider off 5","topic":"","payload":"15","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":570,"y":3600,"wires":[["9960d43d.2239d"]]},{"id":"a56fdbdd.d2ba08","type":"inject","z":"4eca52a7.d332ec","name":"Slider off 10","topic":"","payload":"30","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":580,"y":3640,"wires":[["9960d43d.2239d"]]},{"id":"234ad918.e57a2e","type":"trigger","z":"4eca52a7.d332ec","op1":"1","op2":"0","op1type":"num","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"On","x":920,"y":3160,"wires":[["63a7716.4779d1"],["fffa9b56.52994"]]},{"id":"8690f55a.00575","type":"trigger","z":"4eca52a7.d332ec","op1":"0","op2":"1","op1type":"num","op2type":"num","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","name":"Off","x":940,"y":3280,"wires":[["63a7716.4779d1"],["fadde054.e82a18"]]},{"id":"1ec5c42.cd3e5bc","type":"change","z":"4eca52a7.d332ec","name":"","rules":[{"t":"set","p":"onDelay","pt":"flow","to":"payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":3520,"wires":[[]]},{"id":"9960d43d.2239d","type":"change","z":"4eca52a7.d332ec","name":"","rules":[{"t":"set","p":"offDelay","pt":"flow","to":"payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":3600,"wires":[[]]},{"id":"3512d9a0.07f7ee","type":"change","z":"4eca52a7.d332ec","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"onDelay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":3160,"wires":[["234ad918.e57a2e"]]},{"id":"fffa9b56.52994","type":"change","z":"4eca52a7.d332ec","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"offDelay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":3220,"wires":[["8690f55a.00575"]]},{"id":"fadde054.e82a18","type":"link out","z":"4eca52a7.d332ec","name":"","links":["9e4eb6bf.dc4948"],"x":1005,"y":3340,"wires":[]},{"id":"9e4eb6bf.dc4948","type":"link in","z":"4eca52a7.d332ec","name":"","links":["fadde054.e82a18"],"x":585,"y":3240,"wires":[["3512d9a0.07f7ee"]]},{"id":"7c80abd7.3ca62c","type":"inject","z":"4eca52a7.d332ec","name":"Go","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":3300,"wires":[["167d013c.91dbff"]]},{"id":"7a33b987.6ed838","type":"inject","z":"4eca52a7.d332ec","name":"Stop","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":3340,"wires":[["167d013c.91dbff"]]},{"id":"167d013c.91dbff","type":"switch","z":"4eca52a7.d332ec","name":"stop/go","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":690,"y":3300,"wires":[["3512d9a0.07f7ee"],["dcb355cd.021d88"]]},{"id":"dcb355cd.021d88","type":"change","z":"4eca52a7.d332ec","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":3400,"wires":[["234ad918.e57a2e","8690f55a.00575","616e3781.18c538"]]},{"id":"616e3781.18c538","type":"change","z":"4eca52a7.d332ec","name":"switch off","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":3400,"wires":[["63a7716.4779d1"]]},{"id":"63a7716.4779d1","type":"mqtt out","z":"4eca52a7.d332ec","name":"","topic":"relais/pp005","qos":"","retain":"","broker":"d2bdceba.f61eb","x":1250,"y":3340,"wires":[]},{"id":"6cf9c81e.cd4bf8","type":"ui_slider","z":"4eca52a7.d332ec","name":"","label":"ON DURATION","tooltip":"","group":"114e35a6.54a212","order":0,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":"14","max":"120","step":1,"x":290,"y":3540,"wires":[["1ec5c42.cd3e5bc"]]},{"id":"7d0dc549.52e86c","type":"ui_slider","z":"4eca52a7.d332ec","name":"","label":"PAUSE DURATION","tooltip":"","group":"114e35a6.54a212","order":2,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":"15","max":"120","step":1,"x":310,"y":3640,"wires":[["9960d43d.2239d"]]},{"id":"84d072c5.ac1f6","type":"ui_button","z":"4eca52a7.d332ec","name":"","group":"114e35a6.54a212","order":3,"width":0,"height":0,"passthru":false,"label":"START","tooltip":"","color":"","bgcolor":"","icon":"","payload":"1","payloadType":"num","topic":"","x":310,"y":3280,"wires":[["167d013c.91dbff"]]},{"id":"4e00061b.091a88","type":"ui_button","z":"4eca52a7.d332ec","name":"","group":"114e35a6.54a212","order":2,"width":0,"height":0,"passthru":false,"label":"STOP","tooltip":"","color":"","bgcolor":"","icon":"","payload":"0","payloadType":"num","topic":"","x":340,"y":3360,"wires":[["167d013c.91dbff"]]},{"id":"d2bdceba.f61eb","type":"mqtt-broker","z":"","name":"Relais","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"114e35a6.54a212","type":"ui_group","z":"","name":"AUTO DEMO","tab":"cf052acc.01273","order":1,"disp":true,"width":"6","collapse":false},{"id":"cf052acc.01273","type":"ui_tab","z":"","name":"Auto demo","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

You have lost the override delay with msg.delay setting in the two Trigger nodes

image

If you haven't got that setting available in your Trigger nodes then you must be using an ancient version of node red.

Aaaaaah nice. Updated everything and it works now. Thank you for you help Colin :slight_smile:

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