Holding and sending Value in node red

Hello :wave: :wave:,

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

[{"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 :slight_smile:

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.

Thanks for the feedback and advice! Appreciate it

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:

@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.

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.

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

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. :wink:

Good luck.

1 Like

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.

1 Like

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