Store a value and reinsert it when flows start

I calculate the cost for my power consumption each hour and I put the different values into a Sum-node. This works fine, but I have noticed that if the flows restart the sum-node is empty. Is it possible to make a function node to store the value and reinsert it into the sum-node if the flows restart?

Have a look here:
https://nodered.org/docs/user-guide/context

Isn't it better to have a look why the flow restarts.

I assumed that @FSHelgeland was referring to normal reboot, deploys etc rather than unexpected restarts. Certainly if it is restarting for unknown reasons then that should be addressed.

1 Like

Colin is absolutely correct, I seldom have to restart my Node Red do to faults or unexpected things. But since I am still pretty new programming and since I am still testing a lot of stuff I do some reebooting and deploys from time to time. And I think it is a good thing to know how to do a memory in Node Red as well.

I understand that i have to uncomment some lines in the settings.js to get to work with context it that correct? And when I try to enter my settings.js it looks like it is read only, at least I can not gett access to it.

What environment? If linux try "sudo nano...."

It is on a raspberry pi. What should I type then? Just sudo nano?

If you did not get that hint, I have to encourage you to read up a bit more on Node-RED and settings.js etc

Trust me, I do.

Find out where you have the settings.js file located

As example in /home/pi/.node-red

So you would type

"sudo nano /home/pi/.node-red/settings.js" and there you go and can make the edits you need

1 Like

Thank you

Will this be correct?

You should NOT need sudo, it could lead to problems.

+1 to that. If you need to use sudo you are probably trying to edit the wrong settings.js.

Here is a topic I wrote (quite awhile ago) that may help you out

1 Like

Getting more and more confused @Colin I just need to uncomment in settings so I am able to use context. Did unable what shown above with sudo nano command but that did not seem to do the trick. But if I try to access the file without the sudo nano command I can not access the file.

Ok,so i finally succed in to do the neccesary changes in settings.js but I now get an error:

10 Jul 19:25:29 - [error] Uncaught Exception:
10 Jul 19:25:29 - [error] Error: listen EADDRINUSE: address already in use 0.0.0.0:1880
at Server.setupListenHandle [as _listen2] (net.js:1331:16)
at listenInCluster (net.js:1379:12)
at doListen (net.js:1516:7)
at processTicksAndRejections (internal/process/task_queues.js:83:21)

Probably due to Home assistant was already using context to file.

Will that be a problem, and what should I do to fix it?

Do you have two instances of Node-RED running?? Port 1880 is used by Node-RED

EDIT: maybe that's why you could not edit settings.js, it is locked by a running instance??. Check with command "ps aux" or "top" and check your running processes

will have a look into that.