# Stuck with how to parse weather information in \`function\` node

**URL:** https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059
**Category:** General
**Created:** [31 December 2025 20:20 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059 "2025-12-31T20:20:10Z")
**Posts on this page:** 9
**Page:** 1

<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: [31 December 2025 20:20 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/1 "2025-12-31T20:20:10Z")

</div>

Folks, I am a bit stuck with how to get something done with a message.

I am using the `openweather` node to get the weather and detect if it is RAINING NOW and how much.

The information is in `msg.payload.rain` and there is three modes of operation.  
A, B and C (and Q, which I'll get to later)  
B is easy. It gets the weather at that time and nothing else.  
A and C are _average_ weather readings from either mid-night or sunrise.

And that's where the problem starts.

Let's go with the `mid-night` one.  
There will be a few messages averaged to get the _final_ value.

I added the two extra options as it may be raining from mid-night (or dawn) but stop by mid-day and there is no rain. So with 'no rain', the plants get watered, which is kind of silly as they have already received enough water for that day.

So there is a threshold where there is enough rain fallen, and getting that value - as an _average_ is driving me mad.

Example:  
The cut off is `0.3`mm rain.  
Rain detected at 01:00 = `0.1`mm  
Rain detected at 04:00 = `0.1`mm  
Rain detected at 09:00 = `0.1`mm  
_All other readings were `0`_

So the plants don't need watering.

I understand I only count non-zero values.  
But the _average_ is where I'm falling over.

Maybe I should be using _TOTAL_ rather than _average_. I get that.  
But I'm just wanting to ask if there is an elephant I'm not seeing.

Thanks.

# OH!

## The `Q` mode.

So I have it set to mode B.

But it is raining and looking like it s going to clear before mid-day.  
I press a button and it gets the rainfall NOW and if it is greater than the `0.3`mm, it is marked as to be skipped.  
(a value of \> 0.3 is then sent when the value is requested.)

Clear?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [31 December 2025 20:55 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/2 "2025-12-31T20:55:47Z")

</div>

Which API does the openweathermap node access?

I don't use that node, instead I use an http request node to access v3 "onecall" which includes a total forecast mm of rain for today as msg.payload.daily[0].rain.

---

<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: [31 December 2025 20:59 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/3 "2025-12-31T20:59:57Z")

</div>

I know this is not looking good for me, but I don't understand:

> [@jbudd](#):
>
> Which API does the openweathermap node access

On your mentioning the `forecast`.... Yeah. I'm wanting the actual amount of rain DETECTED falling. Not the forecast. That can be too problematic in itself.

I am working now on just using a running total.  
But it would seem I have taken a lot of `stupid pills` just recently and I am making a `dog's breakfast` of even doing that.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [31 December 2025 21:09 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/4 "2025-12-31T21:09:40Z")

</div>

> [@Trying\_to\_learn](#):
>
> On your mentioning the `forecast`.... Yeah. I'm wanting the actual amount of rain DETECTED falling. Not the forecast. That can be too problematic in itself.

Perhaps Openweathermap knows the actual amount of rain that was reported at the nearest weather station but it certainly doesn't know how much has fallen at your location.  
I suspect you either need a personal weather station of your own, with a rain measurement, or else a soil moisture sensor, or both.

> [@Trying\_to\_learn](#):
>
> I don't understand:
> 
> Which API does the openweathermap node access

Openweathermap has at least two APIs. The more recent one is called "Onecall API 3". You have to give a credit card to get an API key, but there is a generous free tier. There is also an older one which returns different data and needs a different API key.

---

<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: [31 December 2025 21:17 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/5 "2025-12-31T21:17:32Z")

</div>

Oh, ok.

Yes, I have an API Key for it.

But I am using it to get the weather NOW.  
I (maybe) should look if they have a backward looking option too.

That way I can call it once (at mid day) and be told how much rain has fallen today.  
Though it would be _problematic_ with the `sunrise` option. As it may have _bucketed down_ from midnight but stopped at sunrise.....

I think I'd better not waste _your_ (and/or other people's) time with this.  
Sorry.  
I know I've kind of been down this path before _recently_ and kinda failed with that one too.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [31 December 2025 21:19 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/6 "2025-12-31T21:19:51Z")

</div>

How is 2026 looking so far?

---

<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: [31 December 2025 21:21 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/7 "2025-12-31T21:21:56Z")

</div>

I was asleep when it started.  
Kinda wet and rainy from the reports though.

I'm getting `0.12`mm rain falling every hour since midnight from what I'm seeing in the flow.

---

<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: [31 December 2025 22:06 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/8 "2025-12-31T22:06:11Z")

</div>

This is the code which I hope works.

I have done some initial testing and it seems to be doing the right thing/s.

Though time will tel..

```auto
// Get `mode` to determine how the rain is parsed.
//
// A -> From midnight
// B -> Normal
// C -> From sunrise

// Handle reset message.
let total_rain = context.get("total_rain") || 0
if (msg.reset == "reset")
{
    context.set("total_rain",0)
    node.status({})
    msg.payload = {}
    msg.payload.rain = 0 // 2026 01 01 added to wipe anything in the queue.
    return msg
}

const mode = flow.get("mode") || "B"
//node.warn("Mode is " + mode)

let rain = msg.payload.rain

if (mode == "B")
{
    node.status({text:mode})
    return msg // nothing to do in this mode.
}

total_rain = total_rain + rain
context.set("total_rain",total_rain)

node.warn("Rain now is " + rain)
node.warn("Total rain so far is " + total_rain)

node.status({text:mode + ' ' + total_rain})

msg.payload.rain = total_rain
//msg.rain_now = total_rain // This isn't used (2026 01 01)

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: [31 March 2026 22:06 UTC](https://discourse.nodered.org/t/stuck-with-how-to-parse-weather-information-in-function-node/100059/9 "2026-03-31T22:06:51Z")

</div>

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