# Newbie question: openweather 5 day prediction filter (min temp value)

**URL:** https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634
**Category:** General
**Created:** [27 November 2020 16:40 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634 "2020-11-27T16:40:56Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![SKES](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/skes/32/14077_2.png) [@SKES](https://discourse.nodered.org/u/SKES)
#### Post date: [27 November 2020 16:40 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/1 "2020-11-27T16:40:57Z")

</div>

I'm a little bit lost here, I try to filter the lowest temp from the 5 day weather forecast to close some water valves if for example temp\_min is below -5°..  
Hereunder a small part (3 of 40) of the msg output from the 5 day weather forecast from openWeather API.

I just want to return all days when the (temp\_min) is lower than -5° as a result. I was busy all day trying to get this result but I'm completely lost :-(.

Some insights would be appreciated.  
I understand the basics of For loops and If then statements but it's really hard for me to apply this on real examples.

[  
{"dt":1606489200,"main":{"temp":8.44,"feels\_like":5.83,"temp\_min":8.44,"temp\_max":8.64,"pressure":1018}  
,{"dt":1606500000,"main":{"temp":7.15,"feels\_like":3.96,"temp\_min":6.85,"temp\_max":7.15,"pressure":1018}  
,{"dt":1606510800,"main":{"temp":6.64,"feels\_like":3.61,"temp\_min":6.53,"temp\_max":6.64,"pressure":1019}  
]

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 November 2020 16:56 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/2 "2020-11-27T16:56:44Z")

</div>

Have a look the javascript Array.filter() method. [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)

Have a play with that and see if you can work it out.

---

<div class="post-metadata">

### Author: ![SKES](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/skes/32/14077_2.png) [@SKES](https://discourse.nodered.org/u/SKES)
#### Post date: [27 November 2020 17:22 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/3 "2020-11-27T17:22:03Z")

</div>

Hello Colin, thanks for your response and your help. I've made progress 🙂  
If I do this, It get the expected result. It seems that my first array was incomplete also btw..

```auto
const mintemps = [
{"dt":1606489200,"main":{"temp":8.44,"feels_like":5.83,"temp_min":8.44,"temp_max":8.64,"pressure":1018}},
{"dt":1606500000,"main":{"temp":7.15,"feels_like":3.96,"temp_min":6.85,"temp_max":7.15,"pressure":1018}},
{"dt":1606510800,"main":{"temp":6.64,"feels_like":3.61,"temp_min":6.53,"temp_max":6.64,"pressure":1019}}
]

const result = mintemps.filter(mintemps => mintemps.main.temp_min <7);

console.log(result);

```

> Array [Object { dt: 1606500000, main: Object { temp: 7.15, feels\_like: 3.96, temp\_min: 6.85, temp\_max: 7.15, pressure: 1018 } }, Object { dt: 1606510800, main: Object { temp: 6.64, feels\_like: 3.61, temp\_min: 6.53, temp\_max: 6.64, pressure: 1019 } }]

---

<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: [27 November 2020 17:22 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/4 "2020-11-27T17:22:27Z")

</div>

You can also do this in the change node using [JSONata](https://docs.jsonata.org/overview.html) expression.  
e.g.

```auto
[{"id":"b0987c18.4dcc6","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[][main.temp_min < 7]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":2120,"wires":[["e8309938.fb1628"]]},{"id":"d8f3269b.a43d9","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"dt\":1606489200,\"main\":{\"temp\":8.44,\"feels_like\":5.83,\"temp_min\":8.44,\"temp_max\":8.64,\"pressure\":1018}},{\"dt\":1606500000,\"main\":{\"temp\":7.15,\"feels_like\":3.96,\"temp_min\":6.85,\"temp_max\":7.15,\"pressure\":1018}},{\"dt\":1606510800,\"main\":{\"temp\":6.64,\"feels_like\":3.61,\"temp_min\":6.53,\"temp_max\":6.64,\"pressure\":1019}}]","payloadType":"json","x":130,"y":2120,"wires":[["b0987c18.4dcc6","e8309938.fb1628"]]},{"id":"e8309938.fb1628","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":2040,"wires":[]}]

```

this will return all array items where temp\_min is less than 7.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [27 November 2020 17:26 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/5 "2020-11-27T17:26:04Z")

</div>

If you wanted just the timestamps back then if you then use `.map()` on the filtered result you can return just an array of timestamps.

---

<div class="post-metadata">

### Author: ![SKES](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/skes/32/14077_2.png) [@SKES](https://discourse.nodered.org/u/SKES)
#### Post date: [27 November 2020 17:27 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/6 "2020-11-27T17:27:46Z")

</div>

I'll try that to Cid, thank you.

---

<div class="post-metadata">

### Author: ![SKES](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/skes/32/14077_2.png) [@SKES](https://discourse.nodered.org/u/SKES)
#### Post date: [27 November 2020 17:30 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/7 "2020-11-27T17:30:25Z")

</div>

I'll have a look at .map () too. thank you (again 🙂

---

<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: [27 November 2020 17:31 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/8 "2020-11-27T17:31:26Z")

</div>

If you just want the timestamps the Jsonata expression would be `payload[][main.temp_min < 7].dt`

---

<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: [11 December 2020 17:31 UTC](https://discourse.nodered.org/t/newbie-question-openweather-5-day-prediction-filter-min-temp-value/36634/9 "2020-12-11T17:31:27Z")

</div>

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