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

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

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.

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

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.

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.

//  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;

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