Getting next hours electric spot-price from Nordpool via nordpool-api-plus

I need to get hold of the "next hour" electric price from "nordpool-api-plus" node.

I've managed to setup the "nordpool-api-plus" node so I get the array of prices for the actual days spot-prices looking as this in the debug node:

[0 … 9]
0: object
timestamp: "2023-10-18T00:00:00.000Z"
price: 46.68
currency: "SEK"
area: "SE2"
1: object
2: object
3: object
4: object
5: object
6: object
7: object
8: object
9: object
[10 … 19]
[20 … 23]

I then connect a function node after the "nordpool-api-plus" node for entering some javascript but this is where I need help;

1. How do i fetch next hours price?
Lets say I run the timestamp each hour, generating a array shown above with the actual days prices.
So at this time I want to fetch the price for object "23" in the array.

How do I do this with Javascript?

Welcome @P-solver ,

If the payload is just an array of those objects:

msg.payload[23].price will get you the price at index 23

I get an error "Function tried to send a message of type number" for this code:

var nexthourprice;
nexthourprice = msg.payload[23].price;
return nexthourprice;

Any idea what I'm doing wrong? (I'm not that good at javascript as you probably can tell :))

You’re not sending an object, in Node RED the message being passed down, needs to be an object.

return {payload: msg.payload[23].price}

Or better

msg.payload = msg.payload[23].price 
return msg

So you need to determine the hour you're in then use that to find the array with that index

const date = new Date();
///date.setHours(date.getHours()+1); // uncomment for next hour
const index = date.getHours();
msg.payload = msg.payload[index].price
return msg;

your error is
You must return an object to each output.
eg. set the price to a msg property.

1 Like


return {topic: 'Price', payload: nexthourprice}

Worked like a charm!

Many thanks!

1 Like

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