Control generators

[
    {
        "id": "70c7ec66.31e354",
        "type": "tab",
        "label": "Electricity",
        "disabled": false,
        "info": ""
    },
    {
        "id": "190dc64a.a1249a",
        "type": "ui_led",
        "z": "70c7ec66.31e354",
        "order": 1,
        "group": "ca9031ed.6508",
        "width": "0",
        "height": "0",
        "label": "LEC",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "bool"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "bool"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 710,
        "y": 120,
        "wires": []
    },
    {
        "id": "dc628a10.7e8588",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "num",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 120,
        "wires": [
            [
                "190dc64a.a1249a"
            ]
        ]
    },
    {
        "id": "b9ac64f9.cce7d8",
        "type": "rpi-gpio in",
        "z": "70c7ec66.31e354",
        "name": "LEC",
        "pin": "5",
        "intype": "tri",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 270,
        "y": 120,
        "wires": [
            [
                "dc628a10.7e8588"
            ]
        ]
    },
    {
        "id": "9ea94c27.24e7d",
        "type": "ui_led",
        "z": "70c7ec66.31e354",
        "order": 1,
        "group": "ca9031ed.6508",
        "width": 0,
        "height": 0,
        "label": "Generator 30Kva",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "str"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "str"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 710,
        "y": 180,
        "wires": []
    },
    {
        "id": "1de9d56f.2aeb7b",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "num",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 180,
        "wires": [
            [
                "9ea94c27.24e7d"
            ]
        ]
    },
    {
        "id": "4e327b9b.971464",
        "type": "rpi-gpio in",
        "z": "70c7ec66.31e354",
        "name": "",
        "pin": "6",
        "intype": "up",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 280,
        "y": 180,
        "wires": [
            [
                "1de9d56f.2aeb7b"
            ]
        ]
    },
    {
        "id": "d98fe3e107e2879b",
        "type": "ui_led",
        "z": "70c7ec66.31e354",
        "order": 1,
        "group": "ca9031ed.6508",
        "width": 0,
        "height": 0,
        "label": "Generator 100Kva",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "str"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "str"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 710,
        "y": 240,
        "wires": []
    },
    {
        "id": "cb54b3d5f07c254b",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "num",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 240,
        "wires": [
            [
                "d98fe3e107e2879b"
            ]
        ]
    },
    {
        "id": "6659825d16a45def",
        "type": "rpi-gpio in",
        "z": "70c7ec66.31e354",
        "name": "",
        "pin": "13",
        "intype": "up",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 280,
        "y": 240,
        "wires": [
            [
                "cb54b3d5f07c254b"
            ]
        ]
    },
    {
        "id": "3b506a80a3120bc7",
        "type": "ui_led",
        "z": "70c7ec66.31e354",
        "order": 1,
        "group": "ca9031ed.6508",
        "width": 0,
        "height": 0,
        "label": "Generator 150Kva",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "false",
                "valueType": "str"
            },
            {
                "color": "#008000",
                "value": "true",
                "valueType": "str"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 710,
        "y": 300,
        "wires": []
    },
    {
        "id": "c3ea82460537377a",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "0",
                "fromt": "num",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 300,
        "wires": [
            [
                "3b506a80a3120bc7"
            ]
        ]
    },
    {
        "id": "03d9a3e67fd73930",
        "type": "rpi-gpio in",
        "z": "70c7ec66.31e354",
        "name": "",
        "pin": "19",
        "intype": "up",
        "debounce": "25",
        "read": true,
        "bcm": true,
        "x": 280,
        "y": 300,
        "wires": [
            [
                "c3ea82460537377a"
            ]
        ]
    },
    {
        "id": "41f146119cbcf39f",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen1",
        "pin": "18",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 750,
        "y": 400,
        "wires": []
    },
    {
        "id": "dfc5f88f4dd54dcf",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen2",
        "pin": "23",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 750,
        "y": 480,
        "wires": []
    },
    {
        "id": "37b2b3f5d5d6106b",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen3",
        "pin": "24",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 750,
        "y": 560,
        "wires": []
    },
    {
        "id": "9b4134fa5a0293bb",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 230,
        "y": 500,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "121db839a3fa1bfd",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 230,
        "y": 460,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "11ad600b9f5ab6d1",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 230,
        "y": 420,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "fbbee97f43cf6037",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "Determine relay states",
        "func": "\nlet msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]\n\nif (msg.payload > 0 && msg.payload <= 3) {\n    \n    msgs[msg.payload - 1].payload = 1\n}\nreturn msgs;",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 480,
        "wires": [
            [
                "93ae482345d5d61e"
            ],
            [
                "3095e251a52004f4"
            ],
            [
                "1ad2302b94027a93"
            ]
        ]
    },
    {
        "id": "93ae482345d5d61e",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "function 1",
        "func": "if (msg.payload == 0) {\n    msg.payload.gpio18 = 0\n   }\n\nelse if (msg.payload == 1) {\n    msg.payload.gpio18 = 1\n    }\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 620,
        "y": 400,
        "wires": [
            [
                "41f146119cbcf39f"
            ]
        ]
    },
    {
        "id": "c7b05837cf50f1f7",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 230,
        "y": 540,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "3095e251a52004f4",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "function 2",
        "func": "if (msg.payload == 0) {\n    msg.payload.gpio23 = 0\n   }\n\nelse if (msg.payload == 1) {\n    msg.payload.gpio23 = 1\n    }\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 620,
        "y": 480,
        "wires": [
            [
                "dfc5f88f4dd54dcf"
            ]
        ]
    },
    {
        "id": "1ad2302b94027a93",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "function 3",
        "func": "if (msg.payload == 0) {\n    msg.payload.gpio24 = 0\n   }\n\nelse if (msg.payload == 1) {\n    msg.payload.gpio24 = 1\n    }\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 620,
        "y": 560,
        "wires": [
            [
                "37b2b3f5d5d6106b"
            ]
        ]
    },
    {
        "id": "ca9031ed.6508",
        "type": "ui_group",
        "name": "Electricity",
        "tab": "91457eaf.c4e2c",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "91457eaf.c4e2c",
        "type": "ui_tab",
        "name": "Electricity",
        "icon": "dashboard",
        "order": 16,
        "disabled": false,
        "hidden": false
    }
]

