I modified the code because the ‹ delay › nodes were in milliseconds instead of minutes…oops, my bad
! And I added a ‹ send time › function to track the time at which the « sunrise » message is sent for the second time (the first at 00:01), just duplicate to track the others.
[details=« Flow code »]
[
{
"id": "7ff8481b0e530218",
"type": "tab",
"label": "Suncalc API",
"disabled": false,
"info": "",
"env": []
},
{
"id": "467565bd915a2a8d",
"type": "group",
"z": "7ff8481b0e530218",
"name": "Suncalc API",
"style": {
"stroke": "#000000",
"fill": "#e3f3d3",
"label": true
},
"nodes": [
"eae0976220b585b3",
"5dda4437af0bff5e",
"9ed546b6886bbafa",
"f6ea59633d3bb98b",
"e5be0b9d45a8b6c2",
"38e643d99efa7a95",
"846f914fd081c13f",
"152afaf0fdc6be38",
"59307f7f63590e5d",
"838df80a9f965a6d",
"a4397d1a98150a4d",
"5d1de6bc5497c087",
"c2b15889e9096be1",
"b8a6dca76c04f480",
"3a99ad9a2f752241",
"3ea4979d2eaf146b",
"901f952626786b11",
"1d040814b1befb3a",
"8f7e50836226d1ee",
"8c49858b8bbfe11c",
"9e462a3d9f69bee0",
"048c1578dc7d13d5",
"bee1fb0b9897f334",
"3dd556977ebeb003",
"17d36d7e51f3c5aa",
"89002c75327e8e5f",
"2e8b434a55627e7a",
"21097eb9222e6af0",
"e389303bb28be230"
],
"x": 54,
"y": 79,
"w": 1312,
"h": 722
},
{
"id": "eae0976220b585b3",
"type": "inject",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "00 00 * * *",
"once": true,
"onceDelay": "1",
"topic": "",
"payload": "",
"payloadType": "date",
"x": 170,
"y": 400,
"wires": [
[
"5dda4437af0bff5e"
]
]
},
{
"id": "5dda4437af0bff5e",
"type": "http request",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "api.sunrise-sunset.org",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.sunrise-sunset.org/json?lat={42.555}&lng={2.833}&date=today",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 220,
"y": 460,
"wires": [
[
"9ed546b6886bbafa",
"38e643d99efa7a95",
"846f914fd081c13f",
"152afaf0fdc6be38",
"59307f7f63590e5d",
"838df80a9f965a6d",
"a4397d1a98150a4d",
"5d1de6bc5497c087",
"c2b15889e9096be1",
"b8a6dca76c04f480",
"3a99ad9a2f752241"
]
]
},
{
"id": "9ed546b6886bbafa",
"type": "debug",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "auto",
"x": 470,
"y": 460,
"wires": []
},
{
"id": "f6ea59633d3bb98b",
"type": "debug",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "debug 3",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload",
"statusType": "msg",
"x": 700,
"y": 120,
"wires": []
},
{
"id": "e5be0b9d45a8b6c2",
"type": "mqtt out",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "Publish to MQTT broker IP Gladys:1883",
"topic": "",
"qos": "",
"retain": "",
"respTopic": "",
"contentType": "",
"userProps": "",
"correl": "",
"expiry": "",
"broker": "f4ab211ed11dc81c",
"x": 1190,
"y": 460,
"wires": []
},
{
"id": "38e643d99efa7a95",
"type": "function",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "sunrise",
"func": "var topic = msg.topic;\nvar msg = msg.payload;\n\nmsg.topic = \"gladys/master/device/mqtt:suncalc/feature/mqtt:sunrise/text\";\n\n// time string in AM/PM format\nvar timeString = msg.results.sunrise;\n\n// Convert the string to a Date object\nvar date = new Date(\"2000-01-01 \" + timeString);\n\n// Format the time in 24-hour format\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\n\n// add a zero in front of the digits if necessary\nhours = hours < 10 ? \"0\" + hours : hours;\nminutes = minutes < 10 ? \"0\" + minutes : minutes;\n\n// Display the time in 24-hour format\nvar formattedTime = hours + \":\" + minutes;\n\n// send in 24h format\nmsg.payload = formattedTime;\n\n// calculate the delay after midnight in minutes to send the message\nvar delai = (hours * 60) + minutes + 1;\nmsg.delay = delai;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 160,
"wires": [
[
"e5be0b9d45a8b6c2",
"f6ea59633d3bb98b",
"3ea4979d2eaf146b",
"2e8b434a55627e7a"
]
]
},
{
"id": "846f914fd081c13f",
"type": "function",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "sunset",
"func": "var topic = msg.topic;\nvar msg = msg.payload;\n\nmsg.topic = \"gladys/master/device/mqtt:suncalc/feature/mqtt:sunset/text\";\n\n\n// time string in AM/PM format\nvar timeString =msg.results.sunset;\n\n// Convert the string to a Date object\nvar date = new Date(\"2000-01-01 \" + timeString);\n\n// Format the time in 24-hour format\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\n\n// add a zero in front of the digits if necessary\nhours = hours < 10 ? \"0\" + hours : hours;\nminutes = minutes < 10 ? \"0\" + minutes : minutes;\n\n// Display the time in 24-hour format\nvar formattedTime = hours + \":\" + minutes;\n\n// send in 24h format\nmsg.payload = formattedTime;\n\n// calculate the delay after midnight in minutes to send the message\nvar delai = hours *60 + minutes + 1;\nmsg.delay = delai;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 450,
"y": 220,
"wires": [
[
"e5be0b9d45a8b6c2",
"901f952626786b11"
]
]
},
{
"id": "152afaf0fdc6be38",
"type": "function",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "solar_noon",
"func": "var topic = msg.topic;\nvar msg = msg.payload;\n\nmsg.topic = \"gladys/master/device/mqtt:suncalc/feature/mqtt:solar_noon/text\";\n\n\n// time string in AM/PM format\nvar timeString =msg.results.solar_noon;\n\n// Convert the string to a Date object\nvar date = new Date(\"2000-01-01 \" + timeString);\n\n// Format the time in 24-hour format\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\n\n// add a zero in front of the digits if necessary\nhours = hours < 10 ? \"0\" + hours : hours;\nminutes = minutes < 10 ",? "0" + minutes : minutes;
// Display time in 24-hour format
var formattedTime = hours + ":" + minutes;
// Send in 24h format
msg.payload = formattedTime;
// Calculate the delay after midnight in minutes to send the message
var delai = hours *60 + minutes + 1;
msg.delay = delai;
return msg;"},? \"0\" + hours : hours;\nminutes = minutes < 10 ? \"0\" + minutes : minutes;\n\n// Display time in 24-hour format\nvar formattedTime = hours + \":\" + minutes;\n\n// send in 24h format\nmsg.payload = formattedTime;\n\n// calculate the delay after midnight in minutes to send the message\nvar delai = hours *60 + minutes + 1;\nmsg.delay = delai;\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 700,
"wires": [
[
"e5be0b9d45a8b6c2",
"048c1578dc7d13d5"
]
]
},
{
"id": "3a99ad9a2f752241",
"type": "function",
"z": "7ff8481b0e530218",
"g": "467565bd915a2a8d",
"name": "astronomical_twilight_end",
"func": "var topic = msg.topic;\nvar msg = msg.payload;\n\nmsg.topic = \"gladys/master/device/mqtt:suncalc/feature/mqtt:astronomical_twilight_end/text\";\n\n// time string in AM/PM format\nvar timeString =msg.results.astronomical_twilight_end;\n\n// Convert the string to a Date object\nvar date = new Date(\"2000-01-01 \" + timeString);\n\n// Format the time in 24-hour format\nvar hours = date.getHours();\nvar minutes = date.getMinutes();\n\n// add a leading zero if necessary\nhours = hours < 10 ? \"0\" + hours : hours;\nminutes = minutes < 10