flows.json (10.7 KB)
O i forgot to mention I did have a debug. Still image, But what I saw yesterday happen was that the "button 1gp" switches to 0 and 1 and back without any interaction multiple times. There is no button or any wire connected to any pins yet, so no physical trigger possible.
[
{
"id": "09c77f24e7bccf15",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "d4cdc552e12c5621",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Button 1",
"props": [
{
"p": "payload"
},
{
"p": "Repeat",
"v": "none",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "flow",
"x": 200,
"y": 140,
"wires": [
[
"c91e285e20d5a874"
]
]
},
{
"id": "f40fe163d7499fb8",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Button 2",
"props": [
{
"p": "payload"
},
{
"p": "Repeat",
"v": "none",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 220,
"y": 320,
"wires": [
[
"cd7c353cd80d7aeb"
]
]
},
{
"id": "cd7c353cd80d7aeb",
"type": "function",
"z": "09c77f24e7bccf15",
"name": "function 2",
"func": "// Input: msg.payload (button state)\n// Output: msg.payload (command to control relays)\n\nvar relayState2 = flow.get(\"relayState2\") || false;\nvar relayState3 = flow.get(\"relayState3\") || false;\nvar relayState4 = flow.get(\"relayState4\") || false;\n\n// Check if any of the relays are off\nif (!relayState2 || !relayState3 || !relayState4) {\n // Turn on all relays\n relayState2 = true;\n relayState3 = true;\n relayState4 = true;\n} else {\n // Turn off all relays\n relayState2 = false;\n relayState3 = false;\n relayState4 = false;\n}\n\nflow.set(\"relayState2\", relayState2);\nflow.set(\"relayState3\", relayState3);\nflow.set(\"relayState4\", relayState4);\n\n// Prepare the output command\nvar command = {\n relay2: relayState2 ? 1 : 0,\n relay3: relayState3 ? 1 : 0,\n relay4: relayState4 ? 1 : 0\n};\n\nmsg.payload = command;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 320,
"wires": [
[
"7223ffd76740e175"
]
]
},
{
"id": "f53cb388b02ccf28",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Button 3",
"props": [
{
"p": "payload"
},
{
"p": "Repeat",
"v": "none",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 160,
"y": 500,
"wires": [
[
"921a33090ad9837c"
]
]
},
{
"id": "f66f04e359b9c550",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Button 4",
"props": [
{
"p": "payload"
},
{
"p": "Repeat",
"v": "none",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 200,
"y": 620,
"wires": [
[]
]
},
{
"id": "ed26f34718414f5e",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Button 5",
"props": [
{
"p": "payload"
},
{
"p": "Repeat",
"v": "none",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 200,
"y": 660,
"wires": [
[]
]
},
{
"id": "a82449df7ba0d205",
"type": "rpi-gpio out",
"z": "09c77f24e7bccf15",
"name": "Relay1",
"pin": "22",
"set": false,
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 690,
"y": 140,
"wires": []
},
{
"id": "642fcfa9eb369aad",
"type": "rpi-gpio out",
"z": "09c77f24e7bccf15",
"name": "Relay2",
"pin": "16",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 690,
"y": 320,
"wires": []
},
{
"id": "dccae454835bdfd4",
"type": "rpi-gpio out",
"z": "09c77f24e7bccf15",
"name": "Relay3",
"pin": "18",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 690,
"y": 380,
"wires": []
},
{
"id": "47f57b74dbb0cf48",
"type": "rpi-gpio out",
"z": "09c77f24e7bccf15",
"name": "Relay4",
"pin": "22",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 690,
"y": 440,
"wires": []
},
{
"id": "525384a05af3164c",
"type": "rpi-gpio in",
"z": "09c77f24e7bccf15",
"name": "Button 1gp",
"pin": "15",
"intype": "tri",
"debounce": "25",
"read": false,
"bcm": true,
"x": 200,
"y": 80,
"wires": [
[
"c91e285e20d5a874"
]
]
},
{
"id": "c91e285e20d5a874",
"type": "trigger",
"z": "09c77f24e7bccf15",
"name": "400ms",
"op1": "1",
"op2": "0",
"op1type": "str",
"op2type": "str",
"duration": "400",
"extend": false,
"overrideDelay": false,
"units": "ms",
"reset": "",
"bytopic": "all",
"topic": "topic",
"outputs": 1,
"x": 410,
"y": 80,
"wires": [
[
"a82449df7ba0d205",
"37e6a4cea7d28de6"
]
]
},
{
"id": "37e6a4cea7d28de6",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 80,
"wires": []
},
{
"id": "7223ffd76740e175",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 500,
"wires": []
},
{
"id": "2cddb2d96640f760",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 3",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 580,
"wires": []
},
{
"id": "84f502513097d5a4",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 620,
"wires": []
},
{
"id": "767331b147c24f38",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 5",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 660,
"wires": []
},
{
"id": "3cb117841d1bdba7",
"type": "debug",
"z": "09c77f24e7bccf15",
"name": "debug 6",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 540,
"wires": []
},
{
"id": "770c0858dd2addc1",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "On",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1",
"payloadType": "num",
"x": 250,
"y": 380,
"wires": [
[
"642fcfa9eb369aad"
]
]
},
{
"id": "ceca0a062856929e",
"type": "inject",
"z": "09c77f24e7bccf15",
"name": "Off",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "0",
"payloadType": "num",
"x": 230,
"y": 420,
"wires": [
[
"642fcfa9eb369aad"
]
]
},
{
"id": "921a33090ad9837c",
"type": "function",
"z": "09c77f24e7bccf15",
"name": "function 3",
"func": "// Input: msg.payload (always 1)\n// Output: msg.payload (command to toggle relay 2)\n\nvar relay2State = context.get(\"relay2\");\nif (relay2State === undefined || isNaN(relay2State)) {\n relay2State = 0; // Set initial state to off if not defined or NaN\n}\n\nif (relay2State === 1) {\n relay2State = 0; // Turn off relay 2\n} else {\n relay2State = 1; // Turn on relay 2\n}\n\ncontext.set(\"relay2\", relay2State);\n\nmsg.payload = { relay2: relay2State };\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 480,
"wires": [
[
"dccae454835bdfd4",
"3cb117841d1bdba7"
]
]
}
]
"Edit:
I spoke too soon, the self switching of the gpio in is still happening."