question

tijntert avatar image
tijntert asked

Node RED & Tibber API how to use/find 3 types of prices?

hey y'all,


Im new to NodeRED, but getting there... now I want to use the Tibber API to get some data :D

but, how? mmmhhh...


Can find, show (right side, via debug) some data... but what I want is to know how to use that in a flow...

this for:

* lowest price of the next day. At the moment I can only find all of the next day price, debug.

* highest price of the day

* current price


Could someone please give me a flowExample, so I can see/figure out how to do this?



thx in advance :D

Node-REDapi
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

1 Answer
matt1309 avatar image
matt1309 answered ·

Hi @Tijntert

It's probably easier to watch a few node red guides first. However as a high level guide.

I cant help with Tibber api specifics but i can explain how you use the data in a flow.

Can you provide an example of what the data looks like from Tibber please?





3 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

tijntert avatar image tijntert commented ·

thx :D but also for this, getting there...

and indeed, watch * infinity = know... ;)


example:

const homes = msg.payload.viewer.homes;

if (!homes || homes.length === 0) {

node.error('No homes found in the payload.');

return null;

}


const tomorrowPrices = homes[0].currentSubscription.priceInfo.tomorrow;

if (!tomorrowPrices || tomorrowPrices.length === 0) {

node.error('No prices for tomorrow, yet.');

return null;

}


let lowestPriceLP = Math.min(...tomorrowPrices.map(p => p.total));


if (isNaN(lowestPriceLP)) {

node.error('Lowest price is Not-a-Number.');

return null;

}


// only lowestPriceLP to msg.payload

msg.payload = lowestPriceLP;


return msg;

0 Likes 0 ·
matt1309 avatar image matt1309 tijntert commented ·

@Tijntert can you give an example of what the api data looks like. ie what does homes look like.


Without the data the syntax alone looks fine. (I prefer loops than spread syntax but im not a js dev so probably why).

You look to have solved it. Then you just repeat. Depending on how you plan on using those variables you can either save them in global or flow context for use elsewhere within node red/flow.

ie global.set('lowesetPrice',lowestPriceLP);

Or you pass then in msg if that's prefer. ie you could use

msg.LP = lowestPriceLP;

msg.HP = highestPriceHP;

msg.current = currentPrice;


return msg;


1 Like 1 ·
tijntert avatar image tijntert matt1309 commented ·
im a global.guy :D

tab with global. and flow in another tab, etc.etc. ;)

0 Likes 0 ·