# Send http request using delay node

**URL:** <https://discourse.nodered.org/t/send-http-request-using-delay-node/5950>\
**Category:** General\
**Created:** [19 December 2018 06:29 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950 "2018-12-19T06:29:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NRIT](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@NRIT](https://discourse.nodered.org/u/NRIT)\
**Post date:** [19 December 2018 06:29 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/1 "2018-12-19T06:29:19Z")

</div>

Hi all,

I'm developing a simple node red IoT project  
In particular, when a sensor value is over a threshold, an http request is performed against a ticket system and, if doesn't yet exist, a ticket is opened  
This is ok but, because data are gathered each second, if the value is higher than the threshold, node red will perform an http request each second too and this isn't good, I think.  
So, I put a delay node using Rate Limit and a period of 30 second  
In this way, when the value is over the threshold the first ticket will be opened after 30 second, while I would like open the ticket immediately and then wait for 30 second  
Is this possibile using only the delay node or shall I develop custom code?  
I hope my explation is clear  
Thanks in advance for your help

Regards

---

<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:** [19 December 2018 06:38 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/2 "2018-12-19T06:38:55Z")

</div>

I think you can use the **Trigger** node with following settings

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/233f1ba5ee5c2ec76fc66d34788543f5cf7af57c.png)

---

<div class="post-metadata">

