# This flow is generating interesting files

**URL:** <https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637>\
**Category:** General\
**Created:** [8 February 2021 23:00 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637 "2021-02-08T23:00:16Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [8 February 2021 23:00 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/1 "2021-02-08T23:00:17Z")

</div>

I wrote this flow recently to try and help track my daily computer usage.

The flow:

```auto
[{"id":"39fd3a77.cbb756","type":"group","z":"26262ba1.62dcbc","name":"Uptime","style":{"label":true},"nodes":["ece2d27e.1926e8","4511a9a0.0b2e38","97bdf5b5.57e4c8","611b65a9.71b0f4","ac7fc38f.acb178","1f6371fd.ba4d56","2fa4bddf.cb243a","15466412.7808ac","1644881a.fb9ab","abd001b.e0ee4","fadf9736.69d95","11f8a8d.dd42957","6a30385a.7bb1f","ad90ee9d.430698","8042da6d.3015d"],"x":4204,"y":39,"w":792,"h":242},{"id":"5a81f3be.561bdc","type":"subflow","name":"Time Stamp","info":" **3 outputs. 1 - msg.payload holds the time. 2 - msg.time holds the time in a way to be used for reading time in a log file. 3 - outputs nsg.time in a format usable for file names**","category":"","in":[{"x":80,"y":100,"wires":[{"id":"682ac304.0590d4"}]}],"out":[{"x":640,"y":180,"wires":[{"id":"cf554e88.9fff18","port":0},{"id":"682ac304.0590d4","port":0}]},{"x":640,"y":230,"wires":[{"id":"682ac304.0590d4","port":0},{"id":"3db4df41.634848","port":0}]},{"x":640,"y":280,"wires":[{"id":"e4ca4227.3109c8","port":0},{"id":"682ac304.0590d4","port":0}]}],"env":[],"color":"#FF8888","outputLabels":["For use in log files","msg.time","For filename use"],"icon":"node-red/timer.svg"},{"id":"cf554e88.9fff18","type":"moment","z":"5a81f3be.561bdc","name":"","topic":"","input":"payload","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"YYYY-MM-DD HH:mm:ss","locale":"en_AU","output":"payload","outputType":"msg","outTz":"Australia/Sydney","x":390,"y":180,"wires":[["e4ca4227.3109c8","c810aa73.a5706"]]},{"id":"e4ca4227.3109c8","type":"string","z":"5a81f3be.561bdc","name":"","methods":[{"name":"replaceAll","params":[{"type":"str","value":":"},{"type":"str","value":""}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":440,"y":280,"wires":[[]]},{"id":"c810aa73.a5706","type":"change","z":"5a81f3be.561bdc","name":"TOPIC","rules":[{"t":"move","p":"payload","pt":"msg","to":"time","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":230,"wires":[["3db4df41.634848"]]},{"id":"be4fd533.c9abb","type":"change","z":"5a81f3be.561bdc","name":"Save","rules":[{"t":"set","p":"payload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":140,"wires":[["c7ad4b3c.3a5368"]]},{"id":"3db4df41.634848","type":"change","z":"5a81f3be.561bdc","name":"Get","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":230,"wires":[[]]},{"id":"682ac304.0590d4","type":"switch","z":"5a81f3be.561bdc","name":"check topic","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"TIMESTAMP","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":200,"y":100,"wires":[[],["be4fd533.c9abb"]]},{"id":"c7ad4b3c.3a5368","type":"change","z":"5a81f3be.561bdc","name":"TimeStamp","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":180,"wires":[["cf554e88.9fff18"]]},{"id":"ece2d27e.1926e8","type":"subflow:5a81f3be.561bdc","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","x":4520,"y":150,"wires":[["97bdf5b5.57e4c8"],[],[]]},{"id":"4511a9a0.0b2e38","type":"inject","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"Clock","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":4350,"y":150,"wires":[["611b65a9.71b0f4","ece2d27e.1926e8"]]},{"id":"97bdf5b5.57e4c8","type":"gate","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":4690,"y":120,"wires":[["ac7fc38f.acb178"]]},{"id":"611b65a9.71b0f4","type":"exec","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","command":"uptime -p","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":4510,"y":100,"wires":[["2fa4bddf.cb243a"],[],[]]},{"id":"ac7fc38f.acb178","type":"function","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","func":"msg.payload = flow.get(\"Uptime\") + \"Last alive \" + msg.payload;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":4805,"y":120,"wires":[["15466412.7808ac","1644881a.fb9ab","8042da6d.3015d"]],"l":false},{"id":"1f6371fd.ba4d56","type":"function","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"set","func":"msg.payload = \"open\";\nmsg.topic = \"control\";\nreturn msg;","outputs":1,"noerr":0,"x":4690,"y":160,"wires":[["97bdf5b5.57e4c8"]]},{"id":"2fa4bddf.cb243a","type":"change","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"Uptime","rules":[{"t":"set","p":"Uptime","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":4700,"y":80,"wires":[[]]},{"id":"15466412.7808ac","type":"file","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"Alive","filename":"/home/me/.node-red/public/uptime.txt","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":4900,"y":120,"wires":[[]]},{"id":"1644881a.fb9ab","type":"debug","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"Uptime","active":false,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":4850,"y":160,"wires":[]},{"id":"abd001b.e0ee4","type":"delay","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":4700,"y":200,"wires":[["1f6371fd.ba4d56"]]},{"id":"fadf9736.69d95","type":"subflow:5a81f3be.561bdc","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","x":4520,"y":200,"wires":[[],["abd001b.e0ee4"],["11f8a8d.dd42957"]]},{"id":"11f8a8d.dd42957","type":"function","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"build msg","func":"msg.spath = \"/home/me/.node-red/public/\";\nmsg.dpath = \"/home/me/.node-red/public/history/\";\n\nmsg.payload = \"Powered on at \" + msg.payload + \".db\";\nnode.status(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":4700,"y":240,"wires":[["ad90ee9d.430698"]]},{"id":"6a30385a.7bb1f","type":"inject","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"Boot detector","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"BOOT SIGNAL","payloadType":"str","x":4330,"y":200,"wires":[["fadf9736.69d95"]]},{"id":"ad90ee9d.430698","type":"fs-ops-move","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","sourcePath":"spath","sourcePathType":"msg","sourceFilename":"uptime.txt","sourceFilenameType":"str","destPath":"dpath","destPathType":"msg","destFilename":"payload","destFilenameType":"msg","link":false,"x":4850,"y":240,"wires":[[]]},{"id":"8042da6d.3015d","type":"mqtt out","z":"26262ba1.62dcbc","g":"39fd3a77.cbb756","name":"","topic":"uptime/txt","qos":"","retain":"","broker":"378c0403.8cda04","x":4910,"y":80,"wires":[]},{"id":"378c0403.8cda04","type":"mqtt-broker","name":"TIMEPI MQTT","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"true","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

No foreign nodes, but a sub-flow I wrote included.

Basically it does this:  
Boot: rename and move current file to `(existing path)/history`  
and rename it to one of my weird filenames. (Not really that weird)

`MQTT` listens in and a `python` script shows me on the screen the usage for THIS time.

Ok. No problem/s yet.

But!

Today is 9 Feb. This is the only time I have turned on the machine. (First/only session for today)

Looking in the directory (`history`) I see this:

 ![Screenshot from 2021-02-09 09-46-49](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/5/0569136f0df18b5f8eed53e91ecb30592811cf3a.png)

How (semi rhetorical) were those files made?

I get that today when I turned it on, yesterday's "log" would be renamed to "Powerd on at...." with today's timestamp.

That explaines one of the two files.

06:48 is about the time I powered on the machine.  
But it hasn't been turned off since then.  
Note I did say ABOUT. 07:40 is also possible.

This is what a screen shot of the flow shows me which is why I changed the original claim of 06:xx to 07:xx

 ![Screenshot from 2021-02-09 09-48-47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d0df713084ec29f59d508f99649449f3e750313.png)

DIgging a bit deeper, these are the file contents:

```auto
me@me-desktop:~/.node-red/public/history$ cat Powered\ on\ at\ 2021-02-09\ 064813.db 
up 1 hour, 3 minutes
Last alive 2021-02-08 22:55:30
me@me-desktop:~/.node-red/public/history$ cat Powered\ on\ at\ 2021-02-09\ 074737.db 
up 58 minutes
Last alive 2021-02-09 07:47:11
me@me-desktop:~/.node-red/public/history$ cd ..
me@me-desktop:~/.node-red/public$ cat uptime.txt 
up 3 hours, 3 minutes
Last alive 2021-02-09 09:52:35
me@me-desktop:~/.node-red/public$ 

```

So `uptime.txt` us the current session.  
Uptime 3:03. So that means it started .... `09:54 - 3:03 = 06:51`

Which doesn't tie in with the flow's "powered on at" time.  
It says `07:47`  
The `uptime` does match. The `2:54` and 3:03` is only 9 minutes and that would have passed as I was looking at things and posting.

Low priority.  
But it just seems confusing how the second file got created with todays' date if I haven't tured off the machine today since I turned it on.

# Update:

The flow I posted is in a **group**. Shame on me for not reading all the stuff on groups.

But it would appear that the `inject` node set to inject on boot is triggered every time I DEPLOY something on any flow on the machine.

Errrr....... Is that what should happen?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 February 2021 23:19 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/2 "2021-02-08T23:19:14Z")

