Instead of many words I hope my drawing will explain, I am almost there (with your help)
On the Button (Toggle - detecting edge) I manually enter a number from 1 to 50.
Each button refers to an output in the plc.
So when I push Button and payload goes true the .topic (Number 1) uses the value in the array 1: 222 and send it to the plc in one scan.
The status for output 1 is in the other array also 1:false.
So red arrows is the config value
blue arrows is the actual state.
[{"id":"1d0d2a4c05bf9850","type":"subflow","name":"Output","info":"","category":"","in":[{"x":200,"y":280,"wires":[{"id":"991cdbd91140358d"},{"id":"7449b6a54bdbc6ee"}]}],"out":[{"x":830,"y":280,"wires":[{"id":"df89f815b849c0e0","port":0}]},{"x":820,"y":360,"wires":[{"id":"d484f1e25b6f11cc","port":0}]},{"x":820,"y":420,"wires":[{"id":"d484f1e25b6f11cc","port":1}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["ButtonConfigState"],"outputLabels":["Order","On","Off"]},{"id":"991cdbd91140358d","type":"trigger","z":"1d0d2a4c05bf9850","name":"Trigger","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"100","extend":false,"overrideDelay":false,"units":"ms","reset":"cd420bc85ebee335","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":280,"wires":[["df89f815b849c0e0"]]},{"id":"d484f1e25b6f11cc","type":"switch","z":"1d0d2a4c05bf9850","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":540,"wires":[[],[]]},{"id":"df89f815b849c0e0","type":"function","z":"1d0d2a4c05bf9850","name":"function 18","func":"let btnIndex = parseInt(msg.topic)\n\nlet lightStatusArr = global.get(\"LightStatus\")\nlet lightConfigArr = global.get(\"LightConfig\")\n\n//Modify your indexes to be from 0 to 49 if necessary\nif (typeof btnIndex === \"number\" && btnIndex >= 1 && btnIndex<=50) {\n if (lightStatusArr[btnIndex-1] === true){\n msg.payload = lightConfigArr[btnIndex-1] \n }\n else msg.payload = 0;\n}\nelse node.warn(\"Unknown topic\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":280,"wires":[[]]},{"id":"7449b6a54bdbc6ee","type":"function","z":"1d0d2a4c05bf9850","name":"function 19","func":"let btnIndex = parseInt(msg.topic)\n\nlet lightStatusArr = global.get(\"LightStatus\")\nlet lightConfigArr = global.get(\"LightConfig\")\n\n//Modify your indexes to be from 0 to 49 if necessary\nif (typeof btnIndex === \"number\" && btnIndex >= 1 && btnIndex<=50) {\n if (lightStatusArr[btnIndex-1] === true){\n msg.payload = lightConfigArr[btnIndex-1] \n }\n else msg.payload = 0;\n}\nelse node.warn(\"Unknown topic\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":400,"wires":[["d484f1e25b6f11cc"]]},{"id":"e63f1cc0a8b69fae","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"4e92c1034122f3b2","type":"s7 out","z":"e63f1cc0a8b69fae","endpoint":"24c121bc8a089078","variable":"Order","name":"Order","x":970,"y":520,"wires":[]},{"id":"46d75c07a9192b13","type":"link in","z":"e63f1cc0a8b69fae","name":"link in 2","links":["84c4ab1cf63880eb","ec385de5f0be49eb","8a0412da6f458528"],"x":795,"y":520,"wires":[["4e92c1034122f3b2"]]},{"id":"262e9bf7773b2e17","type":"server-state-changed","z":"e63f1cc0a8b69fae","name":"Button","server":"2d39e267082bb0e5","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.output_01","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"global","value":"1","valueType":"num"}],"x":170,"y":400,"wires":[["2917584253d561c1"],["2917584253d561c1"]]},{"id":"ec385de5f0be49eb","type":"link out","z":"e63f1cc0a8b69fae","name":"link out 2","mode":"link","links":["7baad5ef49bbadac","46d75c07a9192b13"],"x":495,"y":360,"wires":[]},{"id":"2917584253d561c1","type":"subflow:1d0d2a4c05bf9850","z":"e63f1cc0a8b69fae","name":"","x":350,"y":400,"wires":[["ec385de5f0be49eb"],["67d69ac5a0addbe7"],["d05266e14837d813"]]},{"id":"67d69ac5a0addbe7","type":"api-call-service","z":"e63f1cc0a8b69fae","name":"Output 01 On","server":"2d39e267082bb0e5","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.output_01_status"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":400,"wires":[[]]},{"id":"d05266e14837d813","type":"api-call-service","z":"e63f1cc0a8b69fae","name":"Output 01 Off","server":"2d39e267082bb0e5","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.button_01_status","input_boolean.output_01_status"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":440,"wires":[[]]},{"id":"3980665e97111ff2","type":"debug","z":"e63f1cc0a8b69fae","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":560,"y":140,"wires":[]},{"id":"68f8b82870e9f55e","type":"s7 in","z":"e63f1cc0a8b69fae","endpoint":"c7105b9cf8d353a1","mode":"all","variable":"Single Push Value","diff":true,"name":"Light Status","x":170,"y":140,"wires":[["a6c4755e1841bfae"]]},{"id":"459222043236b8d3","type":"debug","z":"e63f1cc0a8b69fae","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":200,"wires":[]},{"id":"d565e9d330dd4268","type":"comment","z":"e63f1cc0a8b69fae","name":"Read all config and states. Save them in array","info":"","x":370,"y":60,"wires":[]},{"id":"fe91b7fb292e8235","type":"s7 in","z":"e63f1cc0a8b69fae","endpoint":"81d5f9355d319443","mode":"all","variable":"Single Push Value","diff":true,"name":"Light Config","x":170,"y":200,"wires":[["50b8d23f9586c514"]]},{"id":"a6c4755e1841bfae","type":"function","z":"e63f1cc0a8b69fae","name":"Store Status","func":"//Change JSON to Array of values\nlet functions = Object.values(msg.payload)\n\nmsg.payload = functions;\nglobal.set(\"LightStatus\", functions)\n\nreturn msg;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":140,"wires":[["3980665e97111ff2"]]},{"id":"50b8d23f9586c514","type":"function","z":"e63f1cc0a8b69fae","name":"Store Config","func":"//Change JSON to Array of values\nlet functions = Object.values(msg.payload)\n\nmsg.payload = functions;\nglobal.set(\"LightConfig\", functions)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":200,"wires":[["459222043236b8d3"]]},{"id":"108fb680fdffc3a6","type":"server-state-changed","z":"e63f1cc0a8b69fae","name":"Button","server":"2d39e267082bb0e5","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.output_02","entityidfiltertype":"exact","outputinitially":false,"state_type":"habool","haltifstate":"true","halt_if_type":"bool","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"topic","propertyType":"global","value":"2","valueType":"num"}],"x":170,"y":600,"wires":[["0015ada15f99a524"],["0015ada15f99a524"]]},{"id":"8a0412da6f458528","type":"link out","z":"e63f1cc0a8b69fae","name":"link out 3","mode":"link","links":["7baad5ef49bbadac","46d75c07a9192b13"],"x":495,"y":560,"wires":[]},{"id":"0015ada15f99a524","type":"subflow:1d0d2a4c05bf9850","z":"e63f1cc0a8b69fae","name":"","x":350,"y":600,"wires":[["8a0412da6f458528"],["bfe4eec7729990b0"],["12302dfba9f6e9a9"]]},{"id":"bfe4eec7729990b0","type":"api-call-service","z":"e63f1cc0a8b69fae","name":"Output 02 On","server":"2d39e267082bb0e5","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.output_01_status"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":600,"wires":[[]]},{"id":"12302dfba9f6e9a9","type":"api-call-service","z":"e63f1cc0a8b69fae","name":"Output 02 Off","server":"2d39e267082bb0e5","version":5,"debugenabled":true,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.button_01_status","input_boolean.output_01_status"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":640,"wires":[[]]},{"id":"24c121bc8a089078","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.4.106","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapter":"","busaddr":"2","cycletime":"1000","timeout":"2000","name":"Strandly","vartable":[{"addr":"DB12,INT2","name":"Order"}]},{"id":"2d39e267082bb0e5","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":": ","statusYear":"hidden","statusMonth":"hidden","statusDay":"hidden","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":false},{"id":"c7105b9cf8d353a1","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.4.106","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapter":"","busaddr":"2","cycletime":"1000","timeout":"2000","name":"Light Status","vartable":[{"addr":"DB12,X32.0","name":"Output_01"},{"addr":"DB12,X32.1","name":"Output_02"},{"addr":"DB12,X32.2","name":"Output_03"},{"addr":"DB12,X32.3","name":"Output_04"},{"addr":"DB12,X32.4","name":"Output_05"},{"addr":"DB12,X32.5","name":"Output_06"},{"addr":"DB12,X32.6","name":"Output_07"},{"addr":"DB12,X32.7","name":"Output_08"},{"addr":"DB12,X33.0","name":"Output_09"},{"addr":"DB12,X33.1","name":"Output_10"},{"addr":"DB12,X33.2","name":"Output_11"},{"addr":"DB12,X33.3","name":"Output_12"},{"addr":"DB12,X33.4","name":"Output_13"},{"addr":"DB12,X33.5","name":"Output_14"},{"addr":"DB12,X33.6","name":"Output_15"},{"addr":"DB12,X33.7","name":"Output_16"},{"addr":"DB12,X34.0","name":"Output_17"},{"addr":"DB12,X34.1","name":"Output_18"},{"addr":"DB12,X34.2","name":"Output_19"},{"addr":"DB12,X34.3","name":"Output_20"},{"addr":"DB12,X34.4","name":"Output_21"},{"addr":"DB12,X34.5","name":"Output_22"},{"addr":"DB12,X34.6","name":"Output_23"},{"addr":"DB12,X34.7","name":"Output_24"},{"addr":"DB12,X35.0","name":"Output_25"},{"addr":"DB12,X35.1","name":"Output_26"},{"addr":"DB12,X35.2","name":"Output_27"},{"addr":"DB12,X35.3","name":"Output_28"},{"addr":"DB12,X35.4","name":"Output_29"},{"addr":"DB12,X35.5","name":"Output_30"},{"addr":"DB12,X35.6","name":"Output_31"},{"addr":"DB12,X35.7","name":"Output_32"},{"addr":"DB12,X36.0","name":"Output_33"},{"addr":"DB12,X36.1","name":"Output_34"},{"addr":"DB12,X36.2","name":"Output_35"},{"addr":"DB12,X36.3","name":"Output_36"},{"addr":"DB12,X36.4","name":"Output_37"},{"addr":"DB12,X36.5","name":"Output_38"},{"addr":"DB12,X36.6","name":"Output_39"},{"addr":"DB12,X36.7","name":"Output_40"},{"addr":"DB12,X37.0","name":"Output_41"},{"addr":"DB12,X37.1","name":"Output_42"},{"addr":"DB12,X37.2","name":"Output_43"},{"addr":"DB12,X37.3","name":"Output_44"},{"addr":"DB12,X37.4","name":"Output_45"},{"addr":"DB12,X37.5","name":"Output_46"},{"addr":"DB12,X37.6","name":"Output_47"},{"addr":"DB12,X37.7","name":"Output_48"},{"addr":"DB12,X38.0","name":"Output_49"},{"addr":"DB12,X38.1","name":"Output_50"}]},{"id":"81d5f9355d319443","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.4.106","port":"102","rack":"0","slot":"1","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapter":"","busaddr":"2","cycletime":"1000","timeout":"2000","name":"Light Config","vartable":[{"addr":"DB12,INT40","name":"Output_01_Config"},{"addr":"DB12,INT42","name":"Output_02_Config"},{"addr":"DB12,INT44","name":"Output_03_Config"},{"addr":"DB12,INT46","name":"Output_04_Config"},{"addr":"DB12,INT48","name":"Output_05_Config"},{"addr":"DB12,INT50","name":"Output_06_Config"},{"addr":"DB12,INT52","name":"Output_07_Config"},{"addr":"DB12,INT54","name":"Output_08_Config"},{"addr":"DB12,INT56","name":"Output_09_Config"},{"addr":"DB12,INT58","name":"Output_10_Config"},{"addr":"DB12,INT60","name":"Output_11_Config"},{"addr":"DB12,INT62","name":"Output_12_Config"},{"addr":"DB12,INT64","name":"Output_13_Config"},{"addr":"DB12,INT66","name":"Output_14_Config"},{"addr":"DB12,INT68","name":"Output_15_Config"},{"addr":"DB12,INT70","name":"Output_16_Config"},{"addr":"DB12,INT72","name":"Output_17_Config"},{"addr":"DB12,INT74","name":"Output_18_Config"},{"addr":"DB12,INT76","name":"Output_19_Config"},{"addr":"DB12,INT78","name":"Output_20_Config"},{"addr":"DB12,INT80","name":"Output_21_Config"},{"addr":"DB12,INT82","name":"Output_22_Config"},{"addr":"DB12,INT84","name":"Output_23_Config"},{"addr":"DB12,INT86","name":"Output_24_Config"},{"addr":"DB12,INT88","name":"Output_25_Config"},{"addr":"DB12,INT90","name":"Output_26_Config"},{"addr":"DB12,INT92","name":"Output_27_Config"},{"addr":"DB12,INT94","name":"Output_28_Config"},{"addr":"DB12,INT96","name":"Output_29_Config"},{"addr":"DB12,INT98","name":"Output_30_Config"},{"addr":"DB12,INT100","name":"Output_31_Config"},{"addr":"DB12,INT102","name":"Output_32_Config"},{"addr":"DB12,INT104","name":"Output_33_Config"},{"addr":"DB12,INT106","name":"Output_34_Config"},{"addr":"DB12,INT108","name":"Output_35_Config"},{"addr":"DB12,INT110","name":"Output_36_Config"},{"addr":"DB12,INT112","name":"Output_37_Config"},{"addr":"DB12,INT114","name":"Output_38_Config"},{"addr":"DB12,INT116","name":"Output_39_Config"},{"addr":"DB12,INT118","name":"Output_40_Config"},{"addr":"DB12,INT120","name":"Output_41_Config"},{"addr":"DB12,INT122","name":"Output_42_Config"},{"addr":"DB12,INT124","name":"Output_43_Config"},{"addr":"DB12,INT126","name":"Output_44_Config"},{"addr":"DB12,INT128","name":"Output_45_Config"},{"addr":"DB12,INT130","name":"Output_46_Config"},{"addr":"DB12,INT132","name":"Output_47_Config"},{"addr":"DB12,INT134","name":"Output_48_Config"},{"addr":"DB12,INT136","name":"Output_49_Config"},{"addr":"DB12,INT138","name":"Output_50_Config"}]}]