Extract time and send a output at this time

Hi!
At the picture here, i get a date and time in a payload.
Is there a way to just extract the time and make an output to activate at this specific time?
image

my approach would be to use a node called Cron Plus that allows you to create dynamic schedules

with a little bit of javascript you can modify the datetime to Cron format and construct a msg to create that dynamic schedule

Test flow : (based on your previous thread)

[{"id":"ab7e3bcb993b03b8","type":"inject","z":"4895ea10b4ee9ead","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"viewer\":{\"homes\":[{\"currentSubscription\":{\"priceInfo\":{\"current\":{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},\"today\":[{\"total\":0.6721,\"energy\":0.5181,\"tax\":0.154,\"startsAt\":\"2021-09-06T00:00:00.000+02:00\"},{\"total\":0.6608,\"energy\":0.509,\"tax\":0.1518,\"startsAt\":\"2021-09-06T01:00:00.000+02:00\"},{\"total\":0.6603,\"energy\":0.5086,\"tax\":0.1517,\"startsAt\":\"2021-09-06T02:00:00.000+02:00\"},{\"total\":0.6641,\"energy\":0.5117,\"tax\":0.1524,\"startsAt\":\"2021-09-06T03:00:00.000+02:00\"},{\"total\":0.6731,\"energy\":0.5189,\"tax\":0.1542,\"startsAt\":\"2021-09-06T04:00:00.000+02:00\"},{\"total\":0.9165,\"energy\":0.7136,\"tax\":0.2029,\"startsAt\":\"2021-09-06T05:00:00.000+02:00\"},{\"total\":1.5177,\"energy\":1.1946,\"tax\":0.3231,\"startsAt\":\"2021-09-06T06:00:00.000+02:00\"},{\"total\":1.899,\"energy\":1.4996,\"tax\":0.3994,\"startsAt\":\"2021-09-06T07:00:00.000+02:00\"},{\"total\":2.0578,\"energy\":1.6266,\"tax\":0.4312,\"startsAt\":\"2021-09-06T08:00:00.000+02:00\"},{\"total\":1.7942,\"energy\":1.4158,\"tax\":0.3784,\"startsAt\":\"2021-09-06T09:00:00.000+02:00\"},{\"total\":1.6516,\"energy\":1.3017,\"tax\":0.3499,\"startsAt\":\"2021-09-06T10:00:00.000+02:00\"},{\"total\":1.4313,\"energy\":1.1254,\"tax\":0.3059,\"startsAt\":\"2021-09-06T11:00:00.000+02:00\"},{\"total\":1.3661,\"energy\":1.0733,\"tax\":0.2928,\"startsAt\":\"2021-09-06T12:00:00.000+02:00\"},{\"total\":1.2986,\"energy\":1.0193,\"tax\":0.2793,\"startsAt\":\"2021-09-06T13:00:00.000+02:00\"},{\"total\":1.3323,\"energy\":1.0462,\"tax\":0.2861,\"startsAt\":\"2021-09-06T14:00:00.000+02:00\"},{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},{\"total\":1.5488,\"energy\":1.2195,\"tax\":0.3293,\"startsAt\":\"2021-09-06T16:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T17:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T18:00:00.000+02:00\"},{\"total\":1.6558,\"energy\":1.3051,\"tax\":0.3507,\"startsAt\":\"2021-09-06T19:00:00.000+02:00\"},{\"total\":1.2656,\"energy\":0.9929,\"tax\":0.2727,\"startsAt\":\"2021-09-06T20:00:00.000+02:00\"},{\"total\":1.1671,\"energy\":0.9141,\"tax\":0.253,\"startsAt\":\"2021-09-06T21:00:00.000+02:00\"},{\"total\":0.9563,\"energy\":0.7454,\"tax\":0.2109,\"startsAt\":\"2021-09-06T22:00:00.000+02:00\"},{\"total\":0.6288,\"energy\":0.4834,\"tax\":0.1454,\"startsAt\":\"2021-09-06T23:00:00.000+02:00\"}],\"tomorrow\":[{\"total\":0.6308,\"energy\":0.4851,\"tax\":0.1457,\"startsAt\":\"2021-09-07T00:00:00.000+02:00\"},{\"total\":0.6263,\"energy\":0.4814,\"tax\":0.1449,\"startsAt\":\"2021-09-07T01:00:00.000+02:00\"},{\"total\":0.6249,\"energy\":0.4803,\"tax\":0.1446,\"startsAt\":\"2021-09-07T02:00:00.000+02:00\"},{\"total\":0.6241,\"energy\":0.4797,\"tax\":0.1444,\"startsAt\":\"2021-09-07T03:00:00.000+02:00\"},{\"total\":0.6293,\"energy\":0.4838,\"tax\":0.1455,\"startsAt\":\"2021-09-07T04:00:00.000+02:00\"},{\"total\":0.7142,\"energy\":0.5518,\"tax\":0.1624,\"startsAt\":\"2021-09-07T05:00:00.000+02:00\"},{\"total\":1.1434,\"energy\":0.8951,\"tax\":0.2483,\"startsAt\":\"2021-09-07T06:00:00.000+02:00\"},{\"total\":1.4823,\"energy\":1.1662,\"tax\":0.3161,\"startsAt\":\"2021-09-07T07:00:00.000+02:00\"},{\"total\":1.7308,\"energy\":1.3651,\"tax\":0.3657,\"startsAt\":\"2021-09-07T08:00:00.000+02:00\"},{\"total\":1.5923,\"energy\":1.2543,\"tax\":0.338,\"startsAt\":\"2021-09-07T09:00:00.000+02:00\"},{\"total\":1.4388,\"energy\":1.1315,\"tax\":0.3073,\"startsAt\":\"2021-09-07T10:00:00.000+02:00\"},{\"total\":1.4383,\"energy\":1.1311,\"tax\":0.3072,\"startsAt\":\"2021-09-07T11:00:00.000+02:00\"},{\"total\":1.362,\"energy\":1.07,\"tax\":0.292,\"startsAt\":\"2021-09-07T12:00:00.000+02:00\"},{\"total\":1.1805,\"energy\":0.9248,\"tax\":0.2557,\"startsAt\":\"2021-09-07T13:00:00.000+02:00\"},{\"total\":1.1298,\"energy\":0.8842,\"tax\":0.2456,\"startsAt\":\"2021-09-07T14:00:00.000+02:00\"},{\"total\":0.9907,\"energy\":0.773,\"tax\":0.2177,\"startsAt\":\"2021-09-07T15:00:00.000+02:00\"},{\"total\":0.9702,\"energy\":0.7566,\"tax\":0.2136,\"startsAt\":\"2021-09-07T16:00:00.000+02:00\"},{\"total\":1.0907,\"energy\":0.853,\"tax\":0.2377,\"startsAt\":\"2021-09-07T17:00:00.000+02:00\"},{\"total\":1.0866,\"energy\":0.8497,\"tax\":0.2369,\"startsAt\":\"2021-09-07T18:00:00.000+02:00\"},{\"total\":1.0081,\"energy\":0.7869,\"tax\":0.2212,\"startsAt\":\"2021-09-07T19:00:00.000+02:00\"},{\"total\":0.9414,\"energy\":0.7335,\"tax\":0.2079,\"startsAt\":\"2021-09-07T20:00:00.000+02:00\"},{\"total\":0.872,\"energy\":0.678,\"tax\":0.194,\"startsAt\":\"2021-09-07T21:00:00.000+02:00\"},{\"total\":0.5883,\"energy\":0.451,\"tax\":0.1373,\"startsAt\":\"2021-09-07T22:00:00.000+02:00\"},{\"total\":0.4366,\"energy\":0.3296,\"tax\":0.107,\"startsAt\":\"2021-09-07T23:00:00.000+02:00\"}]}}}]}}","payloadType":"json","x":130,"y":620,"wires":[["6068ec2576871871","6f82207b692dd1cf"]]},{"id":"6068ec2576871871","type":"debug","z":"4895ea10b4ee9ead","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":230,"y":560,"wires":[]},{"id":"6f82207b692dd1cf","type":"function","z":"4895ea10b4ee9ead","name":"","func":"let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today.slice(-5)\nlet tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow.slice(0, 5)\nlet total = today.concat(tomorrow)\nnode.warn(total);\n\nlet totalMinimum = today[0].total\nlet totalMinimumStartsAt;\n\ntotal.forEach(el => {\n    if (el.total < totalMinimum) {\n        totalMinimum = el.total;\n        totalMinimumStartsAt = el.startsAt;\n    }\n})\n\n\nmsg.payload = {\n    totalMinimum,\n    totalMinimumStartsAt\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":620,"wires":[["b1f094c1b38cb61b","12791505802fe0d3"]]},{"id":"b1f094c1b38cb61b","type":"debug","z":"4895ea10b4ee9ead","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":560,"wires":[]},{"id":"08fd97ed5d4aee8a","type":"cronplus","z":"4895ea10b4ee9ead","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":720,"y":620,"wires":[[]]},{"id":"12791505802fe0d3","type":"function","z":"4895ea10b4ee9ead","name":"Date to Cron","func":"const dateToCron = (date) => {\n    const seconds = date.getSeconds();\n    const minutes = date.getMinutes();\n    const hours = date.getHours();\n    const day = date.getDate();\n    const month = date.getMonth() + 1;\n    const year = date.getFullYear();\n\n    return `${seconds} ${minutes} ${hours} ${day} ${month} * ${year}`;\n};\n\nconst dateText = msg.payload.totalMinimumStartsAt;\nconst date = new Date(dateText);\n\nconst cron = dateToCron(date);\n\n// create Dynamic Cron Schedule\nmsg.payload = {\n    \"command\": \"add\",\n    \"name\": \"Dynamic Cron Schedule\",\n    \"expression\": cron,\n    \"expressionType\": \"cron\",\n    \"payloadType\": \"default\",\n    \"limit\": 1   \n}\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":620,"wires":[["704890d26877d232","08fd97ed5d4aee8a"]]},{"id":"704890d26877d232","type":"debug","z":"4895ea10b4ee9ead","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":650,"y":560,"wires":[]}]

