Countdown Node

1,586 views
Skip to first unread message

boris runakov

unread,
Dec 29, 2016, 6:18:04 AM12/29/16
to Node-RED
Hello !
New to node-red. I would like to create a flow to specify a delay (30 min) for example and trigger something after that period.
Is there any node for this? Or any package I can insall ?
Thank you in advance

Zenofmud

unread,
Dec 29, 2016, 6:29:03 AM12/29/16
to node...@googlegroups.com
Take a look at the ‘Inject’ node in the sidebar or look in https://flows.nodered.org for one of the timer nodes

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/7237b848-0c03-4c9b-a196-2f4150cb1412%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave C-J

unread,
Dec 29, 2016, 6:55:32 AM12/29/16
to node...@googlegroups.com
or the delay node if you want a fixed delay
or the trigger node if you want to be able to cancel or extend it.

boris runakov

unread,
Dec 29, 2016, 7:05:24 AM12/29/16
to Node-RED
I have tried the trigger node , however I would like to make the duration adjustable using a numeric node of the ui-dasboard package.
Is that possible?

boris runakov

unread,
Dec 29, 2016, 7:11:57 AM12/29/16
to node...@googlegroups.com
What I would like to do is set the duration for the trigger node , turn a led on , and turn it off after the set time automatically

On Thu, Dec 29, 2016 at 2:05 PM, boris runakov <borisr...@gmail.com> wrote:
I have tried the trigger node , however I would like to make the duration adjustable using a numeric node of the ui-dasboard package.
Is that possible?

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/pfa8qSIE82I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Dave C-J

unread,
Dec 29, 2016, 10:57:47 AM12/29/16
to node...@googlegroups.com
welcome to the world of functions :-)
I would use a function node to do this, fed by the two UI elements - one a button to trigger things and the numeric input to set the duration - set a topic on at least one of them... then in the function use the msg.topic to distinguish which message arrived. If the numeric one then set a context variable with the value (to save it) and return null. If the trigger message use the context variable to 1)  create a setTimeout statement to node.send({payload:"off"} and 2) then return {payload:"on"};     then return will happen straight away and then the timeout will occur and fire later.

boris runakov

unread,
Dec 29, 2016, 12:52:48 PM12/29/16
to node...@googlegroups.com
So far I have this :
[{"id":"8206d965.39384","type":"tab","label":"Flow 2"},{"id":"47ca922a.a7c244","type":"ui_switch","z":"8206d965.39384","name":"","label":"switch","group":"7d660aaa.41817c","order":0,"width":0,"height":0,"passthru":true,"topic":"on_off","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":218.5,"y":179,"wires":[["24024d81.92a282"]]},{"id":"827033bc.32ab1","type":"ui_numeric","z":"8206d965.39384","name":"","label":"numeric","group":"7d660aaa.41817c","order":0,"width":0,"height":0,"passthru":true,"topic":"numeric","format":"{{value}}","min":0,"max":10,"step":1,"x":207.5,"y":240,"wires":[["24024d81.92a282"]]},{"id":"24024d81.92a282","type":"function","z":"8206d965.39384","name":"","func":"var time = 0;\n\nif (msg.topic == \"numeric\"){\n    var time = msg.payload;\n    return null;\n}\nelse if (msg.topic == \"on_off\"){\n    setTimeout({payload:\"off\"},time);\n    return {payload:\"on\"};\n}","outputs":1,"noerr":0,"x":359.5,"y":207,"wires":[["ce7d307f.388958"]]},{"id":"ce7d307f.388958","type":"debug","z":"8206d965.39384","name":"","active":true,"console":"false","complete":"payload","x":580.5,"y":166,"wires":[]},{"id":"7d660aaa.41817c","type":"ui_group","z":"","name":"Default","tab":"9b0940f3.a925b8","disp":true,"width":"6"},{"id":"9b0940f3.a925b8","type":"ui_tab","z":"","name":"tests","icon":"dashboard"}]


Can you help me out with this please?


On Thu, Dec 29, 2016 at 5:57 PM, Dave C-J <dce...@gmail.com> wrote:
welcome to the world of functions :-)
I would use a function node to do this, fed by the two UI elements - one a button to trigger things and the numeric input to set the duration - set a topic on at least one of them... then in the function use the msg.topic to distinguish which message arrived. If the numeric one then set a context variable with the value (to save it) and return null. If the trigger message use the context variable to 1)  create a setTimeout statement to node.send({payload:"off"} and 2) then return {payload:"on"};     then return will happen straight away and then the timeout will occur and fire later.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/pfa8qSIE82I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

somebuddy

