Injection of a Node Only Once

I am using Node-Red 3.0.2 and Node.JS v18.14.0x64

I have a Flow that has an Inject every 60 seconds

I have it connect to get some data and one of the points is a Value . Of that value (using a filter) is >= 60 AND <= 100, it starts getting a Temperature that I want every 60 seconds.

I put that in a csv file.

The file name is partially based on the timestamp that is in the format YYYY MM DD.

Again, that all works except it updates every 60 seconds.

I want to create a File Name that is something like "My Temperatures 20230218. csv"

Again not an issue.

The issue is:

How do I read the timestamp in a Function Node only the first time when my status >= 60 ( the status remains at that condition for a long time.)

I have some other functions where I want to "save" and use the information just once.

I want to make the File Name Static and use it in the path of the csv node.

Hi @oakbarn, and welcome to Node-RED forum. I'm not sure if this is optimal but in my case I would use flow variables as flag, may be this example flow can help you.

[{"id":"f6bbb3e2737a229c","type":"tab","label":"Flow 29","disabled":false,"info":"","env":[]},{"id":"a6dc9c324b19b9c6","type":"function","z":"f6bbb3e2737a229c","name":"function 31","func":"var flag = flow.get('flag');\nvar value = msg.payload;\nif(value >= 60)\n{\n    if(flag == true)\n    {\n        flow.set('flag', false);\n        msg.payload = {Time : new Date(), value : msg.payload}\n    }\nreturn msg;\n}else\n{\n    flow.set('flag', true);\n}\n\n","outputs":1,"noerr":0,"initialize":"// Code added here will be run once\n// whenever the node is started.\nflow.set('flag', true);","finalize":"","libs":[],"x":670,"y":320,"wires":[["efeaf15f870a7775"]]},{"id":"efeaf15f870a7775","type":"debug","z":"f6bbb3e2737a229c","name":"debug 72","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":820,"y":320,"wires":[]},{"id":"fb3bab68e9e2c1a7","type":"inject","z":"f6bbb3e2737a229c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"61","payloadType":"num","x":530,"y":300,"wires":[["a6dc9c324b19b9c6"]]},{"id":"38277f466a1a07b9","type":"inject","z":"f6bbb3e2737a229c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"59","payloadType":"num","x":530,"y":340,"wires":[["a6dc9c324b19b9c6"]]}]

Regards.

I looked at you flows and tried flags but did not get it to work, I did solve the issue as I do not neet to inject once, It worked fine and just appended the file. I was following some youtube videos and they lead me to believe I needed to see if the file existed. As it turn out I did not need to as I control the flow with an externally generated number that is created by the program where I am getting the data from.

I would post my solution, but it did not really fix the question, it just made the question immaterial to what I wanted to do. In addition, the flow is very dependent on external data so it would not run on anyone's node red if they did not have the program and hardware where the external data is provided.

Thanks for the help regardless as I had never even heard of flags. I might do something with them in the future.

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