Pass Variable if condition is true

Hi, new to red-node, my question is regarding the function node.

I receive a variable (Integer) from a Siemens S7 PLC - Flow Name "Config"
I have a button in my Home Assistant - Flow name "Button"

What I am trying to do is when the button is triggered it moves the Integer value out of the function, after 100ms (Adjustable) then 0 again. But all I get back is "undefined when the Integer is moved.

I have the palette node-red-contrib-s7 installed

[{"id":"e839406253dead82","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"3feeff449417f3f4","type":"s7 in","z":"e839406253dead82","endpoint":"24c121bc8a089078","mode":"single","variable":"Single Push Value","diff":true,"name":"Config","x":550,"y":240,"wires":[["48824097d786854a"]]},{"id":"48824097d786854a","type":"function","z":"e839406253dead82","name":"Move Integer","func":"var X = msg.payload;\nvar myCount = flow.get([\"Config\"]);\n\n\nif (X == true )\n{\n    return { payload: myCount};\n}\nelse if (X==false)\n{\n    return{payload:0};\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":180,"wires":[["58b56e97bb0df945"]]},{"id":"58b56e97bb0df945","type":"debug","z":"e839406253dead82","name":"debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":180,"wires":[]},{"id":"8e2492fa5b109e58","type":"trigger","z":"e839406253dead82","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":560,"y":180,"wires":[["48824097d786854a"]]},{"id":"138588ba5338eea8","type":"server-state-changed","z":"e839406253dead82","name":"Button","server":"2d39e267082bb0e5","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.button_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":[],"x":410,"y":180,"wires":[["8e2492fa5b109e58"],["8e2492fa5b109e58"]]},{"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,S0.10","name":"Name"},{"addr":"DB12,S12.10","name":"Location"},{"addr":"DB12,S24.20","name":"Secret"},{"addr":"DB12,DINT46","name":"ID"},{"addr":"DB12,INT50","name":"Target"},{"addr":"DB12,INT52","name":"Actual"},{"addr":"DB12,X154.0","name":"Heater Status"},{"addr":"DB12,X0.0","name":"Night"},{"addr":"DB12,INT2","name":"Order"},{"addr":"DB12,X132.0","name":"Light Status"},{"addr":"DB12,INT134","name":"Single Push Value"}]},{"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}]

In a scl language i would type something like this:

If Button then
Function:=Config;
else
Function:=0;
End_if;

Hello @Strandl and welcome to Node-red.

It can be difficult moving from a more traditional programming style to flow based programming.

Beginners often try to do as much as possible in function nodes because its a more familiar text based, top down approach.
There's nothing wrong with functions but it's a good idea to try and avoid using them so that you get used to the visual flow based style.

I do not have Home Assistant or node-red-config-s7 but I can take a look at your core node-red code.

I first looked at the function node.
Why the square brackets in your flow.get(["Config"])?
Does msg.payload need to be an array?
If so, why is your alternative value 0 rather than an array?

I think that you want to

  • Send a message with payload = flow.Config
  • 100ms later send another message with payload = 0

You can do this with just the trigger node:

Hi jbudd

I want to attach more pictures the page wont allow me

Thanks for the quick response,

I have tried using a switch but I get the same answer.. "Undefined" when I
debug
send the integer.

No, it does not have to be an array, 0 states that the order has been given to the system.

I don´t think the S7 node from the plc stores the value, so maybe that can cause the error.

Can I push the config to a container?.

I have to copy this 50 times, new button and a different interger value.

Maybe i make it more difficult for myself.

[{"id":"a09ebb5a3c4125dd","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"63e23dcdf463e16a","type":"s7 in","z":"a09ebb5a3c4125dd","endpoint":"24c121bc8a089078","mode":"single","variable":"Single Push Value","diff":true,"name":"Config","x":510,"y":320,"wires":[["d1f251729909a2d7"]]},{"id":"bcc537a921924166","type":"debug","z":"a09ebb5a3c4125dd","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":820,"y":260,"wires":[]},{"id":"77b2da270d804433","type":"trigger","z":"a09ebb5a3c4125dd","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":500,"y":260,"wires":[["d1f251729909a2d7"]]},{"id":"b889ed28179c3950","type":"server-state-changed","z":"a09ebb5a3c4125dd","name":"Button","server":"2d39e267082bb0e5","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.button_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":[],"x":350,"y":260,"wires":[["77b2da270d804433"],["77b2da270d804433"]]},{"id":"d1f251729909a2d7","type":"trigger","z":"a09ebb5a3c4125dd","name":"Transfer","op1":"Config","op2":"","op1type":"flow","op2type":"num","duration":"100","extend":false,"overrideDelay":false,"units":"ms","reset":"cd420bc85ebee335","bytopic":"all","topic":"topic","outputs":1,"x":660,"y":260,"wires":[["bcc537a921924166"]]},{"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,S0.10","name":"Name"},{"addr":"DB12,S12.10","name":"Location"},{"addr":"DB12,S24.20","name":"Secret"},{"addr":"DB12,DINT46","name":"ID"},{"addr":"DB12,INT50","name":"Target"},{"addr":"DB12,INT52","name":"Actual"},{"addr":"DB12,X154.0","name":"Heater Status"},{"addr":"DB12,X0.0","name":"Night"},{"addr":"DB12,INT2","name":"Order"},{"addr":"DB12,X132.0","name":"Light Status"},{"addr":"DB12,INT134","name":"Single Push Value"}]},{"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}]

debug

It looks like the variable flow.Config has no value at the time you access it.
Why a context variable rather than passing the value as a property of the message?
What does the integer represent and where do you store the value?

Sorry but I have no idea what a container is. Presumably something to do with Home Assistant.
Nor do I know what a Home Assistant button is or what it can do.

Something like this?

[{"id":"bcc537a921924166","type":"debug","z":"a09ebb5a3c4125dd","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":640,"y":420,"wires":[]},{"id":"77b2da270d804433","type":"trigger","z":"a09ebb5a3c4125dd","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":320,"y":420,"wires":[["0fe93392dabc20c9"]]},{"id":"6337723e052c4ff6","type":"inject","z":"a09ebb5a3c4125dd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":130,"y":420,"wires":[["77b2da270d804433"]]},{"id":"28cb41762877bcd4","type":"function","z":"a09ebb5a3c4125dd","name":"Store latestValue","func":"flow.set(\"PushValue\", msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":520,"wires":[[]]},{"id":"0fe93392dabc20c9","type":"function","z":"a09ebb5a3c4125dd","name":"function 14","func":"let state = msg.payload;\nlet value = flow.get(\"PushValue\")\n\nif (typeof value != \"undefined\")\n{\n    if (state === true) {\n        msg.payload = value;\n    }\n    else msg.payload = 0\n}\nelse node.warn(\"Undefined value\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":420,"wires":[["bcc537a921924166"]]},{"id":"c5f938476ec477a5","type":"s7 in","z":"a09ebb5a3c4125dd","endpoint":"24c121bc8a089078","mode":"single","variable":"Single Push Value","diff":true,"name":"Config","x":250,"y":520,"wires":[["28cb41762877bcd4"]]},{"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,S0.10","name":"Name"},{"addr":"DB12,S12.10","name":"Location"},{"addr":"DB12,S24.20","name":"Secret"},{"addr":"DB12,DINT46","name":"ID"},{"addr":"DB12,INT50","name":"Target"},{"addr":"DB12,INT52","name":"Actual"},{"addr":"DB12,X154.0","name":"Heater Status"},{"addr":"DB12,X0.0","name":"Night"},{"addr":"DB12,INT2","name":"Order"},{"addr":"DB12,X132.0","name":"Light Status"},{"addr":"DB12,INT134","name":"Single Push Value"}]}]