unread,
Dec 30, 2016, 7:02:57 AM12/30/16
to Node-RED
[{"id":"ce5534a3.3f8b98","type":"function","z":"be10358d.5f3058","name":"","func":"\nvar value  = context.get('value') || 60000;\n\nif (msg.topic == \"value\")\n{\n  value = msg.payload * 60000;\n  context.set('value',value);  \n}\n\nelse if (msg.topic == \"start\")\n{\n\nvar timer = setTimeout(function(){msg.payload = \"now\";node.send([msg,{ payload: \"Ende\" }]);var countdownstop  = context.get('countdown');clearInterval(countdownstop)},value);\ncontext.set('timer',timer); \n\nvar count = value/60000;\n//count = count -1 ;\nmsg.payload=count;\nnode.send([null,msg]);\nvar countdown = setInterval(function() {count=count-1;msg.payload=count; node.send([null,msg]) }, 60000);\ncontext.set('countdown',countdown);\n\n}\n\nelse if (msg.topic == \"stop\")\n{\nvar timerstop  = context.get('timer')\nclearTimeout(timerstop);\n\nvar countdownstop  = context.get('countdown')\nclearInterval(countdownstop);\n\n}\n\n\n","outputs":"2","noerr":0,"x":410,"y":220,"wires":[["a70f86ce.c18f58"],["fa7c7eb.15f9d8"]]},{"id":"a70f86ce.c18f58","type":"debug","z":"be10358d.5f3058","name":"","active":true,"console":"false","complete":"payload","x":590,"y":180,"wires":[]},{"id":"6c4f84d8.656ebc","type":"ui_button","z":"be10358d.5f3058","name":"","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"label":"Start","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"start","x":190,"y":200,"wires":[["ce5534a3.3f8b98"]]},{"id":"1f4a748.bcd498c","type":"ui_numeric","z":"be10358d.5f3058","name":"","label":"Minuten","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"passthru":true,"topic":"value","format":"{{value}}","min":"1","max":"300","step":1,"x":180,"y":280,"wires":[["ce5534a3.3f8b98"]]},{"id":"8dba67c8.f2a418","type":"ui_button","z":"be10358d.5f3058","name":"","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"label":"Stop","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"stop","x":190,"y":240,"wires":[["ce5534a3.3f8b98"]]},{"id":"fa7c7eb.15f9d8","type":"ui_text","z":"be10358d.5f3058","group":"637d8cb3.d53d74","order":0,"width":0,"height":0,"name":"","label":"Restzeit","format":"{{msg.payload}} Minuten","layout":"row-spread","x":600,"y":240,"wires":[]},{"id":"637d8cb3.d53d74","type":"ui_group","z":"","name":"Default","tab":"7fe8c0a9.8eebd","disp":true,"width":"6"},{"id":"7fe8c0a9.8eebd","type":"ui_tab","z":"","name":"tests","icon":"dashboard"}]


Am Donnerstag, 29. Dezember 2016 18:52:48 UTC+1 schrieb boris runakov:
So far I have this :
[{"id":"8206d965.39384","type":"tab","label":"Flow 2"},{"id":"47ca922a.a7c244","type":"ui_switch","z":"8206d965.39384","name":"","label":"switch","group":"7d660aaa.41817c","order":0,"width":0,"height":0,"passthru":true,"topic":"on_off","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":218.5,"y":179,"wires":[["24024d81.92a282"]]},{"id":"827033bc.32ab1","type":"ui_numeric","z":"8206d965.39384","name":"","label":"numeric","group":"7d660aaa.41817c","order":0,"width":0,"height":0,"passthru":true,"topic":"numeric","format":"{{value}}","min":0,"max":10,"step":1,"x":207.5,"y":240,"wires":[["24024d81.92a282"]]},{"id":"24024d81.92a282","type":"function","z":"8206d965.39384","name":"","func":"var time = 0;\n\nif (msg.topic == \"numeric\"){\n    var time = msg.payload;\n    return null;\n}\nelse if (msg.topic == \"on_off\"){\n    setTimeout({payload:\"off\"},time);\n    return {payload:\"on\"};\n}","outputs":1,"noerr":0,"x":359.5,"y":207,"wires":[["ce7d307f.388958"]]},{"id":"ce7d307f.388958","type":"debug","z":"8206d965.39384","name":"","active":true,"console":"false","complete":"payload","x":580.5,"y":166,"wires":[]},{"id":"7d660aaa.41817c","type":"ui_group","z":"","name":"Default","tab":"9b0940f3.a925b8","disp":true,"width":"6"},{"id":"9b0940f3.a925b8","type":"ui_tab","z":"","name":"tests","icon":"dashboard"}]


Can you help me out with this please?

On Thu, Dec 29, 2016 at 5:57 PM, Dave C-J <dce...@gmail.com> wrote:
welcome to the world of functions :-)
I would use a function node to do this, fed by the two UI elements - one a button to trigger things and the numeric input to set the duration - set a topic on at least one of them... then in the function use the msg.topic to distinguish which message arrived. If the numeric one then set a context variable with the value (to save it) and return null. If the trigger message use the context variable to 1)  create a setTimeout statement to node.send({payload:"off"} and 2) then return {payload:"on"};     then return will happen straight away and then the timeout will occur and fire later.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/pfa8qSIE82I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

boris runakov

unread,
Dec 30, 2016, 7:10:35 AM12/30/16
to node...@googlegroups.com
Wunderbar!
Exactly what I was looking for !Appreciate it !




To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Joseph Martine

unread,
Mar 14, 2017, 5:06:51 PM3/14/17
to Node-RED
This is GREAT!   spent most of yesterday evening fighting a good way to do this with delay or timer.   The sticky piece was injecting how long to wait/countdown.

THanks!
Reply all
Reply to author
Forward
0 new messages