ps. Im not sure about the timezone time conversion

Andy, clever demo :+1:

However, since the OP's date time is already correct format, we can simply add a date schedule (instead of parsing the date into a cron schedule)

The benefit of this is the +02:00 timezone offset is taken into account.

LLArKk8Djf

[{"id":"ab7e3bcb993b03b8","type":"inject","z":"5d3f964c.fef898","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"viewer\":{\"homes\":[{\"currentSubscription\":{\"priceInfo\":{\"current\":{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},\"today\":[{\"total\":0.6721,\"energy\":0.5181,\"tax\":0.154,\"startsAt\":\"2021-09-06T00:00:00.000+02:00\"},{\"total\":0.6608,\"energy\":0.509,\"tax\":0.1518,\"startsAt\":\"2021-09-06T01:00:00.000+02:00\"},{\"total\":0.6603,\"energy\":0.5086,\"tax\":0.1517,\"startsAt\":\"2021-09-06T02:00:00.000+02:00\"},{\"total\":0.6641,\"energy\":0.5117,\"tax\":0.1524,\"startsAt\":\"2021-09-06T03:00:00.000+02:00\"},{\"total\":0.6731,\"energy\":0.5189,\"tax\":0.1542,\"startsAt\":\"2021-09-06T04:00:00.000+02:00\"},{\"total\":0.9165,\"energy\":0.7136,\"tax\":0.2029,\"startsAt\":\"2021-09-06T05:00:00.000+02:00\"},{\"total\":1.5177,\"energy\":1.1946,\"tax\":0.3231,\"startsAt\":\"2021-09-06T06:00:00.000+02:00\"},{\"total\":1.899,\"energy\":1.4996,\"tax\":0.3994,\"startsAt\":\"2021-09-06T07:00:00.000+02:00\"},{\"total\":2.0578,\"energy\":1.6266,\"tax\":0.4312,\"startsAt\":\"2021-09-06T08:00:00.000+02:00\"},{\"total\":1.7942,\"energy\":1.4158,\"tax\":0.3784,\"startsAt\":\"2021-09-06T09:00:00.000+02:00\"},{\"total\":1.6516,\"energy\":1.3017,\"tax\":0.3499,\"startsAt\":\"2021-09-06T10:00:00.000+02:00\"},{\"total\":1.4313,\"energy\":1.1254,\"tax\":0.3059,\"startsAt\":\"2021-09-06T11:00:00.000+02:00\"},{\"total\":1.3661,\"energy\":1.0733,\"tax\":0.2928,\"startsAt\":\"2021-09-06T12:00:00.000+02:00\"},{\"total\":1.2986,\"energy\":1.0193,\"tax\":0.2793,\"startsAt\":\"2021-09-06T13:00:00.000+02:00\"},{\"total\":1.3323,\"energy\":1.0462,\"tax\":0.2861,\"startsAt\":\"2021-09-06T14:00:00.000+02:00\"},{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},{\"total\":1.5488,\"energy\":1.2195,\"tax\":0.3293,\"startsAt\":\"2021-09-06T16:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T17:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T18:00:00.000+02:00\"},{\"total\":1.6558,\"energy\":1.3051,\"tax\":0.3507,\"startsAt\":\"2021-09-06T19:00:00.000+02:00\"},{\"total\":1.2656,\"energy\":0.9929,\"tax\":0.2727,\"startsAt\":\"2021-09-06T20:00:00.000+02:00\"},{\"total\":1.1671,\"energy\":0.9141,\"tax\":0.253,\"startsAt\":\"2021-09-06T21:00:00.000+02:00\"},{\"total\":0.9563,\"energy\":0.7454,\"tax\":0.2109,\"startsAt\":\"2021-09-06T22:00:00.000+02:00\"},{\"total\":0.6288,\"energy\":0.4834,\"tax\":0.1454,\"startsAt\":\"2021-09-06T23:00:00.000+02:00\"}],\"tomorrow\":[{\"total\":0.6308,\"energy\":0.4851,\"tax\":0.1457,\"startsAt\":\"2021-09-07T00:00:00.000+02:00\"},{\"total\":0.6263,\"energy\":0.4814,\"tax\":0.1449,\"startsAt\":\"2021-09-07T01:00:00.000+02:00\"},{\"total\":0.6249,\"energy\":0.4803,\"tax\":0.1446,\"startsAt\":\"2021-09-07T02:00:00.000+02:00\"},{\"total\":0.6241,\"energy\":0.4797,\"tax\":0.1444,\"startsAt\":\"2021-09-07T03:00:00.000+02:00\"},{\"total\":0.6293,\"energy\":0.4838,\"tax\":0.1455,\"startsAt\":\"2021-09-07T04:00:00.000+02:00\"},{\"total\":0.7142,\"energy\":0.5518,\"tax\":0.1624,\"startsAt\":\"2021-09-07T05:00:00.000+02:00\"},{\"total\":1.1434,\"energy\":0.8951,\"tax\":0.2483,\"startsAt\":\"2021-09-07T06:00:00.000+02:00\"},{\"total\":1.4823,\"energy\":1.1662,\"tax\":0.3161,\"startsAt\":\"2021-09-07T07:00:00.000+02:00\"},{\"total\":1.7308,\"energy\":1.3651,\"tax\":0.3657,\"startsAt\":\"2021-09-07T08:00:00.000+02:00\"},{\"total\":1.5923,\"energy\":1.2543,\"tax\":0.338,\"startsAt\":\"2021-09-07T09:00:00.000+02:00\"},{\"total\":1.4388,\"energy\":1.1315,\"tax\":0.3073,\"startsAt\":\"2021-09-07T10:00:00.000+02:00\"},{\"total\":1.4383,\"energy\":1.1311,\"tax\":0.3072,\"startsAt\":\"2021-09-07T11:00:00.000+02:00\"},{\"total\":1.362,\"energy\":1.07,\"tax\":0.292,\"startsAt\":\"2021-09-07T12:00:00.000+02:00\"},{\"total\":1.1805,\"energy\":0.9248,\"tax\":0.2557,\"startsAt\":\"2021-09-07T13:00:00.000+02:00\"},{\"total\":1.1298,\"energy\":0.8842,\"tax\":0.2456,\"startsAt\":\"2021-09-07T14:00:00.000+02:00\"},{\"total\":0.9907,\"energy\":0.773,\"tax\":0.2177,\"startsAt\":\"2021-09-07T15:00:00.000+02:00\"},{\"total\":0.9702,\"energy\":0.7566,\"tax\":0.2136,\"startsAt\":\"2021-09-07T16:00:00.000+02:00\"},{\"total\":1.0907,\"energy\":0.853,\"tax\":0.2377,\"startsAt\":\"2021-09-07T17:00:00.000+02:00\"},{\"total\":1.0866,\"energy\":0.8497,\"tax\":0.2369,\"startsAt\":\"2021-09-07T18:00:00.000+02:00\"},{\"total\":1.0081,\"energy\":0.7869,\"tax\":0.2212,\"startsAt\":\"2021-09-07T19:00:00.000+02:00\"},{\"total\":0.9414,\"energy\":0.7335,\"tax\":0.2079,\"startsAt\":\"2021-09-07T20:00:00.000+02:00\"},{\"total\":0.872,\"energy\":0.678,\"tax\":0.194,\"startsAt\":\"2021-09-07T21:00:00.000+02:00\"},{\"total\":0.5883,\"energy\":0.451,\"tax\":0.1373,\"startsAt\":\"2021-09-07T22:00:00.000+02:00\"},{\"total\":0.4366,\"energy\":0.3296,\"tax\":0.107,\"startsAt\":\"2021-09-07T23:00:00.000+02:00\"}]}}}]}}","payloadType":"json","x":970,"y":1900,"wires":[["6068ec2576871871","12791505802fe0d3"]]},{"id":"6068ec2576871871","type":"debug","z":"5d3f964c.fef898","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":1960,"wires":[]},{"id":"08fd97ed5d4aee8a","type":"cronplus","z":"5d3f964c.fef898","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":1400,"y":1900,"wires":[["90682615323afee9"]]},{"id":"12791505802fe0d3","type":"function","z":"5d3f964c.fef898","name":"Generate date event","func":"\n\n// create Dynamic Cron Schedule\nmsg.payload = {\n    \"command\": \"add\",\n    \"name\": \"Dynamic Cron Schedule\",\n    \"expression\": new Date(msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow[0].startsAt),\n    \"expressionType\": \"dates\",\n    \"payloadType\": \"default\",\n    \"limit\": 1   \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":1900,"wires":[["08fd97ed5d4aee8a","598fe8c6d01b9460"]]},{"id":"90682615323afee9","type":"debug","z":"5d3f964c.fef898","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1470,"y":1960,"wires":[]},{"id":"598fe8c6d01b9460","type":"debug","z":"5d3f964c.fef898","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1250,"y":1960,"wires":[]}]
2 Likes

