Global Context being updated when no global.set executed

I have a function node which will eventually allow Add/Change/Delete capabilities to my device schedules. (it uses the output of the ui_form which we have discussed in another thread regarding UTC 00:00 time).

I've successfully used Global context elsewhere in my project without problem but here I am doing something which I have not attempted before , that is, pushing data onto an an array.

I assign the Global variable to a variable in my function node, the variable is called itemList. The Global variable contains an array of objects defining a schedule event.

I assemble my new object and push it onto the the array itemList

I set msg.payload to itemList and pipe the message to debug.

Nowhere in the function do I set the Global context variable.

The two things I notice are :-

The new object is pushed to the beginning of the array

The Global variable has also been updated

Is this the way I would expect these actions to perform.

OHHHH
and btw

Please can someone tell me how to stop the UI from refreshing wiping out any undeployed changes and all debug evidence while I'm temporarily away writing something like this or researching syntax etc?

I would suggest reading this and providing some more information -

https://discourse.nodered.org/t/note-to-new-forum-members/71295

Hi @Tilerdon

You are hitting a side effect of how JavaScript passes variables around by reference, rather than value.

This recent post explains it in more detail and how to avoid it: Issues with variables - #2 by TotallyInformation

1 Like

You might want to put that in a separate thread - something is wrong somewhere as this is not normal. But we don't have enough info here to be able to help.

Ok here you go @smcgann99

I've created test flows based on the function in which I had my initial problem and after much confusion I'm still confused.

But first I have a few questions which do probably expose some of my lack of understanding of Node RED or Javascript.

I've said it in other forum posts but I'm 74 years old with a background in Programming and Computer languages that precedes 2004. Until less than 18months ago I knew nothing of Javascript and had never heard of Node.js or Node RED and I knew nothing of Objects or JSON,though I had done a little work in Java and C++. Everything I now know I've learned in that time. So please excuse the many holes in my knowledge.

In doing the work to define this problem I had to ask "Well what is a "Flow"? I can see a clear definition of a "Subflow" but if a flow is a Tab in the Node RED editor what do I call these nodes wired together with an Inject at one end and a Debug at the other but several of them, unconnected on the same Editor Tab and isn't Flow context really Tab Context.

And now I have to ask what is Context storage ? I'd thought of it as somewhere outside my function or node where I could hold some data from one node or flow and access it in another. I assumed I had to put my data in that place using a .set() and retrieve it using a .get() and that was the only way I could get it in and out of these places and I assumed that they were discrete. I haven't seen anywhere in discussions on Context that you can't have a Flow context variable with the same name as one in Global but you create yourself a lot of problems in doing so.

I'm running NodeRed as an Integration within Home Assistant this is within VirtualBox on Linux Mint. My everyday UI is on AVG Secure Browser on a Windows 11 Laptop
Screenshot 2022-11-30 191407
Screenshot 2022-11-30 190641

Node RED Integration is Version 13.5.3

The requirement within my project is to maintain an array of objects with Add/Change/Delete functions

My current array is held in Global as Radiators_Today and initially contains 46 elements. My original attempt was

var itemList = global.get("Radiators_Today");
.
.
.
itemList.push(msg1)

but I find that this updates the Global variable without even doing a Global.set which I found most odd. In all my programming experience if you assign the value of a new variable and then manipulate the new variable you don't usually affect the value of the original source.

I decided to see if the same effect occurred using a Flow variable. I added the code to do so, named the Flow context variable the same as the Global one but left the Global variable code in place. I found that when I updated one of the internal variables in the function the other internal variable and the Context variables themselves were also updated.

I created a new Editor Tab with the same Context Variables. When context variables in the first tab were updated the Flow Variable in the other tab was also updated reflecting the change in the Global variable.

