I am working on a project that will eventually use a Raspberry Pi to start and stop my generator via relays on the fuel and starter solenoids. I have a basic POC working on my desk. I need to still work out the final logic. I built a simple dashboard with switches that control the relays and Indicator templates that I want the color to toggle between green (on) and red (off). The problem is that the "Starter Solenoid" switch changes all of them. The other switches don't change anything. I am not sure why. Here is the flow. I am mainly focused on the switches for now and why they aren't changing the indicator templates. One thing I noticed in the debug output is
debug2 is connected to the change nodes to the Starter solenoid switch.
debug1 is connected to the change nodes for the Fuel solenoid switch. So it seems that those change nodes are sending the full object. I am not sure why.
11/27/2024, 11:11:44 AMnode: debug 2
msg.payload : string[3]
"red"
11/27/2024, 11:12:02 AMnode: debug 1
msg : Object
{ payload: "red", socketid: "Z7vRtpSJMDLr4w5LAAAp", _msgid: "e6620f37f7a4af03" }
[
{
"id": "3d58b8e8.2450c8",
"type": "tab",
"label": "Generator Starter",
"disabled": false,
"info": ""
},
{
"id": "32cfb89af08b6c76",
"type": "group",
"z": "3d58b8e8.2450c8",
"style": {
"stroke": "#999999",
"stroke-opacity": "1",
"fill": "none",
"fill-opacity": "1",
"label": true,
"label-position": "nw",
"color": "#a4a4a4"
},
"nodes": [],
"x": 354,
"y": 1259,
"w": 40,
"h": 40
},
{
"id": "274ce6cb.d1e47a",
"type": "function",
"z": "3d58b8e8.2450c8",
"name": "Blynk LED Control",
"func": "\nif (msg.payload == 1)\n\n{ msg.payload=250 }\n\nelse {\nmsg.payload=0}\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 340,
"wires": [
[]
]
},
{
"id": "ac099a01.803be8",
"type": "function",
"z": "3d58b8e8.2450c8",
"name": "Blynk Label Properties",
"func": "if (msg.payload == 1)\n\n{ msg.label = \"ON\";\nmsg.color = \"#23C48E\";\nmsg.payload= \"ON;\"\n }\n\nelse {\nmsg.label = \"OFF\";\nmsg.color = \"#D3435C\";\n msg.payload= \"OFF;\"\n}\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 780,
"y": 400,
"wires": [
[
"5d87086562907a0d",
"1d50ec0c8fdc80e5"
]
]
},
{
"id": "b7d3042.235adf8",
"type": "rpi-gpio in",
"z": "3d58b8e8.2450c8",
"name": "DetectStart",
"pin": "22",
"intype": "down",
"debounce": "25",
"read": true,
"bcm": true,
"x": 300,
"y": 1120,
"wires": [
[
"5e98c41c16ceeca5"
]
]
},
{
"id": "610241ee.30ada",
"type": "rpi-gpio out",
"z": "3d58b8e8.2450c8",
"name": "Fuel Solenoid",
"pin": "4",
"set": true,
"level": "1",
"freq": "",
"out": "out",
"bcm": true,
"x": 1200,
"y": 500,
"wires": []
},
{
"id": "ca6a2a2d.30daa8",
"type": "rpi-gpio out",
"z": "3d58b8e8.2450c8",
"name": "Starter Solenoid",
"pin": "27",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 1220,
"y": 580,
"wires": []
},
{
"id": "26449b3a.09aa24",
"type": "debug",
"z": "3d58b8e8.2450c8",
"name": "detectstarttest",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1060,
"y": 880,
"wires": []
},
{
"id": "38613394.636ebc",
"type": "function",
"z": "3d58b8e8.2450c8",
"name": "Detect Start Logic",
"func": "//var numoftics = 0;\n//var timerstopped = false;\n//var detectstart = 0;\nvar started = 2;\n\ncontext.set('timeroff', false);\ncontext.set('detectstart', 0);\ncontext.set('ticksleft',6)\n\n// check for timer running state\nif (msg.topic == \"countdown\") {\n if (msg.payload)\n {\n msg.payload = 0;\n return msg;\n }\n }\n \n \n// check for GPIO input pin\n if (msg.topic == \"detectstart\")\n {\n if (msg.payload == 1)\n {\n return msg;\n }\n }\n ",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 850,
"y": 820,
"wires": [
[
"26449b3a.09aa24",
"50c46dc9.cc5794"
]
]
},
{
"id": "78d448cb.4837d8",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "detectstarttopic",
"rules": [
{
"t": "set",
"p": "topic",
"pt": "msg",
"to": "detectstart",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 600,
"y": 860,
"wires": [
[
"38613394.636ebc",
"9478aa1d.e9eed8"
]
]
},
{
"id": "9478aa1d.e9eed8",
"type": "debug",
"z": "3d58b8e8.2450c8",
"name": "detectifstarted",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 800,
"y": 880,
"wires": []
},
{
"id": "24cc14d0.0f3f8c",
"type": "comment",
"z": "3d58b8e8.2450c8",
"name": "Blynk Push Button to start/stop the generator",
"info": "",
"x": 510,
"y": 240,
"wires": []
},
{
"id": "a78477f5.d38358",
"type": "comment",
"z": "3d58b8e8.2450c8",
"name": "Set properties on the Blynk Widgets",
"info": "",
"x": 880,
"y": 220,
"wires": []
},
{
"id": "68eef0c5.19413",
"type": "comment",
"z": "3d58b8e8.2450c8",
"name": "GPIO Read Pin",
"info": "GPIO read pin, if it sees voltage the generator is making power and has started\nwill send a message at every state change so low to high generates a message, high to low generates message",
"x": 380,
"y": 1020,
"wires": []
},
{
"id": "b997f1a5.906a2",
"type": "comment",
"z": "3d58b8e8.2450c8",
"name": "GPIO Out to relays",
"info": "",
"x": 1330,
"y": 400,
"wires": []
},
{
"id": "7ab94a03.74cc84",
"type": "comment",
"z": "3d58b8e8.2450c8",
"name": "Countdown timer",
"info": "will start or stop at every incoming message so if stopped will start running, if running will stop",
"x": 640,
"y": 560,
"wires": []
},
{
"id": "50c46dc9.cc5794",
"type": "switch",
"z": "3d58b8e8.2450c8",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "0",
"vt": "num"
},
{
"t": "eq",
"v": "1",
"vt": "num"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 1050,
"y": 820,
"wires": [
[],
[
"ffa903de.f61e7"
]
]
},
{
"id": "ffa903de.f61e7",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1100,
"y": 720,
"wires": [
[]
]
},
{
"id": "94a87512.2c4ac8",
"type": "countdown",
"z": "3d58b8e8.2450c8",
"name": "",
"topic": "countdown",
"payloadTimerStart": "false",
"payloadTimerStartType": "bool",
"payloadTimerStop": "true",
"payloadTimerStopType": "bool",
"timer": "8",
"resetWhileRunning": false,
"outputOnReset": false,
"setTimeToNewWhileRunning": true,
"startCountdownOnControlMessage": true,
"x": 610,
"y": 620,
"wires": [
[
"38613394.636ebc"
],
[]
]
},
{
"id": "6199fdbdc0fd5f77",
"type": "blynk-iot-style-btn",
"z": "3d58b8e8.2450c8",
"name": "Start Generator",
"pin": "0",
"prop": "0",
"onlabel": "ON",
"offlabel": "OFF",
"oncolor": "#000000",
"onbackcolor": "#28da1b",
"offcolor": "#ffffff",
"offbackcolor": "#b32929",
"client": "70a09ac9323bb2d0",
"x": 520,
"y": 380,
"wires": [
[
"ac099a01.803be8",
"94a87512.2c4ac8"
]
]
},
{
"id": "5d87086562907a0d",
"type": "blynk-iot-out-set-property",
"z": "3d58b8e8.2450c8",
"name": "",
"pin": "1",
"pinmode": "1",
"prop": "bycode",
"client": "70a09ac9323bb2d0",
"x": 1100,
"y": 400,
"wires": []
},
{
"id": "1d50ec0c8fdc80e5",
"type": "blynk-iot-out-write",
"z": "3d58b8e8.2450c8",
"name": "",
"pin": "1",
"pinmode": 0,
"client": "70a09ac9323bb2d0",
"x": 1060,
"y": 340,
"wires": []
},
{
"id": "092e9b42fc3005ae",
"type": "debug",
"z": "3d58b8e8.2450c8",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1880,
"y": 600,
"wires": []
},
{
"id": "5a332cd8f9916281",
"type": "rpi-gpio out",
"z": "3d58b8e8.2450c8",
"name": "Relay Power",
"pin": "23",
"set": "",
"level": "0",
"freq": "",
"out": "out",
"bcm": true,
"x": 390,
"y": 480,
"wires": []
},
{
"id": "61f4b35073197dab",
"type": "ui_switch",
"z": "3d58b8e8.2450c8",
"name": "",
"label": "Relay Control",
"tooltip": "",
"group": "4576ca6a0f0252c0",
"order": 2,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "true",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "false",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"className": "",
"x": 220,
"y": 440,
"wires": [
[
"5a332cd8f9916281"
]
]
},
{
"id": "4e18b2b0b2767674",
"type": "ui_switch",
"z": "3d58b8e8.2450c8",
"name": "Fuel Solenoid Switch",
"label": "Fuel Solenoid",
"tooltip": "",
"group": "4576ca6a0f0252c0",
"order": 3,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "false",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "true",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"className": "",
"x": 860,
"y": 500,
"wires": [
[
"610241ee.30ada",
"9ea88c5a1b6f594d"
]
]
},
{
"id": "7ab4dca25d03475b",
"type": "ui_switch",
"z": "3d58b8e8.2450c8",
"name": "",
"label": "Start Generator",
"tooltip": "",
"group": "4576ca6a0f0252c0",
"order": 1,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "false",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "true",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"className": "",
"x": 220,
"y": 620,
"wires": [
[
"b98c5bbae754d6d8"
]
]
},
{
"id": "c71387aaaad942fc",
"type": "ui_switch",
"z": "3d58b8e8.2450c8",
"name": "Starter Solenoid Switch",
"label": "Starter Solenoid",
"tooltip": "",
"group": "4576ca6a0f0252c0",
"order": 4,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "topic",
"topicType": "msg",
"style": "",
"onvalue": "false",
"onvalueType": "bool",
"onicon": "",
"oncolor": "",
"offvalue": "true",
"offvalueType": "bool",
"officon": "",
"offcolor": "",
"animate": false,
"className": "",
"x": 890,
"y": 600,
"wires": [
[
"ca6a2a2d.30daa8",
"9224c15d7ab65d65"
]
]
},
{
"id": "3026419d18073dd0",
"type": "delay",
"z": "3d58b8e8.2450c8",
"name": "",
"pauseType": "delay",
"timeout": "3",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 360,
"y": 860,
"wires": [
[
"c71387aaaad942fc",
"85ad5f23428f04e6"
]
]
},
{
"id": "b98c5bbae754d6d8",
"type": "function",
"z": "3d58b8e8.2450c8",
"name": "function 1",
"func": "if (msg.payload == false){\n return [msg,null]\n}\n\nelse {\n return [null,msg]\n}\n",
"outputs": 2,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 160,
"y": 740,
"wires": [
[
"3026419d18073dd0",
"4e18b2b0b2767674"
],
[
"4e18b2b0b2767674"
]
]
},
{
"id": "85ad5f23428f04e6",
"type": "delay",
"z": "3d58b8e8.2450c8",
"name": "",
"pauseType": "delay",
"timeout": "10",
"timeoutUnits": "seconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 440,
"y": 960,
"wires": [
[
"e1a80acd7d7971ca"
]
]
},
{
"id": "e1a80acd7d7971ca",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 620,
"y": 1040,
"wires": [
[
"c71387aaaad942fc"
]
]
},
{
"id": "3c193c98b13a0380",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "red",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1460,
"y": 460,
"wires": [
[
"092e9b42fc3005ae",
"8c83d02f1bd4012a"
]
]
},
{
"id": "ae2855e3b0201e30",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "green",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1440,
"y": 500,
"wires": [
[
"092e9b42fc3005ae",
"8c83d02f1bd4012a"
]
]
},
{
"id": "9ea88c5a1b6f594d",
"type": "switch",
"z": "3d58b8e8.2450c8",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "num"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1190,
"y": 460,
"wires": [
[
"3c193c98b13a0380"
],
[
"ae2855e3b0201e30"
]
]
},
{
"id": "fc26ab65348f94b4",
"type": "ui_template",
"z": "3d58b8e8.2450c8",
"group": "6cab795dddec047f",
"name": "Starter Solenoid Status",
"order": 4,
"width": "1",
"height": "1",
"format": "<div id=\"indicator\"></div>\n\n<style>\n #indicator {\n width: 15px;\n height: 15px;\n background-color: {{msg.payload}};\n border-radius: 50%;\n margin: auto;\n }\n</style>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 1670,
"y": 660,
"wires": [
[]
]
},
{
"id": "a5355afd78718b3f",
"type": "ui_template",
"z": "3d58b8e8.2450c8",
"group": "6cab795dddec047f",
"name": "Relay Status",
"order": 2,
"width": "1",
"height": "1",
"format": "<div id=\"indicator\"></div>\n\n<style>\n #indicator {\n width: 15px;\n height: 15px;\n background-color: {{msg.payload}};\n border-radius: 50%;\n margin: auto;\n }\n</style>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 390,
"y": 540,
"wires": [
[]
]
},
{
"id": "9224c15d7ab65d65",
"type": "switch",
"z": "3d58b8e8.2450c8",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1250,
"y": 640,
"wires": [
[
"5d42d0e31477d009"
],
[
"eab41766263e187f"
]
]
},
{
"id": "5d42d0e31477d009",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "red",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1440,
"y": 600,
"wires": [
[
"fc26ab65348f94b4",
"1c6e41b2c7a48811"
]
]
},
{
"id": "eab41766263e187f",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "green",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 1440,
"y": 680,
"wires": [
[
"fc26ab65348f94b4",
"1c6e41b2c7a48811"
]
]
},
{
"id": "ef3b61ecf2dc0994",
"type": "ui_template",
"z": "3d58b8e8.2450c8",
"group": "6cab795dddec047f",
"name": "Generator Started",
"order": 1,
"width": "1",
"height": "1",
"format": "<div id=\"indicator\"></div>\n\n<style>\n #indicator {\n width: 15px;\n height: 15px;\n background-color: {{msg.payload}};\n border-radius: 50%;\n margin: auto;\n }\n</style>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 870,
"y": 1120,
"wires": [
[]
]
},
{
"id": "5e98c41c16ceeca5",
"type": "switch",
"z": "3d58b8e8.2450c8",
"name": "",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 450,
"y": 1120,
"wires": [
[
"72df120c5e6cc2e2"
],
[
"8318dc8b4f84c3ac"
]
]
},
{
"id": "72df120c5e6cc2e2",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "green",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 640,
"y": 1100,
"wires": [
[
"ef3b61ecf2dc0994"
]
]
},
{
"id": "8318dc8b4f84c3ac",
"type": "change",
"z": "3d58b8e8.2450c8",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "red",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 640,
"y": 1160,
"wires": [
[
"ef3b61ecf2dc0994"
]
]
},
{
"id": "1c6e41b2c7a48811",
"type": "debug",
"z": "3d58b8e8.2450c8",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1880,
"y": 720,
"wires": []
},
{
"id": "8c83d02f1bd4012a",
"type": "ui_template",
"z": "3d58b8e8.2450c8",
"group": "6cab795dddec047f",
"name": "Fuel Solenoid Status",
"order": 3,
"width": 0,
"height": 0,
"format": "<div id=\"indicator\"></div>\n\n<style>\n #indicator {\n width: 15px;\n height: 15px;\n\n background-color: {\n {\n msg.payload\n }\n }\n\n ;\n border-radius: 50%;\n margin: auto;\n }\n</style>",
"storeOutMessages": true,
"fwdInMessages": true,
"resendOnRefresh": true,
"templateScope": "local",
"className": "",
"x": 1780,
"y": 480,
"wires": [
[]
]
},
{
"id": "70a09ac9323bb2d0",
"type": "blynk-iot-client",
"name": "Blynk IOT",
"path": "blynk.cloud",
"key": "v4S_CT5Q7shSbXuhwUlh4tzHpi081zpz",
"tmpl": "TMPL2qyPweHl_",
"dbg_all": false,
"dbg_log": false,
"dbg_prop": false,
"dbg_sync": false,
"dbg_low": false,
"dbg_pins": "",
"multi_cmd": false,
"enabled": true
},
{
"id": "4576ca6a0f0252c0",
"type": "ui_group",
"name": "Generator",
"tab": "35a38880037d5deb",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "6cab795dddec047f",
"type": "ui_group",
"name": "Status",
"tab": "35a38880037d5deb",
"order": 3,
"disp": true,
"width": "1",
"collapse": false,
"className": ""
},
{
"id": "35a38880037d5deb",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"disabled": false,
"hidden": false
}
]