# Holding and sending Value in node red

**URL:** <https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875>\
**Category:** General\
**Created:** [25 August 2022 01:57 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875 "2022-08-25T01:57:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [25 August 2022 01:57 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/1 "2022-08-25T01:57:28Z")

</div>

Hello 👋 👋,

For my flow , the value would be constantly injected and send it to a database but when the timer hits a certain timing eg,7pm , it resets the value and gives me a 0 which then sends it to my database , which is not the desired outcome , so is there a way where maybe using the hold node , [Hold Node](https://flows.nodered.org/node/node-red-contrib-hold) or any other methods , can i hold the last value before it reset to 0 and only after the next day it will then reset the value.

These are some of the nodes i use for this flow, hourglass which counts time and will be using a hold node to hold the value.

This is the flow that i have created :

```auto
[{"id":"ce4d60517b69fe3b","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"ada8889f7b6aa22c","type":"group","z":"ce4d60517b69fe3b","name":"simulated data","style":{"label":true},"nodes":["e75b14322e9af3f5","d65468bc5e6d58ed"],"x":394,"y":199,"w":172,"h":122},{"id":"036b26d4fc52fc1f","type":"debug","z":"ce4d60517b69fe3b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"elapsed.millis","targetType":"msg","statusVal":"elapsed.millis","statusType":"auto","x":1240,"y":260,"wires":[]},{"id":"38272a08bf6fb185","type":"hourglass","z":"ce4d60517b69fe3b","name":"","persistId":"","humanizeLocale":"","x":1025,"y":260,"wires":[["036b26d4fc52fc1f","006b5da052794b95","f62b12f8d7ee1a5f","a882769f15226d0e"]]},{"id":"588f0191164799e7","type":"change","z":"ce4d60517b69fe3b","name":"{command:'reset'}","rules":[{"t":"set","p":"command","pt":"msg","to":"reset","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":755,"y":440,"wires":[["38272a08bf6fb185"]]},{"id":"68281e2c204c263d","type":"function","z":"ce4d60517b69fe3b","name":"","func":"if(msg.payload >= 45){\nmsg.command = msg.payload \nmsg.command = \"start\"\n}\n\nif(msg.payload < 45){\n msg.command = msg.payload\n msg.command = \"stop\"\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":260,"wires":[["38272a08bf6fb185"]]},{"id":"86d4f75a5dc322c7","type":"inject","z":"ce4d60517b69fe3b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":550,"y":475,"wires":[["666334e1efbde1bc"]]},{"id":"666334e1efbde1bc","type":"change","z":"ce4d60517b69fe3b","name":"{command:'status'}","rules":[{"t":"set","p":"command","pt":"msg","to":"status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":755,"y":475,"wires":[["38272a08bf6fb185"]]},{"id":"fc4a527c5b2b8e83","type":"timerswitch","z":"ce4d60517b69fe3b","name":"","ontopic":"","offtopic":"","onpayload":"ON","offpayload":"OFF","disabled":false,"schedules":[{"on_h":"17","on_m":"29","on_s":"00","off_h":"09","off_m":"30","off_s":"00","valid":true}],"x":370,"y":360,"wires":[["5276a034779ea0ed"]]},{"id":"15ebf509e61fdfea","type":"gate","z":"ce4d60517b69fe3b","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":700,"y":260,"wires":[["68281e2c204c263d"]]},{"id":"e554b4b24697170b","type":"change","z":"ce4d60517b69fe3b","name":"{command:'stop'}","rules":[{"t":"set","p":"command","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":755,"y":405,"wires":[["38272a08bf6fb185"]]},{"id":"83cf184fbc9626b4","type":"link out","z":"ce4d60517b69fe3b","name":"","mode":"link","links":["917cc68eb8972d61"],"x":800,"y":360,"wires":[]},{"id":"917cc68eb8972d61","type":"link in","z":"ce4d60517b69fe3b","name":"","links":["83cf184fbc9626b4"],"x":520,"y":155,"wires":[["15ebf509e61fdfea"]]},{"id":"5276a034779ea0ed","type":"function","z":"ce4d60517b69fe3b","name":"","func":"if(msg.payload == \"ON\"){\n msg.payload = 1\n}\n\nif(msg.payload == \"OFF\"){\n msg.payload = 0\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":360,"wires":[["544f2e7abfda573c"]]},{"id":"544f2e7abfda573c","type":"function","z":"ce4d60517b69fe3b","name":"","func":"if(msg.payload == 0){\n msg.payload = \"close\"\n msg.topic = \"control\"\n}\n\nif(msg.payload == 1){\n msg.payload = \"open\"\n msg.topic = \"control\"\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":360,"wires":[["83cf184fbc9626b4","2104ed0789be38a9"]]},{"id":"006b5da052794b95","type":"debug","z":"ce4d60517b69fe3b","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"elapsed.time","targetType":"msg","statusVal":"elapsed","statusType":"auto","x":1240,"y":305,"wires":[]},{"id":"2104ed0789be38a9","type":"switch","z":"ce4d60517b69fe3b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"close","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":560,"y":425,"wires":[["e554b4b24697170b","588f0191164799e7"]]},{"id":"f62b12f8d7ee1a5f","type":"function","z":"ce4d60517b69fe3b","name":"","func":"var a = msg.elapsed.time.seconds\nvar b = msg.elapsed.time.minutes\nvar c = msg.elapsed.time.hours\na = a/3600;\nb = b/60;\nmsg.payload = (a+b+c);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1215,"y":220,"wires":[[]]},{"id":"a882769f15226d0e","type":"function","z":"ce4d60517b69fe3b","name":"","func":"var a = msg.elapsed.time.seconds\nvar b = msg.elapsed.time.minutes\nvar c = msg.elapsed.time.hours\na = a/3600;\nb = b/60;\nmsg.payload = ((a+b+c)/8)*100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1215,"y":185,"wires":[[]]},{"id":"c014b5a350cb7a7e","type":"ui_text_input","z":"ce4d60517b69fe3b","name":"","label":"Good Products","tooltip":"","group":"54c7fdf6c43fcb4c","order":5,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"item1","topicType":"str","x":405,"y":570,"wires":[["e7c4cf6653b4d71c"]]},{"id":"ededb52385288391","type":"ui_text_input","z":"ce4d60517b69fe3b","name":"","label":"Total Products","tooltip":"","group":"54c7fdf6c43fcb4c","order":5,"width":0,"height":0,"passthru":true,"mode":"number","delay":300,"topic":"item2","topicType":"str","x":405,"y":610,"wires":[["e7c4cf6653b4d71c"]]},{"id":"e7c4cf6653b4d71c","type":"join","z":"ce4d60517b69fe3b","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":555,"y":590,"wires":[["8270ddd2560b6969","1b929109cecad236"]]},{"id":"8270ddd2560b6969","type":"function","z":"ce4d60517b69fe3b","name":"msg.payload.item1 / msg.payload.item2","func":"msg.payload = (((msg.payload.item1 / msg.payload.item2)*100).toFixed(2))\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":785,"y":590,"wires":[["5cfe1636021fe406"]]},{"id":"8269305852828c2e","type":"ui_gauge","z":"ce4d60517b69fe3b","name":"","group":"54c7fdf6c43fcb4c","order":4,"width":0,"height":0,"gtype":"gage","title":"Quality","label":"Percent","format":"{{value}}","min":0,"max":"100","colors":["#ff0000","#e6e600","#00ff00"],"seg1":"30","seg2":"70","x":1025,"y":710,"wires":[]},{"id":"1e77b379111c7d98","type":"debug","z":"ce4d60517b69fe3b","name":"debug to check Global Variable","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1095,"y":630,"wires":[]},{"id":"a12d6700160c5c8a","type":"ui_button","z":"ce4d60517b69fe3b","name":"","group":"54c7fdf6c43fcb4c","order":8,"width":0,"height":0,"passthru":false,"label":"Confirm","tooltip":"","color":"","bgcolor":"","icon":"","payload":"Percentage","payloadType":"global","topic":"topic","topicType":"msg","x":825,"y":710,"wires":[["8269305852828c2e","d9345c2b7f677ed5","54469912e74bea7a"]]},{"id":"5cfe1636021fe406","type":"function","z":"ce4d60517b69fe3b","name":"Global Variable","func":"global.set(\"Percentage\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1045,"y":590,"wires":[["1e77b379111c7d98"]]},{"id":"d9345c2b7f677ed5","type":"debug","z":"ce4d60517b69fe3b","name":"debug to check if Global Variable went through","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1145,"y":670,"wires":[]},{"id":"9d72d8b5dafdecba","type":"ui_button","z":"ce4d60517b69fe3b","name":"","group":"54c7fdf6c43fcb4c","order":6,"width":0,"height":0,"passthru":false,"label":"Reset","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"topic","topicType":"msg","x":375,"y":670,"wires":[["f3a2266b198dc492"]]},{"id":"f3a2266b198dc492","type":"function","z":"ce4d60517b69fe3b","name":"Reset Function","func":"if(msg.payload == true){\n msg.payload = 0\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":525,"y":670,"wires":[["d6a7fd70484e38e8"]]},{"id":"d6a7fd70484e38e8","type":"link out","z":"ce4d60517b69fe3b","name":"link out 4","mode":"link","links":["635c4a48af06eea2","d503f6dc2906acab","df2b36059a68e3f8"],"x":660,"y":670,"wires":[]},{"id":"635c4a48af06eea2","type":"link in","z":"ce4d60517b69fe3b","name":"link in 4","links":["d6a7fd70484e38e8"],"x":870,"y":670,"wires":[["8269305852828c2e"]]},{"id":"1b929109cecad236","type":"debug","z":"ce4d60517b69fe3b","name":"debug to check join node","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":735,"y":630,"wires":[]},{"id":"df2b36059a68e3f8","type":"link in","z":"ce4d60517b69fe3b","name":"link in 5","links":["d6a7fd70484e38e8"],"x":265,"y":570,"wires":[["c014b5a350cb7a7e"]]},{"id":"d503f6dc2906acab","type":"link in","z":"ce4d60517b69fe3b","name":"link in 6","links":["d6a7fd70484e38e8"],"x":265,"y":610,"wires":[["ededb52385288391"]]},{"id":"54469912e74bea7a","type":"link out","z":"ce4d60517b69fe3b","name":"link out 6","mode":"link","links":["7c6dfd83274dfbc3","a5bee2297d91e2bf"],"x":950,"y":750,"wires":[]},{"id":"e75b14322e9af3f5","type":"inject","z":"ce4d60517b69fe3b","g":"ada8889f7b6aa22c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"46","payloadType":"num","x":490,"y":240,"wires":[["15ebf509e61fdfea"]]},{"id":"d65468bc5e6d58ed","type":"inject","z":"ce4d60517b69fe3b","g":"ada8889f7b6aa22c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"44","payloadType":"num","x":490,"y":280,"wires":[["15ebf509e61fdfea"]]},{"id":"8204cf1b30883b20","type":"comment","z":"ce4d60517b69fe3b","name":"Sends to Database","info":"","x":1405,"y":180,"wires":[]},{"id":"54c7fdf6c43fcb4c","type":"ui_group","name":"Group 1","tab":"f1dc1ca1.c1457","order":1,"disp":true,"width":6},{"id":"f1dc1ca1.c1457","type":"ui_tab","name":"Text-Button","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

Thank you! and appreciate your guidance 🙂

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 August 2022 03:03 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/2 "2022-08-25T03:03:50Z")

</div>

Hi,

Although what you are asking is valid, I'd just like to say that I _see_ a problem with how you are describing what is happening.  
Not having a go at you, but reading it as I see it, I feel there may be an underlying problem that will come back to bite you later on.

How is this _data stream_ being made? (That stops at eg: 7 PM.)  
To me, that is more important to understand how that is happening.

As `hourglass` is not standard I'm not going to load the flow only because I'm knee deep in re-writing some code from a few years ago to make it better and I am just trying to clear my head.

Hope that is somewhat helpful though.

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [25 August 2022 03:05 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/3 "2022-08-25T03:05:01Z")

</div>

Thanks for the feedback and advice! Appreciate it

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 August 2022 03:07 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/4 "2022-08-25T03:07:19Z")

</div>

Just looked at the `hourglass` node.  
I do suspect that is the problem.

Why can't you use the `inject` node and just have it send out pulses at a regular interval?  
There are other (more popular) nodes like cronplus that could do what you want.

But if it is an ongoing thing that is supposed to simply send/generate messages at a regular interval, the basic (standard) `inject` node would more than suffice.

And I just saw it is more than a year since it was last updated.  
Yeah, try this one:

> **[node-red-contrib-cron-plus](https://flows.nodered.org/node/node-red-contrib-cron-plus)**
>
> A flexible scheduler (cron, solar events, simple dates) node for Node-RED with full dynamic control and Timezone support

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [25 August 2022 03:26 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/5 "2022-08-25T03:26:38Z")

</div>

@Trying_to_learn Thanks for the suggestion, i would explore the cronplus node, also for the inject node, it is used as a simulation for constantly injecting data to my database.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 August 2022 03:28 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/6 "2022-08-25T03:28:35Z")

</div>

Well, honestly I think for that the original `inject` should be all you need.

Towards the bottom of the node there is a `repeat` option and that gives you a lot of options.

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [25 August 2022 03:29 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/7 "2022-08-25T03:29:49Z")

</div>

yeap there is, that allow me to inject data at regular intervals. But thanks!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 August 2022 03:31 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/8 "2022-08-25T03:31:39Z")

</div>

No worries.

Please: The only "dumb question/s" are the ones you don't ask.

I know this from first hand experience. Just ask others. 😉

Good luck.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [25 August 2022 03:36 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/9 "2022-08-25T03:36:50Z")

</div>

Oh, (not for the _points_) if me suggesting the `inject` node _fixed_ the problem, could you mark that are the `solution`.

That helps others if they read your thread who have similar problems and it shows them the solution.

---

<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:** [8 September 2022 03:37 UTC](https://discourse.nodered.org/t/holding-and-sending-value-in-node-red/66875/10 "2022-09-08T03:37:20Z")

</div>

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