[{"id":"0c3ae8ccf53d628d","type":"tab","label":"Test Tab 1","disabled":false,"info":"","env":[]},{"id":"13801a39d9f3c5b6","type":"inject","z":"0c3ae8ccf53d628d","name":"Flow 1 Initialise","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Lounge","payload":"[{\"Id\":\"Backbed\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Backbed\"},{\"Id\":\"Master1\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Master1\"},{\"Id\":\"Master2\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0000Lounge\"},{\"Id\":\"Hall\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Hall\"},{\"Id\":\"Bathroom\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Bathroom\"},{\"Id\":\"Shower\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Shower\"},{\"Id\":\"Lounge\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0000Lounge\"},{\"Id\":\"Lounge\",\"Hour\":7,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":20,\"MinsDevice\":\"0420Lounge\"},{\"Id\":\"Lounge\",\"Hour\":8,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":20,\"MinsDevice\":\"0480Lounge\"},{\"Id\":\"Hall\",\"Hour\":8,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Hall\"},{\"Id\":\"Master1\",\"Hour\":8,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Master1\"},{\"Id\":\"Master2\",\"Hour\":8,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Master2\"},{\"Id\":\"Lounge\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0580Lounge\"},{\"Id\":\"Hall\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0580Hall\"},{\"Id\":\"Kitchen2\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0580Kitchen2\"},{\"Id\":\"Master1\",\"Hour\":9,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0590Master1\"},{\"Id\":\"Master2\",\"Hour\":9,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0590Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":10,\"Min\":10,\"temperature\":22,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0610Kitchen1\"},{\"Id\":\"Kitchen1\",\"Hour\":10,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0640Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":10,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0640Kitchen2\"},{\"Id\":\"Kitchen1\",\"Hour\":14,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0890Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":14,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0890Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":23,\"MinsDevice\":\"0930Lounge\"},{\"Id\":\"Hall\",\"Hour\":15,\"Min\":30,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Hall\"},{\"Id\":\"Bathroom\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Bathroom\"},{\"Id\":\"Shower\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Shower\"},{\"Id\":\"Kitchen1\",\"Hour\":15,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0940Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":15,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0940Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":16,\"Min\":30,\"temperature\":23,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":23,\"MinsDevice\":\"0990Lounge\"},{\"Id\":\"Master1\",\"Hour\":19,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1140Master1\"},{\"Id\":\"Master2\",\"Hour\":19,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1140Master2\"},{\"Id\":\"Master1\",\"Hour\":19,\"Min\":45,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1185Master1\"},{\"Id\":\"Master2\",\"Hour\":19,\"Min\":45,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1185Master2\"},{\"Id\":\"Master1\",\"Hour\":21,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1260Master1\"},{\"Id\":\"Master2\",\"Hour\":21,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1260Master2\"},{\"Id\":\"Master1\",\"Hour\":21,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1290Master1\"},{\"Id\":\"Master2\",\"Hour\":21,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1290Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"1310Lounge\"},{\"Id\":\"Hall\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Hall\"},{\"Id\":\"Bathroom\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Bathroom\"},{\"Id\":\"Shower\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Shower\"}]","payloadType":"json","x":220,"y":100,"wires":[["b1faf85f15f94bbf"]]},{"id":"b1faf85f15f94bbf","type":"change","z":"0c3ae8ccf53d628d","name":"","rules":[{"t":"set","p":"Radiators_Today","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"device","pt":"flow","to":"topic","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"Radiators","tot":"str"},{"t":"set","p":"Radiators_Today","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":100,"wires":[[]]},{"id":"4d4e2b97edd4b775","type":"inject","z":"0c3ae8ccf53d628d","name":"Flow 2 Update Global & Flow","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Start\":\"1970-01-01T11:28:00.000Z\",\"temperature\":20,\"End\":null,\"All\":true,\"Sun\":false,\"Mon\":false,\"Tue\":false,\"Wed\":false,\"Thu\":false,\"Fri\":false,\"Sat\":false}","payloadType":"json","x":260,"y":180,"wires":[["ff773131d635de11"]]},{"id":"ff773131d635de11","type":"function","z":"0c3ae8ccf53d628d","name":"Flow and Global","func":"\nvar hours, minutes, seconds, milliseconds, duration;\nvar inMsg = msg.payload\nvar domain = msg.topic;\nvar id = flow.get(\"device\");\nvar itemList = global.get(\"Radiators_Today\");\nvar itemList2 = flow.get(\"Radiators_Today\");\n\nvar newItemList  = []\nfor (var i =0; i <itemList.length; i++){\n  newItemList[i] = itemList[i]\n}\n\nconst time = new Date(inMsg.Start)\n// this is the number of milliseconds into the day, if needed\n//const msecLocal = time.getTime() - time.getTimezoneOffset() * 60000\nconst hour = time.getHours()\nconst min = time.getMinutes()\nvar msg1 = {}\nmsg1.Id = id;\nmsg1.Hour = hour;\nmsg1.Min = min;\nmsg1.temperature = inMsg.temperature\n\nif (inMsg.All == true) {\n  msg1.Sun = true\n  msg1.Mon = true\n  msg1.Tue = true\n  msg1.Wed = true\n  msg1.Thu = true\n  msg1.Fri = true\n  msg1.Sat = true\n} else {\n  msg1.Sun = inMsg.Sun\n  msg1.Mon = inMsg.Mon\n  msg1.Tue = inMsg.Tue\n  msg1.Wed = inMsg.Wed\n  msg1.Thu = inMsg.Thu\n  msg1.Fri = inMsg.Fri\n  msg1.Sat = inMsg.Sat\n\n}\n\nvar mins = hour * 60 + min\nvar Mins = mins.toString()\nmsg1.MinsDevice = Mins.padStart(4, 0) + id;\nitemList.push(msg1)\nitemList2.push(msg1)\nnewItemList.push(msg1)\nnode.warn(itemList)\nnode.warn(itemList2)\nnode.warn(newItemList)\nmsg.payload = itemList\nnode.send([msg,null,null])\nmsg.payload = itemList2\nnode.send([null, msg,  null])\n\nmsg.payload = newItemList\nnode.send([null,null,msg])\nreturn \n\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":180,"wires":[["72a4f19679f5c918"],["5b327aa4bbb68493"],["cab83d28a157c020"]]},{"id":"72a4f19679f5c918","type":"debug","z":"0c3ae8ccf53d628d","name":"Global","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":160,"wires":[]},{"id":"5b327aa4bbb68493","type":"debug","z":"0c3ae8ccf53d628d","name":"Flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":200,"wires":[]},{"id":"cab83d28a157c020","type":"debug","z":"0c3ae8ccf53d628d","name":"New Array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":240,"wires":[]},{"id":"56794ccf340dec0e","type":"inject","z":"0c3ae8ccf53d628d","name":"Flow 3 Update Global only","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Start\":\"1970-01-01T11:28:00.000Z\",\"temperature\":20,\"End\":null,\"All\":true,\"Sun\":false,\"Mon\":false,\"Tue\":false,\"Wed\":false,\"Thu\":false,\"Fri\":false,\"Sat\":false}","payloadType":"json","x":270,"y":340,"wires":[["51fae1eade7ec7d6"]]},{"id":"51fae1eade7ec7d6","type":"function","z":"0c3ae8ccf53d628d","name":"Global Only","func":"\nvar hours, minutes, seconds, milliseconds, duration;\nvar inMsg = msg.payload\nvar domain = msg.topic;\nvar id = flow.get(\"device\");\nvar itemList = global.get(\"Radiators_Today\");\nvar itemList2 = flow.get(\"Radiators_Today\");\n\nvar newItemList  = []\nfor (var i =0; i <itemList.length; i++){\n  newItemList[i] = itemList[i]\n}\n\nconst time = new Date(inMsg.Start)\n// this is the number of milliseconds into the day, if needed\n//const msecLocal = time.getTime() - time.getTimezoneOffset() * 60000\nconst hour = time.getHours()\nconst min = time.getMinutes()\nvar msg1 = {}\nmsg1.Id = id;\nmsg1.Hour = hour;\nmsg1.Min = min;\nmsg1.temperature = inMsg.temperature\n\nif (inMsg.All == true) {\n  msg1.Sun = true\n  msg1.Mon = true\n  msg1.Tue = true\n  msg1.Wed = true\n  msg1.Thu = true\n  msg1.Fri = true\n  msg1.Sat = true\n} else {\n  msg1.Sun = inMsg.Sun\n  msg1.Mon = inMsg.Mon\n  msg1.Tue = inMsg.Tue\n  msg1.Wed = inMsg.Wed\n  msg1.Thu = inMsg.Thu\n  msg1.Fri = inMsg.Fri\n  msg1.Sat = inMsg.Sat\n\n}\n\nvar mins = hour * 60 + min\nvar Mins = mins.toString()\nmsg1.MinsDevice = Mins.padStart(4, 0) + id;\nitemList.push(msg1)\n//itemList2.push(msg1)\nnewItemList.push(msg1)\nnode.warn(itemList)\nnode.warn(newItemList)\nmsg.payload = itemList\nnode.send([msg,null,null])\nmsg.payload = newItemList\nnode.send([null,null,msg])\nreturn \n\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":340,"wires":[["6f87c56e41bb4290"],[],["7429c4373afa894c"]]},{"id":"6f87c56e41bb4290","type":"debug","z":"0c3ae8ccf53d628d","name":"Global","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":340,"wires":[]},{"id":"c8f737bd98a45d30","type":"debug","z":"0c3ae8ccf53d628d","name":"debug 53","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":380,"wires":[]},{"id":"7429c4373afa894c","type":"debug","z":"0c3ae8ccf53d628d","name":"New Array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":420,"wires":[]}]

continued.....

.... continuation

[{"id":"d5fb0a9d6e5c0e0d","type":"tab","label":"Test Tab 2","disabled":false,"info":"","env":[]},{"id":"4207d50747c9d44b","type":"inject","z":"d5fb0a9d6e5c0e0d","name":"Flow 5 Update Global and Flow","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"Start\":\"1970-01-01T11:28:00.000Z\",\"temperature\":20,\"End\":null,\"All\":true,\"Sun\":false,\"Mon\":false,\"Tue\":false,\"Wed\":false,\"Thu\":false,\"Fri\":false,\"Sat\":false}","payloadType":"json","x":250,"y":220,"wires":[["ac0a18d6e89d815e"]]},{"id":"ac0a18d6e89d815e","type":"function","z":"d5fb0a9d6e5c0e0d","name":"Flow and Global","func":"\nvar hours, minutes, seconds, milliseconds, duration;\nvar inMsg = msg.payload\nvar domain = msg.topic;\nvar id = flow.get(\"device\");\nvar itemList = global.get(\"Radiators_Today\");\nvar itemList2 = flow.get(\"Radiators_Today\");\n\nvar newItemList  = []\nfor (var i =0; i <itemList.length; i++){\n  newItemList[i] = itemList[i]\n}\n\nconst time = new Date(inMsg.Start)\n// this is the number of milliseconds into the day, if needed\n//const msecLocal = time.getTime() - time.getTimezoneOffset() * 60000\nconst hour = time.getHours()\nconst min = time.getMinutes()\nvar msg1 = {}\nmsg1.Id = id;\nmsg1.Hour = hour;\nmsg1.Min = min;\nmsg1.temperature = inMsg.temperature\n\nif (inMsg.All == true) {\n  msg1.Sun = true\n  msg1.Mon = true\n  msg1.Tue = true\n  msg1.Wed = true\n  msg1.Thu = true\n  msg1.Fri = true\n  msg1.Sat = true\n} else {\n  msg1.Sun = inMsg.Sun\n  msg1.Mon = inMsg.Mon\n  msg1.Tue = inMsg.Tue\n  msg1.Wed = inMsg.Wed\n  msg1.Thu = inMsg.Thu\n  msg1.Fri = inMsg.Fri\n  msg1.Sat = inMsg.Sat\n\n}\n\nvar mins = hour * 60 + min\nvar Mins = mins.toString()\nmsg1.MinsDevice = Mins.padStart(4, 0) + id;\nitemList.push(msg1)\nitemList2.push(msg1)\nnewItemList.push(msg1)\nnode.warn(itemList)\nnode.warn(newItemList)\nmsg.payload = itemList\nnode.send([msg,null,null])\nmsg.payload = itemList2\nnode.send([null, msg, null])\nmsg.payload = newItemList\nnode.send([null,null,msg])\nreturn \n\n\n","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":220,"wires":[["61963afcde34f910"],["d512f9d242004258"],["37936b051bfae1cf"]]},{"id":"61963afcde34f910","type":"debug","z":"d5fb0a9d6e5c0e0d","name":"Global","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":200,"wires":[]},{"id":"d512f9d242004258","type":"debug","z":"d5fb0a9d6e5c0e0d","name":"Flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":240,"wires":[]},{"id":"37936b051bfae1cf","type":"debug","z":"d5fb0a9d6e5c0e0d","name":"New Array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":280,"wires":[]},{"id":"848908d26512b481","type":"inject","z":"d5fb0a9d6e5c0e0d","name":"Flow 4 Initialise","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Lounge","payload":"[{\"Id\":\"Backbed\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Backbed\"},{\"Id\":\"Master1\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Master1\"},{\"Id\":\"Master2\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0000Lounge\"},{\"Id\":\"Hall\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Hall\"},{\"Id\":\"Bathroom\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Bathroom\"},{\"Id\":\"Shower\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0000Shower\"},{\"Id\":\"Lounge\",\"Hour\":0,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0000Lounge\"},{\"Id\":\"Lounge\",\"Hour\":7,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":20,\"MinsDevice\":\"0420Lounge\"},{\"Id\":\"Lounge\",\"Hour\":8,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":20,\"MinsDevice\":\"0480Lounge\"},{\"Id\":\"Hall\",\"Hour\":8,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Hall\"},{\"Id\":\"Master1\",\"Hour\":8,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Master1\"},{\"Id\":\"Master2\",\"Hour\":8,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0480Master2\"},{\"Id\":\"Lounge\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"0580Lounge\"},{\"Id\":\"Hall\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0580Hall\"},{\"Id\":\"Kitchen2\",\"Hour\":9,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0580Kitchen2\"},{\"Id\":\"Master1\",\"Hour\":9,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0590Master1\"},{\"Id\":\"Master2\",\"Hour\":9,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0590Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":10,\"Min\":10,\"temperature\":22,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0610Kitchen1\"},{\"Id\":\"Kitchen1\",\"Hour\":10,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0640Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":10,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0640Kitchen2\"},{\"Id\":\"Kitchen1\",\"Hour\":14,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0890Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":14,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0890Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":23,\"MinsDevice\":\"0930Lounge\"},{\"Id\":\"Hall\",\"Hour\":15,\"Min\":30,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Hall\"},{\"Id\":\"Bathroom\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Bathroom\"},{\"Id\":\"Shower\",\"Hour\":15,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0930Shower\"},{\"Id\":\"Kitchen1\",\"Hour\":15,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0940Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":15,\"Min\":40,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"0940Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":16,\"Min\":30,\"temperature\":23,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":23,\"MinsDevice\":\"0990Lounge\"},{\"Id\":\"Master1\",\"Hour\":19,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1140Master1\"},{\"Id\":\"Master2\",\"Hour\":19,\"Min\":0,\"temperature\":20,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1140Master2\"},{\"Id\":\"Master1\",\"Hour\":19,\"Min\":45,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1185Master1\"},{\"Id\":\"Master2\",\"Hour\":19,\"Min\":45,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1185Master2\"},{\"Id\":\"Master1\",\"Hour\":21,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1260Master1\"},{\"Id\":\"Master2\",\"Hour\":21,\"Min\":0,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1260Master2\"},{\"Id\":\"Master1\",\"Hour\":21,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1290Master1\"},{\"Id\":\"Master2\",\"Hour\":21,\"Min\":30,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1290Master2\"},{\"Id\":\"Kitchen1\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Kitchen1\"},{\"Id\":\"Kitchen2\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Kitchen2\"},{\"Id\":\"Lounge\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"RoomTemp\":0,\"MinsDevice\":\"1310Lounge\"},{\"Id\":\"Hall\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Hall\"},{\"Id\":\"Bathroom\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Bathroom\"},{\"Id\":\"Shower\",\"Hour\":21,\"Min\":50,\"temperature\":0,\"Sun\":\"yes\",\"Mon\":\"yes\",\"Tue\":\"yes\",\"Wed\":\"yes\",\"Thu\":\"yes\",\"Fri\":\"yes\",\"Sat\":\"yes\",\"MinsDevice\":\"1310Shower\"}]","payloadType":"json","x":200,"y":140,"wires":[["7c113540983ff05e"]]},{"id":"7c113540983ff05e","type":"change","z":"d5fb0a9d6e5c0e0d","name":"","rules":[{"t":"set","p":"Radiators_Today","pt":"global","to":"payload","tot":"msg"},{"t":"set","p":"device","pt":"flow","to":"topic","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"Radiators","tot":"str"},{"t":"set","p":"Radiators_Today","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":140,"wires":[[]]}]

Flows 1 and 4 Initialise the data in the two tabs. There appears to be a difference in which the other flows operate depending on whether 1 is run before 4 or vice versa

You are correct, the word Flow is too overloaded and has multiple meanings. It is difficult to change these things after they become entrenched though. You are correct, Flow Context is using the word flow to mean an editor tab. Unfortunately the word tab is also overloaded as when talking about the dashboard it may be talking about a dashboard tab rather than an editor tab.

Correct again, you can use the same name in different context spaces and they will be referring to different data.

Right again, if the item in context is an object (or array). In javascript, (as in some other languages or in particular contexts) objects are accessed by reference. It is much the same as using pointers in C. So when you do a Global.get() you are effectively getting a pointer to the object, so any changes you make are to the original object. Note that you should still do Global.set() as if the context is not using the default 'in memory' storage then it may be necessary. The built in persistent context using files uses the set() to know that it is necessary to flush the data out to disc.

If you want to make a temporary copy of the object then you can use RED.util.cloneMessage(). So you might do
let myCopy = RED.util.cloneMessage(Global.get("data"))

Thanks @Colin you really are very helpful.

)`

Well here I resorted to old style programming with

var newItemList =
for (var i = 0; i < itemList.length; i++) {
newItemList[i] = itemList[i]
}
I'm just not really used to having all sorts of functions and methods that I have to search out and then remember how to use

I'm not convinced that this is true @Colin . I done some pretty exhaustive testing using the 2 tabs included in my post above and I don't get entirely consistent results on several passes through them

The two tabs have identical flows to reset the identically named variables in the Flow and Global Contexts of each tab. The first tab has 2 further flows both of which set a 2 variables using a .set one with the Global Context and the other with the Flow Context. The second flow does the same thing but update of the Flow variable is commented out. The flow in the second tab is a copy of the first of the 2 flows in the first tab. Here is a table of the results, both arrays are initialised with 46 elements


All results are taken by viewing Context Data on the Dashboard.

As you can see in the first test, the 2 reset flows are run, Tab 1 then Tab 2 and then the other flows are run in turn , the 2 flows from the first tab and then the flow from the second tab and then the 2 flows from the first tab again. I've highlighted where the Flow variable in the second tab is updated by flows running in the first tab, even when the Flow variable in the first tab is itself not updated as in Sequence line 4.
When the first test was performed the first of the 2 flows in the first tab added one element to each of the 3(4 when viewed separately in the 2 tabs) arrays but in the second test where only the variables in the first Tab were reset, that same flow added 2 elements to of its own variables but it did not affect the Flow variable in Tab 2

In the third test I reversed the order in which I ran the two reset flows and ran that in Tab2 first. This again changed the way the flows acted and only Sequence Line 15 which was run in Tab 2 actually updated the Flow variable in Tab 2 but it did also update the Flow variable in Tab 1.

In the course of testing I did find I had recorded different results at some stages on different passes. I've put these down to me own errors but I'm not totally convinced that is true.

However, I do believe that these results do indicate that something may be wrong

That will only work for an array of course, and won't work if the array element contains an object. or another array, or the array is 2D.

Construct simple flow that shows that what I suggest is not correct and post it here please. Then we can test it.

Could this be related to the possibility of the function node sandbox creating its own persistent context? We obviously need a simple example.

@colin the flows are already posted in posts 5 for Tab1 and 6 for Tab2

The "issue" discussed here derives from the situation that all the flows generated are manipulating one (1) array of objects (!). Let's name this array devices.

devices is initialized in the Inject node. msg.payload gets assigned a reference to this object.

The journey begins @ the Change nodes:

Both the flow context and the global context get assigned now a copy of the reference to devices. This is known as copy by reference (as @knolleary already explained) and does not create new objects. Think of it like copying a pointer to an object in C. You assign a pointer to a new variable - yet it's still pointing to the same structure.

It continues in the Function nodes:

var itemList = global.get("Radiators_Today");
var itemList2 = flow.get("Radiators_Today");

itemList & itemList2 now both hold a reference to the same object, to devices.

Let's introduce newItemList:

newItemList is a new array object. :+1:
newItemList[i] = itemList[i] yet copies references of the objects in devices into newItemList.

Let's continue in the Function node:

itemList.push(msg1)
itemList2.push(msg1)
newItemList.push(msg1)

In this section a new object (msg1) is pushed first to itemList, then to itemList2 - increasing the length of devices - and thus the length of itemList === itemList2 - by two (!) items - and finally to newItemList, increasing its length by one item.

Of course msg1 is attached to the end of the array. Personal comment: This would have been much easier to catch if the example wouldn't play around with an array of 46 (!) objects.

Additional remark: As all those additional indexes reference the same object, manipulating this (single) object will be visible in all three arrays!

Finally our three arrays are send to the different outputs - giving the expected result: The first two showing a length of +2, the third of +1:

You additionally raised the question if flow context can be manipulated across flows. It can - but it is not in your examples. To test this, I propose to

  • reduce the number of objects within Flow 1 @ Test Tab 1 to e.g. 2 & keep Flow 4 @ Test Tab 2 as it is (46).
  • Press the button to Inject @ Flow 4.
  • Press the button to Inject @ Flow 1.
  • Press the button to Inject @ Flow 5.

You should get sth like this (I've added a debug node to Flow 1 & Flow 4):

  • Debug#1: Flow 4 injects the 46 item array to global & to (flow local) flow.
  • Debug#2: Flow 1 injects the 2 item array to global (overwriting the 46 item array) & to (flow local) flow.
  • Debug#3: Flow 5 now operates on the 2 item global, adding 1 item; length === 3.
  • Debug#4: Flow 5 operates on the 46 item (flow local) flow, adding 1 item; length === 47.
  • Debug#5: Flow 5 copied global (length === 2) to newItemList, adding 1 item; length === 3.

Summary: It's all about managing objects in Javascript.

1 Like

Thanks @ralphwetzel that is very helpful to my understanding of the problem.

My original post on this subject, because of my lack of the understanding of the pointer references. I asked what I thought was a simple question that could have been answered quite easily by many. But I was challenged to give more information and examples.

In doing so I've spent 2 days not working on my own project but creating and running these example flows and complicating them in the process of finding out what was happening. I don't need the Flow Context variables for my own purpose and just included them to test out a variation. My own project was already proceeding with the new item array that I had created with the For loop

Consider the effort those people invested trying to support you - which starts with identifying the essence of the issue first. Good to read that there's a better understanding now. Enjoy the next steps of your journey with Node-RED ..

I am not sure what question that was and where you asked it. Can you clarify please? I am surprised that a simple question was not answered.

We fully appreciate that things can get very complex, very quickly and the apparent simplicity of Node-RED can quickly move into complexity. This is one of the most approachable and friendly forums on the Internet with lots of people willing to help.

However, quickly checking back over the thread, I can see that answers to the original questions were quickly given but then more questions came in which were more complex to answer.

Please to remember that while you are working on your project, those people providing help to this forum cannot work on theirs.

Node-RED is a very complex tool. It takes on a lot of complexity internally so that we can all enjoy creating "applications" more easily. But it is still a general-purpose computing tool with the ability to do just about anything in any number of different ways. Complexity is inevitable in some tasks.

@Colin it was in post that started this thread

In hindsight I think the object being pushed to the beginning of the array was a red herring and may have been caused by a coding error and subsequently went away. I did however feel that the first response I received was a slap on the wrist for being a newbie to the forum and not following the rules. So I followed the route which I took trying to investigate the effects I was getting. In my own project, I have no need of both the Global and Flow variables with the same name and had only included them in my example flows in pursuit of an answer.

I now have a better understanding of the pointer principle. In most of the historic languages I have used the Global variable containing an array of objects is analogous to a file (mine only has 46 elements or records in old terms) but I can now see that could be many thousands and far too many to hold within a program/function variable. Those old programming languages jealously guarded the variable to which a file was opened and subsequently read and written to and the fact that Javascript just uses it like any other variable is what caused my confusion. As I said earlier in my posts I am of an age and get confused more easily these days.

I do really appreciate your help and think Node RED is a fantastic product without which I don't believe I could even have skimmed the borders of the application which I have created

JavaScript was actually thrown together in a hurry at the start of the Internet age. The author never really expected that it would become so central to the modern world! :rofl:

It was designed to be open which is why there is no type-checking and context separation was very limited to begin with. Only later (much later) were firstly var and then later still let/const introduced in order to let people get more control over variable isolation. Like most languages, just because you can doesn't mean you should (remember calculated goto's in other languages!).

So you may be surprised just how large a variable you can hold in memory. For example, on my live home automation system, Node-RED holds a number of globals persistently. A quick check of the data on disk shows that they come to around 2GB in size. One object alone has over 15,000 entries in it.

Of course, this depends on the device you are running on.

And I've just been reminded that maybe I need to tidy up that particular variable!! It contains daily npm stats for all of my node-red nodes.

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