I am currently using Node RED and want to make a Datepicker Range.
My goal is:
Use the two selected Dates from the two "Datepicker"-Nodes to display a certain time interval from my database.
Here is my Flow in JSON-Code:
(Be aware that you will need to install "node-red-contrib-postgresql" and "node-red-dashboard" beforhand)
[
{
"id": "df8b8a9806f4a546",
"type": "tab",
"label": "Flow 2",
"disabled": false,
"info": "",
"env": []
},
{
"id": "0623165a65c01c00",
"type": "function",
"z": "df8b8a9806f4a546",
"name": "Processing Datepicker Output",
"func": "if (msg.topic === "Datepicker_Von") {n // Hier verarbeiten Sie den Wert des ersten Datepicker-Noden var date1 = msg.payload;n // Führen Sie weitere Verarbeitungen für Datepicker1 durchn} else if (msg.topic === "Datepicker_Bis") {n // Hier verarbeiten Sie den Wert des zweiten Datepicker-Noden var date2 = msg.payload;n // Führen Sie weitere Verarbeitungen für Datepicker2 durchn}nnmsg.params = [date1, date2];nnn/*nvar date1 = msg.payload[0].Datepicker_Von;nvar date2 = msg.payload[1].selectedDate;nnif(date1 && date2){n msg.payload = {date1, date2};n return msg;nn}n*/",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 870,
"y": 780,
"wires": [
[
"5ca2e58ccda4292e",
"5dbeae4a01d86c01"
]
]
},
{
"id": "35a5189090d65418",
"type": "postgresql",
"z": "df8b8a9806f4a546",
"name": "Abfrage_Kalender",
"query": "SELECT wert, datum_mnFROM alle.aggregatparameterwerte1minnWHERE DATE(datum_m) BETWEEN $1 AND $2n",
"postgreSQLConfig": "7a4e4f0f64750523",
"split": false,
"rowsPerMsg": 1,
"outputs": 1,
"x": 1410,
"y": 780,
"wires": [
[
"c7ef1139c1942183"
]
]
},
{
"id": "c7ef1139c1942183",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 10",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1740,
"y": 780,
"wires": []
},
{
"id": "5ca2e58ccda4292e",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 11",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1200,
"y": 940,
"wires": []
},
{
"id": "1c2689ab7eb8477d",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 12",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 780,
"y": 480,
"wires": []
},
{
"id": "5906020c8eecbd4b",
"type": "debug",
"z": "df8b8a9806f4a546",
"name": "debug 13",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 700,
"y": 1040,
"wires": []
},
{
"id": "95076555af56bb28",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 2",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"topic": "Datepicker_Bis",
"topicType": "str",
"className": "",
"x": 510,
"y": 900,
"wires": [
[
"5906020c8eecbd4b",
"0623165a65c01c00"
]
]
},
{
"id": "981a649d06af8b02",
"type": "ui_date_picker",
"z": "df8b8a9806f4a546",
"name": "",
"label": "Datepicker 1",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"topic": "Datepicker_Von",
"topicType": "str",
"className": "",
"x": 510,
"y": 620,
"wires": [
[
"1c2689ab7eb8477d",
"0623165a65c01c00"
]
]
},
{
"id": "5dbeae4a01d86c01",
"type": "ui_button",
"z": "df8b8a9806f4a546",
"name": "",
"group": "c69e5a41.8b69a8",
"order": 2,
"width": 0,
"height": 0,
"passthru": false,
"label": "button",
"tooltip": "",
"color": "",
"bgcolor": "",
"className": "",
"icon": "",
"payload": "",
"payloadType": "str",
"topic": "Datepicker_Von",
"topicType": "msg",
"x": 1150,
"y": 780,
"wires": [
[
"35a5189090d65418"
]
]
},
{
"id": "7a4e4f0f64750523",
"type": "postgreSQLConfig",
"name": "",
"host": "127.0.0.1",
"hostFieldType": "str",
"port": "5432",
"portFieldType": "num",
"database": "dme_lokal",
"databaseFieldType": "str",
"ssl": "false",
"sslFieldType": "bool",
"applicationName": "",
"applicationNameType": "str",
"max": "10",
"maxFieldType": "num",
"idle": "1000",
"idleFieldType": "num",
"connectionTimeout": "10000",
"connectionTimeoutFieldType": "num",
"user": "umeadmin",
"userFieldType": "str",
"password": "umewp1",
"passwordFieldType": "str"
},
{
"id": "c69e5a41.8b69a8",
"type": "ui_group",
"name": "Default",
"tab": "1013c4a0.9de38c",
"order": 1,
"disp": true,
"width": "6",
"collapse": false,
"className": ""
},
{
"id": "1013c4a0.9de38c",
"type": "ui_tab",
"name": "Home",
"icon": "dashboard",
"order": 1,
"disabled": false,
"hidden": false
}
]
As you can see I tried to connect the two "Datepicker"-Nodes with a "Function"-Node.
The problem is that the "Function"-Node doesen’t recieve the two dates at the same time. The flow that is posted here is the latest variant that I tried and failed.
2
Answers
YES it worked! But there is a small detail that needs to be paid attention to. In the topic area of each "Datepicker"-Node you need to differentiate the topic with a "/"
Example:
Topic of Datepicker1:
datepicker/1
Topic of Datepicker2:
datepicker/2
Also there needs to be taken note of that both topics of the datepickers need to be in format "string"
Here is the config-Tab for the "Datepicker"-Node with the Name "Datepicker 1" Write the exact same thing into the second datepicker but replace all "1" with "2"
Datepicker 1
Here the JSON-Code if other people want to try for them selfs :D
Thanks for helping me! :D
You need to look at the join node, place it before the function node and configure it to wait for 2 inputs before sending the joined result.