Hmmm. This was exactly the reason for my long nights sitting in front of the screen pulling my hair out
I didnāt understand, the code you are suggesting,
global.set(msg.topic, {"payload" : msg.payload});
is overwriting (re-instantiating) a global variable COMPLETELY. It is not changing property values as I intended.
It means ALL other values stored in the global variable properties are LOST. See the example below:
[{"id":"cd8f21e1.31158","type":"function","z":"5085dcc5.5bf8dc","name":"set globals (obedXX)","func":"// rybarska mista bez chaticek\nvar r1='<left> <font size=\"4\">';\nvar r2='<img src=\"/verejne/icons/misc/man-fishing.png\" height=\"42\" width=\"42\"> </font></left>';\n\n// rybarska mista s chatickou\nvar c1='<left> <font size=\"4\">';\nvar c2='<img src=\"/verejne/icons/misc/NicePng_house-icon-png_147010.png\" height=\"36\" width=\"36\"> </font></left>';\n\n// rybarska mista bez chaticek\nglobal.set(\"obed03\",{payload:{template:r1+3+r2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed04\",{payload:{template:r1+4+r2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed05\",{payload:{template:r1+5+r2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed10\",{payload:{template:r1+1+r2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed11\",{payload:{template:r1+11+r2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\n\n// rybarska mista s chatickou\nglobal.set(\"obed06\",{payload:{template:c1+6+c2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed07\",{payload:{template:c1+7+c2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed08\",{payload:{template:c1+8+c2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed09\",{payload:{template:c1+9+c2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nglobal.set(\"obed12\",{payload:{template:c1+12+c2, Total:0, Today:0, Yesterday:0, POWER:0, enabled:false}});\nnode.warn(global.get(\"obed03\"));\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":260,"wires":[["34a238ea.41b6b","c0b37f64.08f49","ff0c7997.cf8a7"]]},{"id":"5fa35193.735a4","type":"function","z":"5085dcc5.5bf8dc","name":"new dynamic","func":"\nglobal.set(msg.topic + \".payload.Total\", msg.payload.Total);\nglobal.set(msg.topic + \".payload.Today\", msg.payload.Today);\nglobal.set(msg.topic + \".payload.Yesterday\", msg.payload.Yesterday);\nnode.warn(global.get(msg.topic));\n\n\n","outputs":1,"noerr":0,"x":810,"y":300,"wires":[[]]},{"id":"b7327526.7024e8","type":"inject","z":"5085dcc5.5bf8dc","name":"","topic":"","payload":"{}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":260,"wires":[["cd8f21e1.31158"]]},{"id":"34a238ea.41b6b","type":"change","z":"5085dcc5.5bf8dc","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"obed04","tot":"str"},{"t":"set","p":"payload.Total","pt":"msg","to":"3","tot":"num"},{"t":"set","p":"payload.Today","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"payload.Yesterday","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":300,"wires":[["5fa35193.735a4"]]},{"id":"c0b37f64.08f49","type":"change","z":"5085dcc5.5bf8dc","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"obed03","tot":"str"},{"t":"set","p":"payload.Total","pt":"msg","to":"400","tot":"num"},{"t":"set","p":"payload.Today","pt":"msg","to":"400","tot":"num"},{"t":"set","p":"payload.Yesterday","pt":"msg","to":"400","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":240,"wires":[["c6b857e2.37efa"]]},{"id":"c6b857e2.37efa","type":"function","z":"5085dcc5.5bf8dc","name":"old static original","func":"var total =300;\nvar today = 300;\nvar yesterday = 300;\nvar obed = global.get(\"obed03\"); \n obed.payload.Total=total;\n obed.payload.Today=today;\n obed.payload.Yesterday=yesterday;\n global.set(\"obed03\",obed);\nnode.warn(global.get(\"obed03\"));\n\n","outputs":1,"noerr":0,"x":820,"y":240,"wires":[[]]},{"id":"40719069.a4e8e","type":"function","z":"5085dcc5.5bf8dc","name":"Andrei","func":"global.set(msg.topic); // for testing only. Clear the the global property.\n\n//global.set(msg.topic + \".payload.Total\", msg.payload.Total);\n//global.set(msg.topic + \".payload.Today\", msg.payload.Today);\n//global.set(msg.topic + \".payload.Yesterday\", msg.payload.Yesterday);\n\nglobal.set(msg.topic, {\"payload\" : msg.payload});\n\nnode.warn(global.get(msg.topic));\nreturn msg;\n","outputs":1,"noerr":0,"x":790,"y":380,"wires":[[]]},{"id":"ff0c7997.cf8a7","type":"change","z":"5085dcc5.5bf8dc","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"obed05","tot":"str"},{"t":"set","p":"payload.Total","pt":"msg","to":"500","tot":"num"},{"t":"set","p":"payload.Today","pt":"msg","to":"500","tot":"num"},{"t":"set","p":"payload.Yesterday","pt":"msg","to":"500","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":380,"wires":[["40719069.a4e8e"]]}]