oppps .. ofcourse .. thats much cleaner ..
if only i spent a couple of minutes more reading the Cron plus Help window pass the code example :wink:

1 Like

I get this error when using the function "Generate date event"

TypeError: Cannot read property 'homes' of undefined

I think that maybe it's because the tomorrow doesn't contain any information until after 14.00 PM.
Is the a way to discard that payload if there isn't containing anything?

Hello ..

What do you want your application to do in this case ?
Get the min. value from today only ? or not produce any result ?
In either case, some more checks need to be done in code to avoid any errors.

Put some debug nodes after each step to make sure what step is failing and producing that undefined.

By the way, Steve in his example to demostrate the correct use of Cron plus used this line

"expression": new Date(msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow[0].startsAt),

.. because i worked on your previous question (regarding finding the minimum value from the arrrays)
that process has the date in msg.payload.totalMinimumStartsAt

If tomorrow is null, I want only the value from today

But I think that it works anyway. I get a warning from function node, but it still sends the message

Try this

[{"id":"212466ae0870af64","type":"cronplus","z":"4895ea10b4ee9ead","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":880,"y":1080,"wires":[["892b52223e704e42"]]},{"id":"3ad3b23fec44a0df","type":"function","z":"4895ea10b4ee9ead","name":"Generate date event","func":"\n// create Dynamic Cron Schedule\nmsg.payload = {\n    \"command\": \"add\",\n    \"name\": \"Dynamic Cron Schedule\",\n    \"expression\": new Date(msg.payload.totalMinimumStartsAt),\n    \"expressionType\": \"dates\",\n    \"payload\": \"your msg when the schedule is triggered\",\n    \"payloadType\": \"str\",\n    \"limit\": 1   \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":1080,"wires":[["212466ae0870af64","7a39f750528ad605"]]},{"id":"892b52223e704e42","type":"debug","z":"4895ea10b4ee9ead","name":"3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":1140,"wires":[]},{"id":"7a39f750528ad605","type":"debug","z":"4895ea10b4ee9ead","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":1140,"wires":[]},{"id":"4723ba4c47d907fe","type":"inject","z":"4895ea10b4ee9ead","name":"check status","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"command\":\"status-all\"}","payloadType":"json","x":750,"y":1000,"wires":[["212466ae0870af64"]]},{"id":"ab7e3bcb993b03b8","type":"inject","z":"4895ea10b4ee9ead","name":"with tomorrow","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"viewer\":{\"homes\":[{\"currentSubscription\":{\"priceInfo\":{\"current\":{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},\"today\":[{\"total\":0.6721,\"energy\":0.5181,\"tax\":0.154,\"startsAt\":\"2021-09-06T00:00:00.000+02:00\"},{\"total\":0.6608,\"energy\":0.509,\"tax\":0.1518,\"startsAt\":\"2021-09-06T01:00:00.000+02:00\"},{\"total\":0.6603,\"energy\":0.5086,\"tax\":0.1517,\"startsAt\":\"2021-09-06T02:00:00.000+02:00\"},{\"total\":0.6641,\"energy\":0.5117,\"tax\":0.1524,\"startsAt\":\"2021-09-06T03:00:00.000+02:00\"},{\"total\":0.6731,\"energy\":0.5189,\"tax\":0.1542,\"startsAt\":\"2021-09-06T04:00:00.000+02:00\"},{\"total\":0.9165,\"energy\":0.7136,\"tax\":0.2029,\"startsAt\":\"2021-09-06T05:00:00.000+02:00\"},{\"total\":1.5177,\"energy\":1.1946,\"tax\":0.3231,\"startsAt\":\"2021-09-06T06:00:00.000+02:00\"},{\"total\":1.899,\"energy\":1.4996,\"tax\":0.3994,\"startsAt\":\"2021-09-06T07:00:00.000+02:00\"},{\"total\":2.0578,\"energy\":1.6266,\"tax\":0.4312,\"startsAt\":\"2021-09-06T08:00:00.000+02:00\"},{\"total\":1.7942,\"energy\":1.4158,\"tax\":0.3784,\"startsAt\":\"2021-09-06T09:00:00.000+02:00\"},{\"total\":1.6516,\"energy\":1.3017,\"tax\":0.3499,\"startsAt\":\"2021-09-06T10:00:00.000+02:00\"},{\"total\":1.4313,\"energy\":1.1254,\"tax\":0.3059,\"startsAt\":\"2021-09-06T11:00:00.000+02:00\"},{\"total\":1.3661,\"energy\":1.0733,\"tax\":0.2928,\"startsAt\":\"2021-09-06T12:00:00.000+02:00\"},{\"total\":1.2986,\"energy\":1.0193,\"tax\":0.2793,\"startsAt\":\"2021-09-06T13:00:00.000+02:00\"},{\"total\":1.3323,\"energy\":1.0462,\"tax\":0.2861,\"startsAt\":\"2021-09-06T14:00:00.000+02:00\"},{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},{\"total\":1.5488,\"energy\":1.2195,\"tax\":0.3293,\"startsAt\":\"2021-09-06T16:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T17:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T18:00:00.000+02:00\"},{\"total\":1.6558,\"energy\":1.3051,\"tax\":0.3507,\"startsAt\":\"2021-09-06T19:00:00.000+02:00\"},{\"total\":1.2656,\"energy\":0.9929,\"tax\":0.2727,\"startsAt\":\"2021-09-06T20:00:00.000+02:00\"},{\"total\":1.1671,\"energy\":0.9141,\"tax\":0.253,\"startsAt\":\"2021-09-06T21:00:00.000+02:00\"},{\"total\":0.9563,\"energy\":0.7454,\"tax\":0.2109,\"startsAt\":\"2021-09-06T22:00:00.000+02:00\"},{\"total\":0.6288,\"energy\":0.4834,\"tax\":0.1454,\"startsAt\":\"2021-09-06T23:00:00.000+02:00\"}],\"tomorrow\":[{\"total\":0.6308,\"energy\":0.4851,\"tax\":0.1457,\"startsAt\":\"2021-09-07T00:00:00.000+02:00\"},{\"total\":0.6263,\"energy\":0.4814,\"tax\":0.1449,\"startsAt\":\"2021-09-07T01:00:00.000+02:00\"},{\"total\":0.6249,\"energy\":0.4803,\"tax\":0.1446,\"startsAt\":\"2021-09-07T02:00:00.000+02:00\"},{\"total\":0.6241,\"energy\":0.4797,\"tax\":0.1444,\"startsAt\":\"2021-09-08T03:00:00.000+02:00\"},{\"total\":0.6293,\"energy\":0.4838,\"tax\":0.1455,\"startsAt\":\"2021-09-07T04:00:00.000+02:00\"},{\"total\":0.7142,\"energy\":0.5518,\"tax\":0.1624,\"startsAt\":\"2021-09-07T05:00:00.000+02:00\"},{\"total\":1.1434,\"energy\":0.8951,\"tax\":0.2483,\"startsAt\":\"2021-09-07T06:00:00.000+02:00\"},{\"total\":1.4823,\"energy\":1.1662,\"tax\":0.3161,\"startsAt\":\"2021-09-07T07:00:00.000+02:00\"},{\"total\":1.7308,\"energy\":1.3651,\"tax\":0.3657,\"startsAt\":\"2021-09-07T08:00:00.000+02:00\"},{\"total\":1.5923,\"energy\":1.2543,\"tax\":0.338,\"startsAt\":\"2021-09-07T09:00:00.000+02:00\"},{\"total\":1.4388,\"energy\":1.1315,\"tax\":0.3073,\"startsAt\":\"2021-09-07T10:00:00.000+02:00\"},{\"total\":1.4383,\"energy\":1.1311,\"tax\":0.3072,\"startsAt\":\"2021-09-07T11:00:00.000+02:00\"},{\"total\":1.362,\"energy\":1.07,\"tax\":0.292,\"startsAt\":\"2021-09-07T12:00:00.000+02:00\"},{\"total\":1.1805,\"energy\":0.9248,\"tax\":0.2557,\"startsAt\":\"2021-09-07T13:00:00.000+02:00\"},{\"total\":1.1298,\"energy\":0.8842,\"tax\":0.2456,\"startsAt\":\"2021-09-07T14:00:00.000+02:00\"},{\"total\":0.9907,\"energy\":0.773,\"tax\":0.2177,\"startsAt\":\"2021-09-07T15:00:00.000+02:00\"},{\"total\":0.9702,\"energy\":0.7566,\"tax\":0.2136,\"startsAt\":\"2021-09-07T16:00:00.000+02:00\"},{\"total\":1.0907,\"energy\":0.853,\"tax\":0.2377,\"startsAt\":\"2021-09-07T17:00:00.000+02:00\"},{\"total\":1.0866,\"energy\":0.8497,\"tax\":0.2369,\"startsAt\":\"2021-09-07T18:00:00.000+02:00\"},{\"total\":1.0081,\"energy\":0.7869,\"tax\":0.2212,\"startsAt\":\"2021-09-07T19:00:00.000+02:00\"},{\"total\":0.9414,\"energy\":0.7335,\"tax\":0.2079,\"startsAt\":\"2021-09-07T20:00:00.000+02:00\"},{\"total\":0.872,\"energy\":0.678,\"tax\":0.194,\"startsAt\":\"2021-09-07T21:00:00.000+02:00\"},{\"total\":0.5883,\"energy\":0.451,\"tax\":0.1373,\"startsAt\":\"2021-09-07T22:00:00.000+02:00\"},{\"total\":0.4366,\"energy\":0.3296,\"tax\":0.107,\"startsAt\":\"2021-09-07T23:00:00.000+02:00\"}]}}}]}}","payloadType":"json","x":210,"y":1040,"wires":[["6f82207b692dd1cf"]]},{"id":"6f82207b692dd1cf","type":"function","z":"4895ea10b4ee9ead","name":"totalMinimum","func":"let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today.slice(-5)\nlet tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow || []\ntomorrow = tomorrow.slice(0, 5)\nlet total = today.concat(tomorrow)\nnode.warn(total);\n\nlet totalMinimum = today[0].total\nlet totalMinimumStartsAt;\n\ntotal.forEach(el => {\n    if (el.total < totalMinimum) {\n        totalMinimum = el.total;\n        totalMinimumStartsAt = el.startsAt;\n    }\n})\n\nmsg.payload = {\n    totalMinimum,\n    totalMinimumStartsAt\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":1080,"wires":[["b1f094c1b38cb61b","3ad3b23fec44a0df"]]},{"id":"b1f094c1b38cb61b","type":"debug","z":"4895ea10b4ee9ead","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":1020,"wires":[]},{"id":"02faf65844a13615","type":"inject","z":"4895ea10b4ee9ead","name":"with no tomorrow","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"viewer\":{\"homes\":[{\"currentSubscription\":{\"priceInfo\":{\"current\":{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},\"today\":[{\"total\":0.6721,\"energy\":0.5181,\"tax\":0.154,\"startsAt\":\"2021-09-06T00:00:00.000+02:00\"},{\"total\":0.6608,\"energy\":0.509,\"tax\":0.1518,\"startsAt\":\"2021-09-06T01:00:00.000+02:00\"},{\"total\":0.6603,\"energy\":0.5086,\"tax\":0.1517,\"startsAt\":\"2021-09-06T02:00:00.000+02:00\"},{\"total\":0.6641,\"energy\":0.5117,\"tax\":0.1524,\"startsAt\":\"2021-09-06T03:00:00.000+02:00\"},{\"total\":0.6731,\"energy\":0.5189,\"tax\":0.1542,\"startsAt\":\"2021-09-06T04:00:00.000+02:00\"},{\"total\":0.9165,\"energy\":0.7136,\"tax\":0.2029,\"startsAt\":\"2021-09-06T05:00:00.000+02:00\"},{\"total\":1.5177,\"energy\":1.1946,\"tax\":0.3231,\"startsAt\":\"2021-09-06T06:00:00.000+02:00\"},{\"total\":1.899,\"energy\":1.4996,\"tax\":0.3994,\"startsAt\":\"2021-09-06T07:00:00.000+02:00\"},{\"total\":2.0578,\"energy\":1.6266,\"tax\":0.4312,\"startsAt\":\"2021-09-06T08:00:00.000+02:00\"},{\"total\":1.7942,\"energy\":1.4158,\"tax\":0.3784,\"startsAt\":\"2021-09-06T09:00:00.000+02:00\"},{\"total\":1.6516,\"energy\":1.3017,\"tax\":0.3499,\"startsAt\":\"2021-09-06T10:00:00.000+02:00\"},{\"total\":1.4313,\"energy\":1.1254,\"tax\":0.3059,\"startsAt\":\"2021-09-06T11:00:00.000+02:00\"},{\"total\":1.3661,\"energy\":1.0733,\"tax\":0.2928,\"startsAt\":\"2021-09-06T12:00:00.000+02:00\"},{\"total\":1.2986,\"energy\":1.0193,\"tax\":0.2793,\"startsAt\":\"2021-09-06T13:00:00.000+02:00\"},{\"total\":1.3323,\"energy\":1.0462,\"tax\":0.2861,\"startsAt\":\"2021-09-06T14:00:00.000+02:00\"},{\"total\":1.422,\"energy\":1.118,\"tax\":0.304,\"startsAt\":\"2021-09-06T15:00:00.000+02:00\"},{\"total\":1.5488,\"energy\":1.2195,\"tax\":0.3293,\"startsAt\":\"2021-09-06T16:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T17:00:00.000+02:00\"},{\"total\":1.6755,\"energy\":1.3208,\"tax\":0.3547,\"startsAt\":\"2021-09-06T18:00:00.000+02:00\"},{\"total\":1.6558,\"energy\":1.3051,\"tax\":0.3507,\"startsAt\":\"2021-09-06T19:00:00.000+02:00\"},{\"total\":1.2656,\"energy\":0.9929,\"tax\":0.2727,\"startsAt\":\"2021-09-06T20:00:00.000+02:00\"},{\"total\":1.1671,\"energy\":0.9141,\"tax\":0.253,\"startsAt\":\"2021-09-06T21:00:00.000+02:00\"},{\"total\":0.9563,\"energy\":0.7454,\"tax\":0.2109,\"startsAt\":\"2021-09-06T22:00:00.000+02:00\"},{\"total\":0.6288,\"energy\":0.4834,\"tax\":0.1454,\"startsAt\":\"2021-09-06T23:00:00.000+02:00\"}]}}}]}}","payloadType":"json","x":200,"y":1120,"wires":[["6f82207b692dd1cf"]]}]
let tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow || []
tomorrow = tomorrow.slice(0, 5)

|| [] assigns an empty array to tomorrow variable if the left hand side is undefined

Great ,that should do the trick!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.