**Author:** ![NRIT](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@NRIT](https://discourse.nodered.org/u/NRIT)\
**Post date:** [19 December 2018 08:45 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/3 "2018-12-19T08:45:31Z")

</div>

many thanks. But this configuration works only with a single message.  
If I have multiple messages distingueshed by msg.topic the trigger node sent only a message.  
(see the following flow)

```
[{"id":"19407975.95b1f7","type":"tab","label":"TEST","disabled":false,"info":""},{"id":"9072b336.4e1e9","type":"function","z":"19407975.95b1f7","name":"extract info","func":"\nreturn [\n\n\t{payload: msg.payload.Stoccaggio},\n\t{payload: msg.payload.Prelievo},\n\t{payload: msg.payload.Alimentazione}\n \n];","outputs":3,"noerr":0,"x":752.6587905883789,"y":88.52387809753418,"wires":[["adbad9a5.3df078"],["32a22c82.9c4ed4"],["8c144221.4ea41"]],"outputLabels":["Stoccaggio","Prelievo","Alimentazione"]},{"id":"32a22c82.9c4ed4","type":"function","z":"19407975.95b1f7","name":"Prelievo","func":"//msg.payload = Math.floor(msg.payload/3600.0*100)/100;\n\nmsg.topic = 'Prelievo magazzino';\nmsg.soglia = -1;\nmsg.WO_DESC = 'Prelievo magazzino';\nmsg.WORKTYPE = 'FAIL';\nmsg.LOCATION = 'POEMP';\nmsg.WO_STATUS = 'NUOVO';\n\nvar m = msg.payload*1.5;\nmsg.ui_control = {\"min\":0,\"max\":m}\n\nmsg.url = \"aa\"; \n\nreturn msg;","outputs":1,"noerr":0,"x":1022.4169082641602,"y":88.25006294250488,"wires":[["876030c3.c812"]]},{"id":"876030c3.c812","type":"switch","z":"19407975.95b1f7","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"-1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1209.7383003234863,"y":91.57147407531738,"wires":[["70b8b856.797888"]]},{"id":"87f3534d.9e49a","type":"debug","z":"19407975.95b1f7","name":"Do HTTP Request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1573.5002708435059,"y":92.00007486343384,"wires":[]},{"id":"8c144221.4ea41","type":"function","z":"19407975.95b1f7","name":"Alimentazione","func":"//msg.payload = Math.floor(msg.payload/3600.0*100)/100;\n\nmsg.topic = 'Contatore Alimentazione';\nmsg.soglia = -1;\nmsg.WO_DESC = 'Contatore Alimentazione';\nmsg.WORKTYPE = 'FAIL';\nmsg.LOCATION = 'POEMP';\nmsg.WO_STATUS = 'NUOVO';\n\nvar m = msg.payload*1.5;\nmsg.ui_control = {\"min\":0,\"max\":m}\n\nmsg.url = \"aa\"; \n\nreturn msg;","outputs":1,"noerr":0,"x":1045.6669082641602,"y":138.0000514984131,"wires":[["876030c3.c812"]]},{"id":"adbad9a5.3df078","type":"function","z":"19407975.95b1f7","name":"Stoccaggio","func":"//msg.payload = Math.floor(msg.payload/3600.0*100)/100;\n\nmsg.topic = 'Stoccaggio';\nmsg.soglia = -1;\nmsg.WO_DESC = 'Contatore Stoccaggio';\nmsg.WORKTYPE = 'FAIL';\nmsg.LOCATION = 'POEMP';\nmsg.WO_STATUS = 'NUOVO';\n\nvar m = msg.payload*1.5;\nmsg.ui_control = {\"min\":0,\"max\":m}\n\nmsg.url = \"aa\"; \n\nreturn msg;","outputs":1,"noerr":0,"x":1040.047866821289,"y":37.44049835205078,"wires":[["876030c3.c812"]]},{"id":"d5da8ab.f366678","type":"random","z":"19407975.95b1f7","name":"","low":"1","high":"1000","inte":"true","property":"payload","x":334.5,"y":40.00000762939453,"wires":[["4e261493.d63a7c"]]},{"id":"ef4c7c2e.fde31","type":"inject","z":"19407975.95b1f7","name":"","topic":"Stoccaggio","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":144.10000610351562,"y":40,"wires":[["d5da8ab.f366678"]]},{"id":"c5c0f24f.dcef","type":"inject","z":"19407975.95b1f7","name":"","topic":"Prelievo","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":133,"y":94.00000381469727,"wires":[["973aae07.d2f32"]]},{"id":"514f00f8.35e8c","type":"inject","z":"19407975.95b1f7","name":"","topic":"Alimentazione","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"onceDelay":0.1,"x":149,"y":138.0000057220459,"wires":[["afd3aed3.9cf2c"]]},{"id":"973aae07.d2f32","type":"random","z":"19407975.95b1f7","name":"","low":"1","high":"1000","inte":"true","property":"payload","x":332.00000381469727,"y":93.00002861022949,"wires":[["4e261493.d63a7c"]]},{"id":"afd3aed3.9cf2c","type":"random","z":"19407975.95b1f7","name":"","low":"1","high":"1000","inte":"true","property":"payload","x":373.00000762939453,"y":137.6000051498413,"wires":[["4e261493.d63a7c"]]},{"id":"4e261493.d63a7c","type":"join","z":"19407975.95b1f7","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":562.5000114440918,"y":89.00000667572021,"wires":[["9072b336.4e1e9"]]},{"id":"70b8b856.797888","type":"trigger","z":"19407975.95b1f7","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"30","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1374.1000747680664,"y":88.00000190734863,"wires":[["87f3534d.9e49a"]]}]

```

Can I handle this behavior in a different way?  
many thanks again for your help

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [19 December 2018 09:24 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/4 "2018-12-19T09:24:29Z")

</div>

use a switch node to splitpaths based on msg.topic?

---

<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:** [19 December 2018 09:33 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/5 "2018-12-19T09:33:57Z")

</div>

If you have finite amount of topics (3 I see in your flow) then you can use Trigger node for each and combine flows after Trigger nodes.

---

<div class="post-metadata">

**Author:** ![NRIT](https://avatars.discourse-cdn.com/v4/letter/n/b38774/32.png) [@NRIT](https://discourse.nodered.org/u/NRIT)\
**Post date:** [19 December 2018 09:35 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/6 "2018-12-19T09:35:17Z")

</div>

I joined msg.topic before 🙂  
I would like avoid redundancy of similar nodes.  
In fact, if the values are higher than the threshold the behavior is the same, i.e. perfom the http request to the ticket system  
Many thanks

---

<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:** [19 December 2018 09:51 UTC](https://discourse.nodered.org/t/send-http-request-using-delay-node/5950/7 "2018-12-19T09:51:25Z")

</div>

Actually I would separate input from output. With your input values per topic, just store the values somewhere (global or flow) Then add a triger node with the rate you'll need to send out the request. And use it to do the calculations using latest stored input values and send out the request.