</div>

If the `inject` node is set to run at an interval, yes it will run when you deploy.

---

<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:** [8 February 2021 23:22 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/3 "2021-02-08T23:22:00Z")

</div>

Only at boot.

And I have deployed OTHER parts of other flows on the machine.

But it seems (note: seems) to be that it is triggered with `deploy` also.

ARGH!

I added this because I was doing something just below the `group` and when I deployed I could have sworn I saw the "last booted at" time change.

It did because I have these screen shots.

 ![Screenshot from 2021-02-09 09-48-47](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/d/8d0df713084ec29f59d508f99649449f3e750313.png)

07:47:37

 ![Screenshot from 2021-02-09 10-17-34](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27e7033d5b079ce0e03bd5d1dad928a6ca4a1ef3.png)

Now, I know you are going to say: "But you added nodes in the group."

Alas I wasn't smart enough to take a shot before I did that.

But it did change.

# And now: typically

When I try: It doesn't.

The _Gremlins_ don't like me and are taunting me.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 February 2021 09:58 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/4 "2021-02-09T09:58:34Z")

</div>

> [@Trying\_to\_learn](#):
>
> But it seems (note: seems) to be that it is triggered with `deploy` also.

Are you doing a full or partial deploy?

---

<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:** [9 February 2021 10:08 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/5 "2021-02-09T10:08:26Z")

</div>

Partial / changed nodes.

Full deploys aren't _needed_ for what I usually do.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 February 2021 10:28 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/6 "2021-02-09T10:28:10Z")

</div>

In that case inject nodes set to fire on startup should not inject when you deploy.

---

<div class="post-metadata">

**Author:** ![kuema](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kuema/32/6542_2.png) [@kuema](https://discourse.nodered.org/u/kuema)\
**Post date:** [9 February 2021 11:44 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/7 "2021-02-09T11:44:27Z")

</div>

Tricky one. I noticed this myself when using groups with the inject node (also "trigger once at start") and some custom nodes that do register/deregister stuff on deploy, even if I didn't touch them at all.

Note: I always use the least disruptive deploy mode "Modified Nodes".

It seems, some changes to groups trigger a redeploy (thus reinitialization) of the nodes within.

Things I observed so far:

Redeploy **does** happen, if you:

- add/remove a node to a group
- move a node within a group that changes the group's size as result
- change the group's visual properties (name, colors, etc...)

Redeploy **does NOT** happen, if you:

- move a node within a group that doesn't change the group's size
- add/delete wires

As a result, nodes de-register and re-register themselves, and even the context of (untouched) function nodes gets cleared. Those unexpected redeploys of unchanged nodes makes some use-cases harder when modifying running systems, especially when you explicitly rely on "Modified Nodes" only. 😅

Is this intended behaviour? Maybe @knolleary has some insights? 🙂

---

<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:** [9 February 2021 20:35 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/8 "2021-02-09T20:35:06Z")

</div>

Ooops.

That's what I meant.

 ![Screenshot from 2021-02-10 07-33-15](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/c/2c5895a9a36471aa4a3b6d16682f5c6394044455.png)

---

<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:** [9 February 2021 20:35 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/9 "2021-02-09T20:35:27Z")

</div>

Thanks.

I'll keep those things in mind.

---

<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:** [10 April 2021 20:35 UTC](https://discourse.nodered.org/t/this-flow-is-generating-interesting-files/40637/10 "2021-04-10T20:35:44Z")

</div>

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