# Is anyone familiar with using openweather api to show accumulated rainfall over the period of last 24 hours?

**URL:** <https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537>\
**Category:** Dashboard\
**Tags:** function-node\
**Created:** [29 August 2024 16:43 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537 "2024-08-29T16:43:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhmeh](https://avatars.discourse-cdn.com/v4/letter/a/58956e/32.png) [@abhmeh](https://discourse.nodered.org/u/abhmeh)\
**Post date:** [29 August 2024 16:43 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/1 "2024-08-29T16:43:27Z")

</div>

s anyone fimiliar with using openweather api to show accumulated rainfall over the period of last 24 hours?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 September 2024 11:26 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/2 "2024-09-01T11:26:48Z")

</div>

You will need to show the returned historical data, then some one may give you an example how to parse it to return the info you require.

---

<div class="post-metadata">

**Author:** ![piwi447](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/piwi447/32/67335_2.png) [@piwi447](https://discourse.nodered.org/u/piwi447)\
**Post date:** [2 September 2024 18:55 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/3 "2024-09-02T18:55:19Z")

</div>

I have some experience to get the average f temperature forecast, get the rainfall should be similar….I will. Heck this when I have access to my nodered

Pierre RUWET

---

<div class="post-metadata">

**Author:** ![piwi447](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/piwi447/32/67335_2.png) [@piwi447](https://discourse.nodered.org/u/piwi447)\
**Post date:** [8 September 2024 04:48 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/4 "2024-09-08T04:48:13Z")

</div>

Hello,

First you need to check if the rain data is available for your area on openweathermap. this is not the case for me. I only use the fee plan and have current weather with no rain and forecast3h.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 September 2024 06:13 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/5 "2024-09-08T06:13:31Z")

</div>

I do something similar to what you want.

The mechanics will work.

Mine if from midnight and can gather the total cumulative rain as each hour goes by.

So, hourly I get the weather data.

Sorry if it seems I am dropping this code on you, but just now I feel terrible. I think I have the flu.

```auto
// 2024 04 09
//
// Input: `msg.payload.rain` for normal ops.
// Ouptut: `msg.rain_now`

//===================================================================================

let rainamount = context.get('rainamount') || [] // get context variable, default empty array

// If `reset` message received.
if (msg.reset == "reset") {
    node.status({ text: "RESET" });
    flow.set("total_rain", 0);
    flow.set("todays_rain", 0);
    context.set('rainamount', []);
    rainamount = [];
    return;
}

let todays_rain = flow.get("total_rain") || 0;
node.warn("Today's rain is " + todays_rain);
node.warn("Incoming rain message " + msg.payload.rain);

//==================================================
// 2024 04 09
// This is if there is no rain and the message structure is not defined.
if (msg.payload.rain == undefined) {
    node.warn("no rain detected in message");
    msg.payload.rain = 0;
    node.warn("Set payload.rain to 0");
    node.warn(msg.payload.rain);
}
//==================================================

// 2024 04 09
// This is where the latest value is parsed.
let rain_now = msg.payload.rain * 10;
node.warn("at this point rain_now is = " + rain_now / 10);

//==================================================
// 2024 04 09 Get `count` value.
let count = msg.count || 0;

node.warn("count value set to " + count);

if (count == 0)
{
    node.warn("I shouldn't be here");
    return;
}
// Reduce `count` size.
// 2024 07 31 BIG MISTAKE! If you reduce the count size then divide `todays_rain` by a SMALLER number, the result will be BIGGER - not smaller!
//count = count / 4;
count = count * 4
node.warn("modified count value set to " + count);

//==================================================

//==================================================
// 2024 04 09
//
// Store rain values in context to maybe help with tracing things.
rainamount.push(rain_now) // Add a new array element 
context.set('rainamount', rainamount) // save to node context
//==================================================

node.warn("Adding rain totals together (count included)");

todays_rain = (todays_rain + rain_now);
flow.set("total_rain", todays_rain);

node.warn("Value 1 = " + todays_rain);

todays_rain = Math.round(todays_rain / count) / 10;

node.warn("Value 2 = " + todays_rain);

node.status({ text: "counter = " + msg.count + " Total rain today = " + todays_rain + " Rain = " + rain_now});

flow.set("count", count);

// ********* msg.rain_now used to send data
msg.rain_now = todays_rain;
msg.topic = null;

return msg;

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 October 2024 06:14 UTC](https://discourse.nodered.org/t/is-anyone-familiar-with-using-openweather-api-to-show-accumulated-rainfall-over-the-period-of-last-24-hours/90537/6 "2024-10-08T06:14:04Z")

</div>

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