# Openweather node question - how to filter outputs

**URL:** <https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027>\
**Category:** General\
**Created:** [2 March 2023 21:49 UTC](https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027 "2023-03-02T21:49:22Z")\
**Posts on this page:** 4\
**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:** [2 March 2023 21:49 UTC](https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027/1 "2023-03-02T21:49:22Z")

</div>

Folks, I'm _confused_.

I have my `openweather` node and see it's output.

I am interested in the `rain` output.

If it isn't raining, I'm stuck how to _filter_ the message.

Example/s:  
No rain:

```auto
{"_msgid":"02bbdb546cecd8f5","payload":{"id":804,"weather":"Clouds","detail":"overcast clouds","icon":"04d","tempk":288.3,"tempc":15.1,"temp_maxc":15.1,"temp_minc":15.1,"humidity":87,"pressure":1017,"maxtemp":288.3,"mintemp":288.3,"windspeed":0.83,"winddirection":128,"location":"Cooma","sunrise":1677786638,"sunset":1677832851,"clouds":100,"description":"The weather in Cooma at coordinates: -36.2333, 149.1333 is Clouds (overcast clouds)."},"topic":"","icon":"<i class=\"fa fa-refresh fa-spin\"></i>","background":"#333333","font":"red","location":{"lon":149.1333,"lat":-36.2333,"city":"Cooma","country":"AU"},"data":{"coord":{"lon":149.1333,"lat":-36.2333},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":288.3,"feels_like":288.14,"temp_min":288.3,"temp_max":288.3,"pressure":1017,"humidity":87,"sea_level":1017,"grnd_level":926},"visibility":10000,"wind":{"speed":0.83,"deg":128,"gust":1.36},"clouds":{"all":100},"dt":1677792992,"sys":{"country":"AU","sunrise":1677786638,"sunset":1677832851},"timezone":39600,"id":2170577,"name":"Cooma","cod":200},"time":"2023-03-02T21:36:32.000Z","title":"Current Weather Information","description":"Current weather information at coordinates: -36.2333, 149.1333"}

```

Rain:

```auto
{"_msgid":"400e17eaad85a668","payload":{"id":500,"weather":"Rain","detail":"light rain","icon":"10d","tempk":293.15,"tempc":20,"temp_maxc":21.7,"temp_minc":18.7,"humidity":89,"pressure":1016,"maxtemp":294.87,"mintemp":291.85,"windspeed":3.09,"winddirection":200,"location":"Ashfield","sunrise":1677786271,"sunset":1677832260,"clouds":75,"rain":0.87,"description":"The weather in Ashfield at coordinates: -33.8886, 151.1314 is Rain (light rain)."},"topic":"","location":{"lon":151.1314,"lat":-33.8886,"city":"Ashfield","country":"AU"},"data":{"coord":{"lon":151.1314,"lat":-33.8886},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"base":"stations","main":{"temp":293.15,"feels_like":293.53,"temp_min":291.85,"temp_max":294.87,"pressure":1016,"humidity":89},"visibility":10000,"wind":{"speed":3.09,"deg":200},"rain":{"1h":0.87},"clouds":{"all":75},"dt":1677792601,"sys":{"type":2,"id":2010638,"country":"AU","sunrise":1677786271,"sunset":1677832260},"timezone":39600,"id":7839683,"name":"Ashfield","cod":200},"time":"2023-03-02T21:30:01.000Z","title":"Current Weather Information","description":"Current weather information at coordinates: -33.8886, 151.1314"}

```

What I am looking at:

![No Rain detected](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/1644cfbca1591fa5eceb50e8e6aa7124f453a518.png)

![Rain detected](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/0/f096bd07c601ade7c34ddd5c0ed7b7ca89e9e10a.png)

And so you see this `rain` property.

Just after the `openweather` node I have a `switch` node.  
(code below)

But that won't work if the `rain` _property_ isn't there.  
So I have the `switch` node set to this:

 ![Screenshot from 2023-03-03 08-46-38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/380eba54c6afecb31d791961484dc180d8609cd0.png)

**IS NOT EMPTY**

But that doesn't pass the payload if/when it is raining.

Below is the modified code that works now - while it is raining.  
But what's going to happen when it isn't raining?

I fear an `error` will happen.

The node is basically set to `> 0` - to save you importing the node.  
(Sorry)

```auto
[{"id":"19a82bda1a7ebdf3","type":"switch","z":"05319bbbba06da29","name":"Raining?","property":"data.rain[\"1h\"]","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":655,"y":310,"wires":[["2fdfdb709240ab4e","bbf430450a163bba"]],"l":false}]

```

---

<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:** [2 March 2023 22:40 UTC](https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027/2 "2023-03-02T22:40:22Z")

</div>

I stopped using the OpenWeatherMap node. can't recall exactly why, but I wanted some data that's available in their OneCall API but not in the API accessed with the node.

Anyway, I see similar behaviour:  
The forecast for next Tuesday, msg.payload.daily[5] has a property rainmm = "3mm" ,  
but for tomorrow msg.payload.daily[1].rainmm does not exist.

I copy the values into a dashboard template. Here's a snippet

```auto
<div class="icon">
       <div class="subtitle time">{{msg.payload.daily[2].day}}</div>
       <i class="wi wi-owm-{{msg.payload.daily[2].weather[0].icon}}" style="{{msg.payload.daily[2].iconstyle}}"></i>
       <div class="subtitle temp">{{msg.payload.daily[2].temp.max | number:0}}°</div>
       <div class="subtitle rain">{{msg.payload.daily[2].rainmm}}</div>
       <div class="subtitle snow">{{msg.payload.daily[2].snowmm}}</div>
       <div class="subtitle wind">{{msg.payload.daily[2].strongwind}}</div>
 </div>  

```

It does not give either errors or warnings if those properties don't exist. A debug node set to show payload.daily[2].rainmm gives undefined.

---

<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:** [3 March 2023 22:46 UTC](https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027/3 "2023-03-03T22:46:18Z")

</div>

Thanks, but I fear the meaning for what I was asking was lost in how I asked it.

I do NOT use the forecast _function/feature_.  
Anyway, I'll rephrase the question in a new thread.

---

<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:** [17 March 2023 22:47 UTC](https://discourse.nodered.org/t/openweather-node-question-how-to-filter-outputs/76027/4 "2023-03-17T22:47:08Z")

</div>

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