new flow

still there is one thing. when LEC pin is high . all gen should be 0 values

Why have you added the function nodes after the Determine node? I thought that the rpi gpio out node needs msg.payload set to 0 or 1.

because it didnt worked if i connected it directly to gpio out.
so in every function i change the msg to which pin in gpio out will function .

Any solution to turn off all gpio off if lec(gpio in) is 0 ?

Show me where in the docs it says that the gpio node should have that.
Anyway, the functions do exactly nothing as the payload is not an object. Add a debug node showing what is coming out of the function nodes and have a look yourself.
Take them out and try again.

yes your are right COLIN thanks a lot for your help . appreciate
maybe i did change some value before. now i tested it directly to gpio out and its working perfectly

For switching them off when the lec is 0 you need to do two things

  1. When the lec goes to zero switch them off. You should be able to work that out. You just need to send 0 to the Determine node when the lec input goes zero. Use a switch node to only pass 0 and then send that to the Determine function.

  2. You need to prevent the outputs being set if the lec input is already zero. Probably the easiest way to do that is to save the lec to flow context whenever it changes then add a test of that flow context variable to this line in the Determine function
    if (msg.payload > 0 && msg.payload <= 3) {
    so it only allows the outputs to be set if lec context variable is not 0.

do you mean to use the change node and in the function use the context.get to retrieve the node value

A Change node is one way to set a flow context variable, yes.

In the function it is flow.get to get a flow variable. context.get gets from the node's private context.

[
    {
        "id": "41f146119cbcf39f",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen1",
        "pin": "18",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 460,
        "wires": []
    },
    {
        "id": "dfc5f88f4dd54dcf",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen2",
        "pin": "23",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 540,
        "wires": []
    },
    {
        "id": "37b2b3f5d5d6106b",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen3",
        "pin": "24",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 620,
        "wires": []
    },
    {
        "id": "9b4134fa5a0293bb",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 210,
        "y": 560,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "121db839a3fa1bfd",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 210,
        "y": 520,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "11ad600b9f5ab6d1",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 210,
        "y": 480,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "fbbee97f43cf6037",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "Relay States",
        "func": "\nlet msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]\nvar data = flow.get(\"data\");\nif (data == 1) {\n    return null;\n}\n\nelse if (msg.payload > 0 && msg.payload <= 3) {\n\n        msgs[msg.payload - 1].payload = 1\n    }\n    return msgs;",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 540,
        "wires": [
            [
                "41f146119cbcf39f"
            ],
            [
                "dfc5f88f4dd54dcf"
            ],
            [
                "37b2b3f5d5d6106b"
            ]
        ]
    },
    {
        "id": "c7b05837cf50f1f7",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 210,
        "y": 600,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "33c5a2b32a212dac",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "data",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 380,
        "wires": [
            [
                "edccade3bdbcb6e5",
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "edccade3bdbcb6e5",
        "type": "debug",
        "z": "70c7ec66.31e354",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 380,
        "wires": []
    },
    {
        "id": "a86c9230342eaf6c",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 130,
        "y": 380,
        "wires": [
            [
                "33c5a2b32a212dac"
            ]
        ]
    },
    {
        "id": "3106a2f5107c6a98",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 110,
        "y": 420,
        "wires": [
            [
                "33c5a2b32a212dac"
            ]
        ]
    }
]

i used it this way

Would it be better to call it flow.lec, or something similar, rather than flow.data?

What happens to your relay outputs when you click the 1 inject on the Change node? Read part 1 of my suggested solution again to see what to do about it.

changed to lec.
inject1 means there is lec
inject0 means no lec and could use the generators
when injecting 0 all works fine but when injecting1 i cannot use generators which is good but the last value of any generator will stay either if it is on

[
    {
        "id": "41f146119cbcf39f",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen1",
        "pin": "18",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 460,
        "wires": []
    },
    {
        "id": "dfc5f88f4dd54dcf",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen2",
        "pin": "23",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 540,
        "wires": []
    },
    {
        "id": "37b2b3f5d5d6106b",
        "type": "rpi-gpio out",
        "z": "70c7ec66.31e354",
        "name": "gen3",
        "pin": "24",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 730,
        "y": 620,
        "wires": []
    },
    {
        "id": "9b4134fa5a0293bb",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 210,
        "y": 560,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "121db839a3fa1bfd",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 210,
        "y": 520,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "11ad600b9f5ab6d1",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 210,
        "y": 480,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "fbbee97f43cf6037",
        "type": "function",
        "z": "70c7ec66.31e354",
        "name": "Relay States",
        "func": "\nlet msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]\nvar lec = flow.get(\"lec\");\nif (lec == 1) {\n    return [null, null, null];\n}\n\nelse if (msg.payload > 0 && msg.payload <= 3) {\n\n        msgs[msg.payload - 1].payload = 1\n    }\n    return msgs;",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 540,
        "wires": [
            [
                "41f146119cbcf39f"
            ],
            [
                "dfc5f88f4dd54dcf"
            ],
            [
                "37b2b3f5d5d6106b"
            ]
        ]
    },
    {
        "id": "c7b05837cf50f1f7",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 210,
        "y": 600,
        "wires": [
            [
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "33c5a2b32a212dac",
        "type": "change",
        "z": "70c7ec66.31e354",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "lec",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 390,
        "y": 380,
        "wires": [
            [
                "edccade3bdbcb6e5",
                "fbbee97f43cf6037"
            ]
        ]
    },
    {
        "id": "edccade3bdbcb6e5",
        "type": "debug",
        "z": "70c7ec66.31e354",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 380,
        "wires": []
    },
    {
        "id": "a86c9230342eaf6c",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 130,
        "y": 380,
        "wires": [
            [
                "33c5a2b32a212dac"
            ]
        ]
    },
    {
        "id": "3106a2f5107c6a98",
        "type": "inject",
        "z": "70c7ec66.31e354",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 110,
        "y": 420,
        "wires": [
            [
                "33c5a2b32a212dac"
            ]
        ]
    }
]

In the function it would be better to add the test to the existing test (as suggested in point 2 of my earlier post).

let msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]
const lec = flow.get("lec");
if (lec == 0  &&  msg.payload > 0 && msg.payload <= 3) {
    msgs[msg.payload - 1].payload = 1
}
return msgs;

The reason it is not working to switch the relays off is that you still have not done what I suggested in point 1 of my earlier post

At the moment you are sending 1 as well as 0 to the Determine node. You should only pass it on when the value is 0

Actually that is wrong. When the lec signal goes to 1 you have to send 0 to the Determine node. When the lec signal goes to 0 you should send nothing to the Determine node. So you need a Switch node to pass only values of 1 and then a Change node to set the payload to 0 to switch the relays off.

it works good now after i change the function to what did you send

let msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]
const lec = flow.get("lec");
if (lec == 0  &&  msg.payload > 0 && msg.payload <= 3) {
    msgs[msg.payload - 1].payload = 1
}
return msgs;

but will try to use switch and change node

Actually yes, you are right, it will work without the switch and change node, but only by accident, because any input to the Determine node will switch the relays off if the flow variable is set.

created switch that include value only ==1 and connected to change node the same as before but didn't worked

Export the flow.

[
    {
        "id": "6f900f6e0cc3f39d",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen1",
        "pin": "18",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 890,
        "y": 2100,
        "wires": []
    },
    {
        "id": "667b99cabeaf52b6",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen2",
        "pin": "23",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 890,
        "y": 2180,
        "wires": []
    },
    {
        "id": "f929ebcf7353e0c4",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen3",
        "pin": "24",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 890,
        "y": 2260,
        "wires": []
    },
    {
        "id": "5e0404c763d0a1fe",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 230,
        "y": 2120,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "f92433c54c4f7bdc",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 230,
        "y": 2080,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "448906195ae1480d",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 230,
        "y": 2040,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "23dbcebe12348a76",
        "type": "function",
        "z": "1575273d54101248",
        "name": "Relay States",
        "func": "\nlet msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]\nconst lec = flow.get(\"lec\");\n\nif (lec ==0 && msg.payload > 0 && msg.payload <= 3) {\n\n        msgs[msg.payload - 1].payload = 1\n    }\n    return msgs;",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 410,
        "y": 2100,
        "wires": [
            [
                "6f900f6e0cc3f39d"
            ],
            [
                "667b99cabeaf52b6"
            ],
            [
                "f929ebcf7353e0c4"
            ]
        ]
    },
    {
        "id": "9cb923746e79480c",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 230,
        "y": 2160,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "10795e3032c609fd",
        "type": "change",
        "z": "1575273d54101248",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "lec",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 410,
        "y": 2000,
        "wires": [
            [
                "d0732faf5e47d783",
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "d0732faf5e47d783",
        "type": "debug",
        "z": "1575273d54101248",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 1940,
        "wires": []
    },
    {
        "id": "6e5e0164db7728d9",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 130,
        "y": 1920,
        "wires": [
            [
                "e9c1acfffb449860"
            ]
        ]
    },
    {
        "id": "73478d66bde3f3c6",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 130,
        "y": 1980,
        "wires": [
            [
                "e9c1acfffb449860"
            ]
        ]
    },
    {
        "id": "e9c1acfffb449860",
        "type": "switch",
        "z": "1575273d54101248",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 430,
        "y": 1940,
        "wires": [
            [
                "10795e3032c609fd"
            ]
        ]
    }
]
``

How do you expect that to work? You have put the Switch the wrong side of the Change node, so that it only gets passed messages when lec is switched on, not when it switches off, so the context variable will never get cleared. Also you haven't added the second change node after the Switch node to set the payload to 0.

It is important that you understand the suggestions posted, don't just follow them slavishly. If you thought I meant the Switch node to go where you put it you should have pointed out to me that it would not work because the flow variable would never get cleared. We are not here to feed you answers, we are here to help you understand and learn, so that in the future you can do it yourself, not just come back and ask us to solve the next problem for you.

you are right about what you have said . the problem that i didnt get your point about making that but just giving a try . Anyway i am happy learning from you and thank for your help and patience.
Anyway , as i understand the below should be
1-store the values in change node
2- switch is setting only the value 1 and passed it to the next node
3- change node is getting the value 1 and changing it to 0 and passed it to the function
if am i right the code will be as the following

[
    {
        "id": "6f900f6e0cc3f39d",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen1",
        "pin": "18",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 950,
        "y": 2120,
        "wires": []
    },
    {
        "id": "667b99cabeaf52b6",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen2",
        "pin": "23",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 950,
        "y": 2200,
        "wires": []
    },
    {
        "id": "f929ebcf7353e0c4",
        "type": "rpi-gpio out",
        "z": "1575273d54101248",
        "name": "gen3",
        "pin": "24",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 950,
        "y": 2280,
        "wires": []
    },
    {
        "id": "5e0404c763d0a1fe",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "x": 290,
        "y": 2140,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "f92433c54c4f7bdc",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 290,
        "y": 2100,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "448906195ae1480d",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "v": "",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 290,
        "y": 2060,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "23dbcebe12348a76",
        "type": "function",
        "z": "1575273d54101248",
        "name": "Relay States",
        "func": "\nlet msgs = [{ payload: 0 }, { payload: 0 }, { payload: 0 }]\nconst lec = flow.get(\"lec\");\n\nif (lec ==0 && msg.payload > 0 && msg.payload <= 3) {\n\n        msgs[msg.payload - 1].payload = 1\n    }\n    return msgs;",
        "outputs": 3,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 2120,
        "wires": [
            [
                "6f900f6e0cc3f39d"
            ],
            [
                "667b99cabeaf52b6"
            ],
            [
                "f929ebcf7353e0c4"
            ]
        ]
    },
    {
        "id": "9cb923746e79480c",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "x": 290,
        "y": 2180,
        "wires": [
            [
                "23dbcebe12348a76"
            ]
        ]
    },
    {
        "id": "10795e3032c609fd",
        "type": "change",
        "z": "1575273d54101248",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "lec",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 270,
        "y": 1940,
        "wires": [
            [
                "e9c1acfffb449860"
            ]
        ]
    },
    {
        "id": "d0732faf5e47d783",
        "type": "debug",
        "z": "1575273d54101248",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 940,
        "y": 1960,
        "wires": []
    },
    {
        "id": "6e5e0164db7728d9",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "0",
        "payloadType": "num",
        "x": 110,
        "y": 1920,
        "wires": [
            [
                "10795e3032c609fd"
            ]
        ]
    },
    {
        "id": "73478d66bde3f3c6",
        "type": "inject",
        "z": "1575273d54101248",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "x": 110,
        "y": 1960,
        "wires": [
            [
                "10795e3032c609fd"
            ]
        ]
    },
    {
        "id": "e9c1acfffb449860",
        "type": "switch",
        "z": "1575273d54101248",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 450,
        "y": 1940,
        "wires": [
            [
                "687232cfe7eb44b5"
            ]
        ]
    },
    {
        "id": "687232cfe7eb44b5",
        "type": "change",
        "z": "1575273d54101248",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "1",
                "fromt": "num",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 540,
        "y": 2020,
        "wires": [
            [
                "23dbcebe12348a76",
                "d0732faf5e47d783"
            ]
        ]
    }
]