Fikke en løsning fra Node RED forumet, så da har jeg endelig varsling på avfall igjen 🙂
[
{
"id": "cc42ae3.94b225",
"type": "function",
"z": "a318c51d.29a138",
"name": "",
"func": "var now = new Date();\n\nvar data = msg.payload;\nif(!data || !Array.isArray(data) || !data.length) {\n node.warn(\"no data\");\n return null; //halt flow\n}\n\n//filter the data to today or later AND where name == topic\nvar filtered = data.filter(e => new Date(e.date) >= now && e.name == msg.topic )\n\n//a compare function\nfunction compare( a, b ) {\n if ( a.date < b.date ) return -1;\n if ( a.date > b.date ) return 1;\n return 0;\n}\n//sort data using the compare function\nvar dataSorted = filtered.sort(compare);\n\n//grab the top (earliest) entry - put it in payload\nmsg.payload = dataSorted[0];\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 800,
"y": 120,
"wires": [
[
"b10b1e1e.bb47f"
]
]
}
]