Continuing counting after reboot

I wrote the following counter:
it 's start counting from a defined time forward.
I want it to continue the count from the defined time even if my RPI is rebooted.
But after a reboot the initial time is reset to the time the node red server starts.
I'v tried to save the initial time to a file, but it too resets after the node red server starts.

[{"id":"e83e5464.a42138","type":"function","z":"73999274.50082c","name":"[s] to [hh:mm:ss]","func":"\nmsg.timeStart = msg.payload.col1 /1000\n\nvar seconds =( msg.myepoch /1000 +1) -msg.timeStart;\n\nvar days = Math.floor(seconds / (3600*24));\nseconds  -= days*3600*24;\nvar hrs   = Math.floor(seconds / 3600);\nseconds  -= hrs*3600;\nvar mnts = Math.floor(seconds / 60);\nseconds  -=mnts*60;\nconsole.log(days+\" days, \"+hrs+\" Hrs, \"+mnts+\" Minutes, \"+seconds+\" Seconds\");\n\nmsg.payload = (\"0\"+days).slice(-2)+\" days, \"+(\"0\"+hrs).slice(-2)+\" Hrs, \"+(\"0\"+mnts).slice(-2)+\" Minutes, \"+Math.round(seconds)+\" Seconds\";\n//msg.payload = days+\" days, \"+hrs+\" Hrs, \"+mnts+\" Minutes, \"+seconds+\" Seconds\";\n\nreturn msg;","outputs":1,"noerr":0,"x":920,"y":200,"wires":[["7576155f.39db2c","63dcc4ff.7a769c","a9d275b1.0f08c8"]],"info":"counts from a fixed position in time. - timeStart\n"}]

I don't have NR with me so I can't look at your flow. But have you enabled persistent context so flow variables get restored on restart?

I have enable the persistent context,
But when the server finishes the reboot it flushes the current time to my flow.set function and overrides my initial saved time. therefor the timer start counting from 0 (from the current time)

