Function node min value

Hi!
Can someone help med with a function node to extract the total value in these two arrays and find the minimum value of these?

Sure if you supply a copy of the payload containing the arrays.

payload.viewer.homes[0].currentSubscription.priceInfo.today
payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow
I want the lowest number of all the "total"

E1cid asked for the actual data, not just the path.
Hover you mouse over the root of the msg.payload (from the Debug tab) and use the Copy value icon
then paste the data sample using the Preformatted Text icon to paste in your post.

image

{"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"}]}}}]}}

As you were unresponsive to my request, I will be slightly unresponsive and give you an example that does not use a function node.

[{"id":"a709326a.ebc2f8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload.viewer.homes[0].currentSubscription.priceInfo.today","v":"[{\"total\":3,\"blah\":\"ggg\"},{\"total\":1,\"blah\":\"ggg\"}]","vt":"json"},{"p":"payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow","v":"[{\"total\":4,\"blah\":\"ggg\"},{\"total\":2,\"blah\":\"ggg\"}]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":2200,"wires":[["c7be950d.811bc"]]},{"id":"c7be950d.811bc","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"payload.lowest","pt":"msg","to":"**.total^($)[0]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":2220,"wires":[["9f921d44.b39b2"]]},{"id":"9f921d44.b39b2","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":2320,"wires":[]}]

[edit if you want the object containing the lowest try **.priceInfo.*^(total)[0]

Here's also an example using a Function node :

[{"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":280,"y":620,"wires":[["6068ec2576871871","6f82207b692dd1cf"]]},{"id":"6068ec2576871871","type":"debug","z":"4895ea10b4ee9ead","name":"1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":440,"y":540,"wires":[]},{"id":"6f82207b692dd1cf","type":"function","z":"4895ea10b4ee9ead","name":"","func":"let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today\nlet tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow\n\nlet todayMinimum = today[0].total\nlet tomorrowMinimum = tomorrow[0].total\n\ntoday.forEach(el => {\n    if (el.total < todayMinimum) todayMinimum = el.total\n})\n\ntomorrow.forEach(el => {\n    if (el.total < tomorrowMinimum) tomorrowMinimum = el.total\n})\n\nmsg.payload = {\n    todayMinimum,\n    tomorrowMinimum,\n    totalMinimum: todayMinimum < tomorrowMinimum ? todayMinimum : tomorrowMinimum\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":620,"wires":[["b1f094c1b38cb61b"]]},{"id":"b1f094c1b38cb61b","type":"debug","z":"4895ea10b4ee9ead","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":620,"wires":[]}]

Thanks!
Can I trouble you with one more thing?
Is it possible to get the timestamp o the lowest price?
at every array objekt there is an "StartAt" with date and time

Got this far but don't know how to collect the same object as the min.total

let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today
let tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow

let todayMinimum = today[0].total
let todaytime = today[0].startsAt
let tomorrowMinimum = tomorrow[0].total
let tomorrowtime = tomorrow[0].startsAt

today.forEach(el => {
    if (el.total < todayMinimum) todayMinimum = el.total
})

tomorrow.forEach(el => {
    if (el.total < tomorrowMinimum) tomorrowMinimum = el.total
})

msg.payload = {
    todaytime,
    tomorrowtime,
    todayMinimum,
    tomorrowMinimum,
    totalMinimum: todayMinimum < tomorrowMinimum ? todayMinimum : tomorrowMinimum
}

return msg;

If you dont need seperate minimums for today and tomorrow you could simplify the function by first merging the two arrays and looping through it once.

when you find then min. in the loop, save the startsAt datetime in a totalMinimumStartsAt variable also.

[{"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":280,"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":440,"y":540,"wires":[]},{"id":"6f82207b692dd1cf","type":"function","z":"4895ea10b4ee9ead","name":"","func":"let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today\nlet tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow\nlet total = today.concat(tomorrow)\n//node.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":440,"y":620,"wires":[["b1f094c1b38cb61b"]]},{"id":"b1f094c1b38cb61b","type":"debug","z":"4895ea10b4ee9ead","name":"2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":620,"wires":[]}]
1 Like

Thanks again!
One more question.
If I just want to compare the first 10 objects in the array, is that possible?
Lets say the last 5 from today oand the first 5 from tomorrow?
Quess that it will take some effort to figuring out?

You just need to tag on a slice() array method on each of the two arrays before merging them

let today = msg.payload.viewer.homes[0].currentSubscription.priceInfo.today.slice(-5)
let tomorrow = msg.payload.viewer.homes[0].currentSubscription.priceInfo.tomorrow.slice(0, 5)
1 Like

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