I have 2 inputs (Int32), one displays "left time in min" and one displays "left time in hours". "General left time" is both, X hours and Y min.
So far i show both separately in DB2.0, but i would like to have them as one output ("HH:XX h")
I already managed to combine both into one output and also build a function that it only works when both inputs send a signal each.
I added a change node to replace the "," between both inputs with ":" but it doesn't work.
Please feel free to also look over the rest of what i built, maybe there is an easier way?
I don't know how to add a flow so i just copy the json.
[
{
"id": "5cc0ae9525d73429",
"type": "inject",
"z": "5407f6cf6313c6cb",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "15",
"payloadType": "num",
"x": 370,
"y": 1160,
"wires": [
[
"ae4350a4deb5081a"
]
]
},
{
"id": "3ddb7d3c8b7b7f28",
"type": "inject",
"z": "5407f6cf6313c6cb",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "25",
"payloadType": "num",
"x": 370,
"y": 1200,
"wires": [
[
"13ab6ef759f644e2"
]
]
},
{
"id": "47a99f14ac4c4260",
"type": "debug",
"z": "5407f6cf6313c6cb",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1300,
"y": 1140,
"wires": []
},
{
"id": "f83bcce0ab8cdc65",
"type": "template",
"z": "5407f6cf6313c6cb",
"name": "Add Suffix",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{{ payload }} h",
"output": "str",
"x": 1150,
"y": 1140,
"wires": [
[
"47a99f14ac4c4260"
]
]
},
{
"id": "7284d2c28c8c819c",
"type": "function",
"z": "5407f6cf6313c6cb",
"name": "msg.part 1 & msg.part2 vorhanden?",
"func": "if (!context.parts) {\n context.parts = {};\n}\n\n// Speichere die Teile in Kontextvariablen\ncontext.parts[msg.part] = msg.payload;\n\n// Wenn beide Teile vorhanden sind, sende die kombinierte Nachricht\nif (context.parts[1] !== undefined && context.parts[2] !== undefined) {\n msg.payload = [context.parts[1], context.parts[2]];\n \n // Lösche die gespeicherten Teile, um doppelte Nachrichten zu vermeiden\n context.parts = {};\n \n return msg;\n}",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 780,
"y": 1140,
"wires": [
[
"582b2ba42b7e1d89"
]
]
},
{
"id": "582b2ba42b7e1d89",
"type": "change",
"z": "5407f6cf6313c6cb",
"name": ", zu :",
"rules": [
{
"t": "change",
"p": "payload",
"pt": "msg",
"from": ",",
"fromt": "str",
"to": ":",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 990,
"y": 1200,
"wires": [
[
"f83bcce0ab8cdc65"
]
]
},
{
"id": "ae4350a4deb5081a",
"type": "function",
"z": "5407f6cf6313c6cb",
"name": "function 1",
"func": "msg.part = 1;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 1160,
"wires": [
[
"7284d2c28c8c819c"
]
]
},
{
"id": "13ab6ef759f644e2",
"type": "function",
"z": "5407f6cf6313c6cb",
"name": "function 2",
"func": "msg.part = 2;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 1200,
"wires": [
[
"7284d2c28c8c819c"
]
]
}
]