[{"id":"7771cfcd.f701","type":"tab","label":"Flow 14","disabled":false,"info":""},{"id":"1d5d8faa.283c7","type":"debug","z":"7771cfcd.f701","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":300,"wires":[]},{"id":"11cec979.b5e5c7","type":"inject","z":"7771cfcd.f701","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["fb96a9ee.103c38"]]},{"id":"fb96a9ee.103c38","type":"simpletime","z":"7771cfcd.f701","name":"","x":310,"y":300,"wires":[["fbd9195f.cc36f8"]]},{"id":"afab928c.37628","type":"function","z":"7771cfcd.f701","name":"[s] to [hh:mm:ss]","func":"\nvar timeStart = flow.get(\"startTimeMyepoch\") /1000\n\nvar seconds =( msg.myepoch /1000 +msg.count) -timeStart;\n\nvar days = Math.floor(seconds / (3600*24));\nseconds  -= days*3600*24;\nvar hrs   = Math.floor(seconds / 3600);\nseconds  -= hrs*3600;\nvar mnts = Math.floor(seconds / 60);\nseconds  -=mnts*60;\nconsole.log(days+\" days, \"+hrs+\" Hrs, \"+mnts+\" Minutes, \"+seconds+\" Seconds\");\n\nmsg.payload = (\"0\"+days).slice(-2)+\" days, \"+(\"0\"+hrs).slice(-2)+\" Hrs, \"+(\"0\"+mnts).slice(-2)+\" Minutes, \"+Math.round(seconds)+\" Seconds\";\n//msg.payload = days+\" days, \"+hrs+\" Hrs, \"+mnts+\" Minutes, \"+seconds+\" Seconds\";\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":300,"wires":[["1d5d8faa.283c7","e38c85b3.6ebed8"]],"info":"counts from a fixed position in time. - timeStart\n"},{"id":"fbd9195f.cc36f8","type":"counter","z":"7771cfcd.f701","name":"Sec. Counter","init":0,"step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":530,"y":220,"wires":[["afab928c.37628"]]},{"id":"d93db91a.c4f3d8","type":"ui_button","z":"7771cfcd.f701","name":"","group":"d0615552.932c78","order":31,"width":2,"height":1,"passthru":false,"label":"Reset Time","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":110,"y":440,"wires":[["78fcd6b4.b7d288"]]},{"id":"78fcd6b4.b7d288","type":"function","z":"7771cfcd.f701","name":"send reset request","func":"msg.reset = true;\n\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":440,"wires":[["dd7a0ef9.98e94","fbd9195f.cc36f8"]]},{"id":"dd7a0ef9.98e94","type":"trigger","z":"7771cfcd.f701","op1":"","op2":"","op1type":"pay","op2type":"nul","duration":"10","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":570,"y":440,"wires":[["3315b32d.f35d6c"]]},{"id":"3315b32d.f35d6c","type":"function","z":"7771cfcd.f701","name":"Display Start Time","func":"\nmsg.Stime=msg.myday+\" \"+ msg.mydom+ \"/\"+ msg.mymonthn+ \"/\"+ msg.myyear+ \"@\"+ msg.mytimes; \nvar startTimeMyepoch =flow.set(\"startTimeMyepoch\",msg.myepoch);\nvar startTime= flow.set(\"startTime\",msg.Stime);\nmsg.payload=msg.myepoch\nreturn msg;\n\n//var total=flow.set(\"total\", 123);","outputs":1,"noerr":0,"x":750,"y":440,"wires":[["bf8706da.445c48","afab928c.37628","f87d43b2.726d6"]]},{"id":"5b854f6c.7985b","type":"comment","z":"7771cfcd.f701","name":"reset Start Time","info":"","x":120,"y":580,"wires":[]},{"id":"94bd5bf8.c66a68","type":"comment","z":"7771cfcd.f701","name":"Elapsed Time from Current Time","info":"","x":210,"y":260,"wires":[]},{"id":"84a84497.9bc728","type":"comment","z":"7771cfcd.f701","name":"Trigger = Delay until reset request","info":"","x":590,"y":580,"wires":[]},{"id":"4e9feabd.c75c04","type":"simpletime","z":"7771cfcd.f701","name":"","x":310,"y":500,"wires":[["dd7a0ef9.98e94"]]},{"id":"9c1974ac.c16598","type":"inject","z":"7771cfcd.f701","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":500,"wires":[["4e9feabd.c75c04"]]},{"id":"bf8706da.445c48","type":"debug","z":"7771cfcd.f701","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":950,"y":480,"wires":[]},{"id":"f87d43b2.726d6","type":"ui_text","z":"7771cfcd.f701","group":"d0615552.932c78","order":16,"width":0,"height":0,"name":"","label":"text","format":"{{msg.Stime}}","layout":"row-left","x":1060,"y":400,"wires":[]},{"id":"e38c85b3.6ebed8","type":"ui_text","z":"7771cfcd.f701","group":"d0615552.932c78","order":15,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-left","x":880,"y":200,"wires":[]},{"id":"d0615552.932c78","type":"ui_group","z":"","name":"Default","tab":"21ad5df2.558152","disp":true,"width":12,"collapse":false},{"id":"21ad5df2.558152","type":"ui_tab","z":"","name":"Sensors","icon":"dashboard","disabled":false,"hidden":false}]

I can't look at your flow at the moment, but if it is doing something on restart that you don't want then change that bit of the flow so that it does not.

First, there are far better experts than I but let me at least offer a few of my ideas. First, you need to go into the settings.js file and change default save to localfilesystem. Next, you need to set the data to save into the localfilesystem with a statement like - flow.set('variable name',data,'default') - This saves your data to a file on the pi under the name variable name. This will preserve your data through the reboot. Next, when your pi powers up you need to reload the data back into the flow using flow.get. You have to reload the data once on reboot, I use an inject node set to fire once. Make sure the data is saving to the file system and again you have to reload the data on reboot. Your flow looks like a snippet so I can't determine your whole flow but hopefully this points you in the right direction.

Actually, if - in settings.js - you set the default to be the localfilesystem, you don't need the'default' in the statement since (oh gosh this is going to overload the term) the default is the default. You only need the third option in the flow.set if it is somenting other that the default

i'll try to explain my problem again:
when the node red server loads up after a reboot of the RPI, my UI web page is refreshed (automatically) when the node red is up and running, all my saved data (no matter how i save it - flow.get with the persistent context enabled or by saving it to a file with the "file" node) it looks to me like the "deploy" button is pressed or a msg.reset is given and the saved values are override with the servers current time.

Context saved to a file will not automatically be reset by a restart. Either you are not saving it to a file or something in your flow is resetting it.
Make a very simple flow that saves a value to the context using an inject button. Have another inject that gets it from the context and passes it to debug node so you can see it. Click the first inject then the second to make sure it is working. Then restart and click the second one to see if the value is still there

YOu have probably got the logic incorrect

You need to allow for a couple of cases

  1. Flow starts with no values set
  2. Flow starts with values previously set and they need to be used as a starting point

You then need to think about how you handle each of these as well as edge use situations i.e. flow crashes whilst counting - how do you know what is going on ?

So each time you count (whatever it is you are counting) you need to write the updated amount to the filesystem and set a flag in that filesystem to say it is valid

When you startup you need to check the filesystem - is the Valid flag set, if so then read the count and initialise the variable, otherwise, start the count at Zero (or wherever)


thank you.
what i'v done is i starred my flow with a function "is reset = true"
therefor eliminating the node red forced "reset" of the flow.