Dear All,
I'm trying to send a msg which comes from the second input to a function node if the first input to the node is "true" from a Boolean gate ultimate node.
I also need to make the function node not send a message until both inputs have arrived and send only one message per 24h (though I could do this with a delay node after the function node I think).
Sorry for this pretty basic question but I've trawled the web and can't find a solution to this (seemingly!) Very simple operation.
My test flow is attached below:
[
{
"id": "a0da04ce2ca2ea94",
"type": "tab",
"label": "Test",
"disabled": false,
"info": "",
"env": []
},
{
"id": "681f07f50a06f37d",
"type": "function",
"z": "a0da04ce2ca2ea94",
"name": "If This Is The Min Block Time",
"func": "if (msg.payload[0] = msg.payload[1]) {\n msg.payload = \"true\";\n}\nelse {\n msg.payload =\"false\";\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 400,
"y": 140,
"wires": [
[
"88fa2461164a749b",
"343017c6e242ede5"
]
]
},
{
"id": "343017c6e242ede5",
"type": "debug",
"z": "a0da04ce2ca2ea94",
"name": "Is It The Time?",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 680,
"y": 100,
"wires": []
},
{
"id": "88fa2461164a749b",
"type": "FilterUltimate",
"z": "a0da04ce2ca2ea94",
"name": "If True",
"payloadPropName": "payload",
"translatorConfig": "",
"x": 650,
"y": 140,
"wires": [
[
"3044b872b070af0a"
],
[]
]
},
{
"id": "666c10679f5ef745",
"type": "debug",
"z": "a0da04ce2ca2ea94",
"name": "debug 4",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1120,
"y": 160,
"wires": []
},
{
"id": "3044b872b070af0a",
"type": "function",
"z": "a0da04ce2ca2ea94",
"name": "function 3",
"func": "if (msg.payload[0] == \"true\") {\n msg.payload = msg.payload[1]\n}\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 160,
"wires": [
[
"666c10679f5ef745"
]
]
},
{
"id": "ffd1fdbbf83b213b",
"type": "function",
"z": "a0da04ce2ca2ea94",
"name": "Add Msg To Inverter Payload",
"func": "msg.payload = {\n 'value': msg.payload,\n 'fc': 6,\n 'unitid': 1,\n 'address': 43141,\n 'quantity': 1\n }\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 480,
"y": 200,
"wires": [
[
"3044b872b070af0a"
]
]
},
{
"id": "a88a39fcbfd50be6",
"type": "inject",
"z": "a0da04ce2ca2ea94",
"name": "Current Time",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "time",
"payload": "03:00",
"payloadType": "str",
"x": 130,
"y": 100,
"wires": [
[
"681f07f50a06f37d"
]
]
},
{
"id": "bdbaba788bdecab3",
"type": "inject",
"z": "a0da04ce2ca2ea94",
"name": "Cheapest Block",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "03:00",
"payloadType": "str",
"x": 140,
"y": 140,
"wires": [
[
"681f07f50a06f37d"
]
]
},
{
"id": "6d85670bf6c0fb0d",
"type": "inject",
"z": "a0da04ce2ca2ea94",
"name": "Cheapest Time (Hours)",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "cheapest hours",
"payload": "03",
"payloadType": "str",
"x": 160,
"y": 200,
"wires": [
[
"ffd1fdbbf83b213b"
]
]
}
]
I can't get this to output just the payload from the 'Add Msg To Inverter Payload' node to debug 4 ONLY when the boolean gate sends 'true'. I can then limit it to one message per 24h with a delay node but for the time being I feel my skills are wholly lacking on javascript coding to make the 'function 3' node perform this task.
Very grateful for any help you can offer,
James