Thanks Karolis

this was exactly what i was trying to do.

@jbudd i have a complete system that controls my house and everything in it, i have based it on a order system, i just want to see if i could use Home assistant instead of sms services.

Hi again

now when i want to use this setup many times (Number of outputs) i want to use a subflow but i am limited by 1 input.

So what i am trying to:

  1. Read the complete DB12 in the plc. 50 states of the output and 50 Integers (Config Values),

  2. Can the array/object be global so I can access them from inside the Subflow?

  3. If i can acces the array, can the input (Button).topic be a static number 1-50 which will be the pointer to lookup the array

So if the input Button´s payload is True/false and the topic is the number of output it is referring to.

Inside the subflow i will send the config value if the button is pressed.

I have pasted my subflow solution. I know how i can do it in text (Scl) but i am still learning in here
:slight_smile:

[{"id":"1d0d2a4c05bf9850","type":"subflow","name":"Output","info":"","category":"","in":[{"x":200,"y":280,"wires":[{"id":"991cdbd91140358d"}]}],"out":[{"x":830,"y":280,"wires":[{"id":"f0b063d62d8fdf14","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":[["f0b063d62d8fdf14"]]},{"id":"f0b063d62d8fdf14","type":"function","z":"1d0d2a4c05bf9850","name":"function 16","func":"let state = msg.payload;\nlet value = global.get(\"LightConfig\")\n\nif (typeof value != \"undefined\")\n{\n    if (state === true) {\n        msg.payload = value;\n    }\n    else msg.payload = 0\n}\nelse node.warn(\"Undefined value\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":280,"wires":[[]]},{"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":"e63f1cc0a8b69fae","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"4e92c1034122f3b2","type":"s7 out","z":"e63f1cc0a8b69fae","endpoint":"24c121bc8a089078","variable":"Order","name":"Order","x":1090,"y":360,"wires":[]},{"id":"46d75c07a9192b13","type":"link in","z":"e63f1cc0a8b69fae","name":"link in 2","links":["84c4ab1cf63880eb","ec385de5f0be49eb"],"x":925,"y":360,"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"},{"property":"payload","propertyType":"msg","value":"","valueType":"str"}],"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":"0579b96962817a6a","type":"function","z":"e63f1cc0a8b69fae","name":"Store Status","func":"\nglobal.set(\"LightStatus\", msg.payload)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":140,"wires":[["3980665e97111ff2"]]},{"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":[["0579b96962817a6a"]]},{"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":"602793f79b306aaa","type":"comment","z":"e63f1cc0a8b69fae","name":"Output 01","info":"","x":340,"y":300,"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":[["80b53b48f4b1e68e"]]},{"id":"80b53b48f4b1e68e","type":"function","z":"e63f1cc0a8b69fae","name":"Store Config","func":"\nglobal.set(\"LightConfig\", msg.payload)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":200,"wires":[["459222043236b8d3"]]},{"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"}]}]

Can you post an example of button topic?

There is no need for a subflow:

If I understood correctly your needs can convert S7 results into two arrays of values and look into those with array index:

[{"id":"816ce000a9fd0547","type":"inject","z":"e63f1cc0a8b69fae","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\t    \"Output_01\":false,\t    \"Output_02\":true,\t    \"Output_03\":false\t}","payloadType":"jsonata","x":930,"y":160,"wires":[["82044dd94cc6dfae"]]},{"id":"82044dd94cc6dfae","type":"function","z":"e63f1cc0a8b69fae","name":"Store Status","func":"//Change JSON to Array of values\nlet outputs = Object.values(msg.payload)\nglobal.set(\"LightStatus\", outputs)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1090,"y":160,"wires":[[]]},{"id":"5a024ad397f65109","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":1090,"y":220,"wires":[[]]},{"id":"0ff88dca5a754732","type":"inject","z":"e63f1cc0a8b69fae","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\t    \"Output_01_Config\":100,\t    \"Output_02_Config\":200,\t    \"Output_03_Config\":300\t}","payloadType":"jsonata","x":930,"y":220,"wires":[["5a024ad397f65109"]]},{"id":"3a369c86efc44ef3","type":"inject","z":"e63f1cc0a8b69fae","name":"Button1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"true","payloadType":"bool","x":930,"y":280,"wires":[["c16b48b788669665"]]},{"id":"6dfaf1a5fe02976d","type":"inject","z":"e63f1cc0a8b69fae","name":"Button2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"true","payloadType":"bool","x":930,"y":320,"wires":[["c16b48b788669665"]]},{"id":"c16b48b788669665","type":"function","z":"e63f1cc0a8b69fae","name":"function 17","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":1110,"y":300,"wires":[["c12be04b92920831"]]},{"id":"c12be04b92920831","type":"debug","z":"e63f1cc0a8b69fae","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1280,"y":300,"wires":[]}]

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"}]}]

For the future please provide data with native nodeRED nodes: replace S7 read and HomeAssistant nodes with injects containing same structures, because it is not possible to replicate your system.

Here is an attempt from what I understood:

[{"id":"a4c7d098e2f91896","type":"subflow","name":"Output (2)","info":"","category":"","in":[{"x":200,"y":280,"wires":[{"id":"5f58ae7733c3f573"},{"id":"c2bb81d70e734b03"}]}],"out":[{"x":830,"y":280,"wires":[{"id":"aa716c2a5b32c737","port":0}]},{"x":820,"y":360,"wires":[{"id":"d27665eb02e82f65","port":0}]},{"x":820,"y":420,"wires":[{"id":"d27665eb02e82f65","port":1}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["ButtonConfigState"],"outputLabels":["Order","On","Off"]},{"id":"5f58ae7733c3f573","type":"trigger","z":"a4c7d098e2f91896","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":[["aa716c2a5b32c737"]]},{"id":"d27665eb02e82f65","type":"switch","z":"a4c7d098e2f91896","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":540,"wires":[[],[]]},{"id":"aa716c2a5b32c737","type":"function","z":"a4c7d098e2f91896","name":"function 18","func":"let btnIndex = parseInt(msg.topic)\n\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 (msg.payload === 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":"c2bb81d70e734b03","type":"function","z":"a4c7d098e2f91896","name":"Check Light status","func":"let btnIndex = parseInt(msg.topic)\n\nlet lightStatusArr = global.get(\"LightStatus\")\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 = true \n    }\n    else  msg.payload = false;\n}\nelse node.warn(\"Unknown topic\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":360,"wires":[["d27665eb02e82f65"]]},{"id":"35eec7f7ed50ac36","type":"link in","z":"e4b5d5db4d470e47","name":"link in 2","links":["84c4ab1cf63880eb","cec6b02710266605","2d760bdabdf35490"],"x":855,"y":420,"wires":[["a792fd61d1fb9937"]]},{"id":"cec6b02710266605","type":"link out","z":"e4b5d5db4d470e47","name":"link out 2","mode":"link","links":["7baad5ef49bbadac","35eec7f7ed50ac36"],"x":555,"y":260,"wires":[]},{"id":"2d760bdabdf35490","type":"link out","z":"e4b5d5db4d470e47","name":"link out 3","mode":"link","links":["7baad5ef49bbadac","35eec7f7ed50ac36"],"x":555,"y":460,"wires":[]},{"id":"3a369c86efc44ef3","type":"inject","z":"e4b5d5db4d470e47","name":"Button1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"1","payload":"false","payloadType":"bool","x":230,"y":300,"wires":[["cd3c247eb0a8c03a"]]},{"id":"6dfaf1a5fe02976d","type":"inject","z":"e4b5d5db4d470e47","name":"Button2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"2","payload":"true","payloadType":"bool","x":230,"y":500,"wires":[["b03a50a8328a107e"]]},{"id":"ddb9ba071c5f203b","type":"debug","z":"e4b5d5db4d470e47","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":320,"wires":[]},{"id":"cd3c247eb0a8c03a","type":"subflow:a4c7d098e2f91896","z":"e4b5d5db4d470e47","name":"","x":410,"y":300,"wires":[["cec6b02710266605"],["ddb9ba071c5f203b"],["ddb9ba071c5f203b"]]},{"id":"b03a50a8328a107e","type":"subflow:a4c7d098e2f91896","z":"e4b5d5db4d470e47","name":"","x":410,"y":500,"wires":[["2d760bdabdf35490"],["42e495232d007b02"],["42e495232d007b02"]]},{"id":"a792fd61d1fb9937","type":"debug","z":"e4b5d5db4d470e47","name":"debug 9","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1020,"y":420,"wires":[]},{"id":"42e495232d007b02","type":"debug","z":"e4b5d5db4d470e47","name":"debug 10","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":500,"wires":[]}]

Sorry, i did not think about that.

The Toggle function works, but my state is only updated when the button is pressed.

If the output is triggered by the plc the state is never received in the function because the topic is only written into the function block when the payload is activated.

So I need the topic (Number 1-50) to be send in always.
Maybe I can use a constant?

[{"id":"a4c7d098e2f91896","type":"subflow","name":"Output","info":"","category":"","in":[{"x":200,"y":280,"wires":[{"id":"5f58ae7733c3f573"},{"id":"c2bb81d70e734b03"}]}],"out":[{"x":830,"y":280,"wires":[{"id":"aa716c2a5b32c737","port":0}]},{"x":820,"y":360,"wires":[{"id":"d27665eb02e82f65","port":0}]},{"x":820,"y":420,"wires":[{"id":"d27665eb02e82f65","port":1}]}],"env":[],"meta":{},"color":"#DDAA99","inputLabels":["ButtonConfigState"],"outputLabels":["Order","On","Off"]},{"id":"5f58ae7733c3f573","type":"trigger","z":"a4c7d098e2f91896","name":"Trigger","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"120","extend":false,"overrideDelay":false,"units":"ms","reset":"cd420bc85ebee335","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":280,"wires":[["aa716c2a5b32c737"]]},{"id":"d27665eb02e82f65","type":"switch","z":"a4c7d098e2f91896","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":540,"wires":[[],[]]},{"id":"aa716c2a5b32c737","type":"function","z":"a4c7d098e2f91896","name":"function 18","func":"let btnIndex = parseInt(msg.topic)\n\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 (msg.payload === 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":"c2bb81d70e734b03","type":"function","z":"a4c7d098e2f91896","name":"Check Light status","func":"let btnIndex = parseInt(msg.topic)\n\nlet lightStatusArr = global.get(\"LightStatus\")\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 = true \n    }\n    else  msg.payload = false;\n}\n//else node.warn(\"Unknown topic\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":360,"wires":[["d27665eb02e82f65"]]},{"id":"8c82219b26c4632a","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"821234190ccf6b32","type":"link in","z":"8c82219b26c4632a","name":"Order Link","links":["27ab6da474bc8c02","b00cb3beb336adcb"],"x":875,"y":240,"wires":[["601169c3d17fa8f8"]]},{"id":"27ab6da474bc8c02","type":"link out","z":"8c82219b26c4632a","name":"Output 1","mode":"link","links":["821234190ccf6b32"],"x":515,"y":200,"wires":[]},{"id":"51ad39ce131e39aa","type":"debug","z":"8c82219b26c4632a","name":"debug 12","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":240,"wires":[]},{"id":"e40b4288d3d58b4d","type":"subflow:a4c7d098e2f91896","z":"8c82219b26c4632a","name":"","x":360,"y":240,"wires":[["27ab6da474bc8c02"],["51ad39ce131e39aa"],["e2c28d77149118c9"]]},{"id":"e2c28d77149118c9","type":"debug","z":"8c82219b26c4632a","name":"debug 13","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":280,"wires":[]},{"id":"601169c3d17fa8f8","type":"debug","z":"8c82219b26c4632a","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1000,"y":240,"wires":[]},{"id":"2bddedb0c32624f8","type":"inject","z":"8c82219b26c4632a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":190,"y":220,"wires":[["e40b4288d3d58b4d"]]},{"id":"3c5b721ffa883444","type":"ui_numeric","z":"8c82219b26c4632a","name":"","label":"numeric","tooltip":"","group":"a65de041e2cca0d3","order":6,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"topic","topicType":"msg","format":"1","min":0,"max":10,"step":1,"className":"","x":200,"y":360,"wires":[["e40b4288d3d58b4d"]]},{"id":"ed22ac9e8fcbf929","type":"comment","z":"8c82219b26c4632a","name":"Button True/False","info":"","x":150,"y":180,"wires":[]},{"id":"59bf3f0dac0261d6","type":"comment","z":"8c82219b26c4632a","name":"Output Number Constant 1-50","info":"","x":140,"y":320,"wires":[]},{"id":"a65de041e2cca0d3","type":"ui_group","name":"Default","tab":"96d6e4130a390999","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"96d6e4130a390999","type":"ui_tab","name":"Strandly","icon":"dashboard","disabled":false,"hidden":false}]

Sorry,

but I completely lost what you want to do. You said that you could do it in SCL, can you just write it and I will try and help you to convert it in NodeRED?

The toggle functions works with the config number.

It is only the status i only get when the buttons is pushed, my issue is that the output can be turned on/off by the plc, but i cant see it here.

the simple code i would write here:

// Variables
In
Output_Button = Bool
OutputNo = Integer

In/Out
ConfigValue:=Array[1..50] of INT; (DB12)
StateValue:=Array[1..50] of BOOL; (DB12

Out
Aktivaton = Integer
State = Bool


Toggle:= Output_Button;
OutputNo:= INT#1;

//Activation of output

If toggle then
Activation:=ConfigValue[OutputNo];
else
Activation:=INT#0;
End_if;

// State - Monitored all the time
State:= Statevalue[OutputNo];

Lets try this:

[{"id":"a4c7d098e2f91896","type":"subflow","name":"Output (2)","info":"","category":"","in":[{"x":200,"y":280,"wires":[{"id":"aa716c2a5b32c737"}]}],"out":[{"x":830,"y":280,"wires":[{"id":"aa716c2a5b32c737","port":0}]},{"x":820,"y":360,"wires":[{"id":"d27665eb02e82f65","port":0}]},{"x":820,"y":420,"wires":[{"id":"d27665eb02e82f65","port":1}]}],"env":[{"name":"OutputNo","type":"num","value":"1"}],"meta":{},"color":"#DDAA99","inputLabels":["ButtonConfigState"],"outputLabels":["Order","On","Off"]},{"id":"d27665eb02e82f65","type":"switch","z":"a4c7d098e2f91896","name":"","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":550,"y":540,"wires":[[],[]]},{"id":"aa716c2a5b32c737","type":"function","z":"a4c7d098e2f91896","name":"function 18","func":"let btnIndex = env.get(\"OutputNo\");\n\nlet lightConfigArr = global.get(\"ConfigValue\")\n\n//Modify your indexes to be from 0 to 49 if necessary\nif (typeof btnIndex === \"number\" && btnIndex >= 1 && btnIndex<=50) {\n    if (msg.payload === 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":"c2bb81d70e734b03","type":"function","z":"a4c7d098e2f91896","name":"Check Light status","func":"let btnIndex = msg.payload\n\nlet lightStatusArr = global.get(\"StateValue\")\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 = true \n    }\n    else  msg.payload = false;\n}\nelse node.warn(\"Unknown topic\")\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":360,"wires":[["d27665eb02e82f65"]]},{"id":"1b9454b6fb21edde","type":"inject","z":"a4c7d098e2f91896","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OutputNo","payloadType":"env","x":230,"y":360,"wires":[["c2bb81d70e734b03"]]},{"id":"5f58ae7733c3f573","type":"trigger","z":"a4c7d098e2f91896","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":200,"wires":[[]]},{"id":"816ce000a9fd0547","type":"inject","z":"e4b5d5db4d470e47","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\t    \"Output_01\":false,\t    \"Output_02\":true,\t    \"Output_03\":false\t}","payloadType":"jsonata","x":1350,"y":60,"wires":[["82044dd94cc6dfae"]]},{"id":"82044dd94cc6dfae","type":"function","z":"e4b5d5db4d470e47","name":"Store Status","func":"//Change JSON to Array of values\n//StateValue in SCL\nlet outputs = Object.values(msg.payload)\nglobal.set(\"StateValue\", outputs)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":60,"wires":[[]]},{"id":"5a024ad397f65109","type":"function","z":"e4b5d5db4d470e47","name":"Store Config","func":"//Change JSON to Array of values\n//ConfigValue in SCL\nlet functions = Object.values(msg.payload)\n\nmsg.payload = functions;\nglobal.set(\"ConfigValue\", functions)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1510,"y":100,"wires":[[]]},{"id":"0ff88dca5a754732","type":"inject","z":"e4b5d5db4d470e47","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\t    \"Output_01_Config\":100,\t    \"Output_02_Config\":200,\t    \"Output_03_Config\":300\t}","payloadType":"jsonata","x":1350,"y":100,"wires":[["5a024ad397f65109"]]},{"id":"b03a50a8328a107e","type":"subflow:a4c7d098e2f91896","z":"e4b5d5db4d470e47","name":"Button1","x":1580,"y":200,"wires":[["b4a1d401202184f2"],["42e495232d007b02"],["42e495232d007b02"]]},{"id":"42e495232d007b02","type":"debug","z":"e4b5d5db4d470e47","name":"debug 10","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1780,"y":240,"wires":[]},{"id":"3e649d00f11967eb","type":"inject","z":"e4b5d5db4d470e47","name":"Output_Button1 true","props":[{"p":"payload"},{"p":"topic","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1390,"y":180,"wires":[["b03a50a8328a107e"]]},{"id":"2f887b8003347136","type":"inject","z":"e4b5d5db4d470e47","name":"Output_Button1 false","props":[{"p":"payload"},{"p":"topic","v":"1","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":1400,"y":220,"wires":[["b03a50a8328a107e"]]},{"id":"3342c056b8587aca","type":"inject","z":"e4b5d5db4d470e47","name":"Output_Button2 true","props":[{"p":"payload"},{"p":"topic","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1390,"y":400,"wires":[["ec7b6ee1b112e832"]]},{"id":"39ea263ccb73ac60","type":"inject","z":"e4b5d5db4d470e47","name":"Output_Button2 false","props":[{"p":"payload"},{"p":"topic","v":"2","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":1400,"y":440,"wires":[["ec7b6ee1b112e832"]]},{"id":"b4a1d401202184f2","type":"debug","z":"e4b5d5db4d470e47","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1780,"y":180,"wires":[]},{"id":"ec7b6ee1b112e832","type":"subflow:a4c7d098e2f91896","z":"e4b5d5db4d470e47","name":"Button2","env":[{"name":"OutputNo","value":"2","type":"num"}],"x":1580,"y":420,"wires":[["26412987cea4602d"],["90220fd90210e6ca"],["90220fd90210e6ca"]]},{"id":"26412987cea4602d","type":"debug","z":"e4b5d5db4d470e47","name":"debug 17","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1780,"y":400,"wires":[]},{"id":"90220fd90210e6ca","type":"debug","z":"e4b5d5db4d470e47","name":"debug 18","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1780,"y":440,"wires":[]}]

If I understand correctly you will assign static integer for each button, and in NodeRED as in TIA portal you want to replicate multiinstance FB/FC functionality.

For this purpose you can create variable which is assigned for individual subflow
image

Also you need trigger to activate node. If you need to continuously monitor something you need repeatedly inject something. For this purpose I added:
image
just change injection interval to your liking
image

This should work as your logic in SCL:
Buttons

If something is missing, I think you have plenty of examples to adjust for your liking

Thank you for your help, got it to work.

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