Hi!
I was wondering if someone could help me manage the msg.payload data from the 5 day forecast node openweathermap. What I would like to get out is the average temperature for the next 12 hours.
Cheers!
Hi!
I was wondering if someone could help me manage the msg.payload data from the 5 day forecast node openweathermap. What I would like to get out is the average temperature for the next 12 hours.
Cheers!
Hello @john8andersson, welcome to the forum.
The OWM 5 day forecast returns an array of 40 forecasts, 3 hourly for the next 5 days, like this:
{"cod":"200","message":0,"cnt":40,"list":[{"dt":1663891200,"main":{"temp":288.22,"feels_like":287.98,"temp_min":288.22,"temp_max":288.53,"pressure":1015,"sea_level":1015,"grnd_level":1013,"humidity":84,"temp_kf":-0.31},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":2.6,"deg":243,"gust":6.98},"visibility":10000,"pop":0.14,"sys":{"pod":"n"},"dt_txt":"2022-09-23 00:00:00"},{"dt":1663902000,"main":{"temp":288.08,"feels_like":287.87,"temp_min":287.81,"temp_max":288.08,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":86,"temp_kf":0.27},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":100},"wind":{"speed":2.07,"deg":220,"gust":5.15},"visibility":10000,"pop":0.67,"rain":{"3h":0.89},"sys":{"pod":"n"},"dt_txt":"2022-09-23 03:00:00"},{"dt":1663912800,"main":{"temp":288.03,"feels_like":287.92,"temp_min":287.93,"temp_max":288.03,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":90,"temp_kf":0.1},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":1.68,"deg":253,"gust":3.87},"visibility":10000,"pop":0.96,"rain":{"3h":0.79},"sys":{"pod":"d"},"dt_txt":"2022-09-23 06:00:00"},{"dt":1663923600,"main":{"temp":289.37,"feels_like":289.16,"temp_min":289.37,"temp_max":289.37,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":81,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":99},"wind":{"speed":1.75,"deg":340,"gust":2.46},"visibility":10000,"pop":0.39,"sys":{"pod":"d"},"dt_txt":"2022-09-23 09:00:00"},{"dt":1663934400,"main":{"temp":291.46,"feels_like":291.02,"temp_min":291.46,"temp_max":291.46,"pressure":1014,"sea_level":1014,"grnd_level":1012,"humidity":64,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":1.92,"deg":359,"gust":2.55},"visibility":10000,"pop":0.39,"rain":{"3h":0.25},"sys":{"pod":"d"},"dt_txt":"2022-09-23 12:00:00"},{"dt":1663945200,"main":{"temp":291.15,"feels_like":290.68,"temp_min":291.15,"temp_max":291.15,"pressure":1013,"sea_level":1013,"grnd_level":1011,"humidity":64,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":3.42,"deg":12,"gust":5.07},"visibility":10000,"pop":0.77,"rain":{"3h":0.93},"sys":{"pod":"d"},"dt_txt":"2022-09-23 15:00:00"},{"dt":1663956000,"main":{"temp":290.14,"feels_like":289.46,"temp_min":290.14,"temp_max":290.14,"pressure":1013,"sea_level":1013,"grnd_level":1011,"humidity":60,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":100},"wind":{"speed":2.46,"deg":6,"gust":6.39},"visibility":10000,"pop":0.67,"rain":{"3h":0.42},"sys":{"pod":"n"},"dt_txt":"2022-09-23 18:00:00"},{"dt":1663966800,"main":{"temp":287.98,"feels_like":287.16,"temp_min":287.98,"temp_max":287.98,"pressure":1014,"sea_level":1014,"grnd_level":1012,"humidity":63,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":2.87,"deg":22,"gust":7.94},"visibility":10000,"pop":0.06,"sys":{"pod":"n"},"dt_txt":"2022-09-23 21:00:00"},{"dt":1663977600,"main":{"temp":286.55,"feels_like":286.03,"temp_min":286.55,"temp_max":286.55,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":80,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":2.79,"deg":357,"gust":8.04},"visibility":10000,"pop":0.06,"sys":{"pod":"n"},"dt_txt":"2022-09-24 00:00:00"},{"dt":1663988400,"main":{"temp":285.77,"feels_like":285.31,"temp_min":285.77,"temp_max":285.77,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":85,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":2.97,"deg":351,"gust":7.92},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-24 03:00:00"},{"dt":1663999200,"main":{"temp":285.17,"feels_like":284.67,"temp_min":285.17,"temp_max":285.17,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":86,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":3.07,"deg":352,"gust":8.36},"visibility":10000,"pop":0.2,"rain":{"3h":0.12},"sys":{"pod":"d"},"dt_txt":"2022-09-24 06:00:00"},{"dt":1664010000,"main":{"temp":287.4,"feels_like":286.68,"temp_min":287.4,"temp_max":287.4,"pressure":1016,"sea_level":1016,"grnd_level":1013,"humidity":69,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100},"wind":{"speed":3.86,"deg":360,"gust":7.07},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-24 09:00:00"},{"dt":1664020800,"main":{"temp":290.69,"feels_like":289.78,"temp_min":290.69,"temp_max":290.69,"pressure":1016,"sea_level":1016,"grnd_level":1013,"humidity":49,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":99},"wind":{"speed":4.33,"deg":7,"gust":6.04},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-24 12:00:00"},{"dt":1664031600,"main":{"temp":289.68,"feels_like":288.88,"temp_min":289.68,"temp_max":289.68,"pressure":1016,"sea_level":1016,"grnd_level":1013,"humidity":57,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":4.81,"deg":23,"gust":7.17},"visibility":10000,"pop":0.46,"rain":{"3h":0.58},"sys":{"pod":"d"},"dt_txt":"2022-09-24 15:00:00"},{"dt":1664042400,"main":{"temp":288,"feels_like":287.19,"temp_min":288,"temp_max":288,"pressure":1017,"sea_level":1017,"grnd_level":1014,"humidity":63,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"clouds":{"all":100},"wind":{"speed":4.32,"deg":23,"gust":8.25},"visibility":10000,"pop":0.32,"rain":{"3h":0.27},"sys":{"pod":"n"},"dt_txt":"2022-09-24 18:00:00"},{"dt":1664053200,"main":{"temp":286.49,"feels_like":285.76,"temp_min":286.49,"temp_max":286.49,"pressure":1018,"sea_level":1018,"grnd_level":1015,"humidity":72,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":4.63,"deg":17,"gust":9.55},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-24 21:00:00"},{"dt":1664064000,"main":{"temp":285.32,"feels_like":284.5,"temp_min":285.32,"temp_max":285.32,"pressure":1018,"sea_level":1018,"grnd_level":1015,"humidity":73,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":4.18,"deg":5,"gust":9.44},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-25 00:00:00"},{"dt":1664074800,"main":{"temp":283.97,"feels_like":283.17,"temp_min":283.97,"temp_max":283.97,"pressure":1018,"sea_level":1018,"grnd_level":1015,"humidity":79,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":91},"wind":{"speed":3.91,"deg":355,"gust":10.14},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-25 03:00:00"},{"dt":1664085600,"main":{"temp":283.04,"feels_like":281.21,"temp_min":283.04,"temp_max":283.04,"pressure":1018,"sea_level":1018,"grnd_level":1015,"humidity":81,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":72},"wind":{"speed":3.6,"deg":359,"gust":10.04},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-25 06:00:00"},{"dt":1664096400,"main":{"temp":286.48,"feels_like":285.62,"temp_min":286.48,"temp_max":286.48,"pressure":1018,"sea_level":1018,"grnd_level":1015,"humidity":67,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":0},"wind":{"speed":4.27,"deg":10,"gust":7.99},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-25 09:00:00"},{"dt":1664107200,"main":{"temp":289.63,"feels_like":288.67,"temp_min":289.63,"temp_max":289.63,"pressure":1017,"sea_level":1017,"grnd_level":1014,"humidity":51,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"clouds":{"all":28},"wind":{"speed":3.62,"deg":12,"gust":4.56},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-25 12:00:00"},{"dt":1664118000,"main":{"temp":288.6,"feels_like":287.61,"temp_min":288.6,"temp_max":288.6,"pressure":1016,"sea_level":1016,"grnd_level":1013,"humidity":54,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"clouds":{"all":100},"wind":{"speed":2.44,"deg":358,"gust":3.3},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-25 15:00:00"},{"dt":1664128800,"main":{"temp":288.3,"feels_like":287.23,"temp_min":288.3,"temp_max":288.3,"pressure":1015,"sea_level":1015,"grnd_level":1012,"humidity":52,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":1.59,"deg":272,"gust":3.23},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-25 18:00:00"},{"dt":1664139600,"main":{"temp":286.5,"feels_like":285.33,"temp_min":286.5,"temp_max":286.5,"pressure":1014,"sea_level":1014,"grnd_level":1011,"humidity":55,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":2.5,"deg":250,"gust":6.69},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-25 21:00:00"},{"dt":1664150400,"main":{"temp":285.52,"feels_like":284.43,"temp_min":285.52,"temp_max":285.52,"pressure":1011,"sea_level":1011,"grnd_level":1008,"humidity":62,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":3.92,"deg":259,"gust":9.79},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-26 00:00:00"},{"dt":1664161200,"main":{"temp":284.84,"feels_like":283.84,"temp_min":284.84,"temp_max":284.84,"pressure":1007,"sea_level":1007,"grnd_level":1004,"humidity":68,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":99},"wind":{"speed":5.03,"deg":242,"gust":12.42},"visibility":10000,"pop":0.08,"sys":{"pod":"n"},"dt_txt":"2022-09-26 03:00:00"},{"dt":1664172000,"main":{"temp":284.55,"feels_like":283.99,"temp_min":284.55,"temp_max":284.55,"pressure":1003,"sea_level":1003,"grnd_level":1000,"humidity":86,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":96},"wind":{"speed":5.87,"deg":235,"gust":13.88},"visibility":10000,"pop":0.55,"rain":{"3h":0.73},"sys":{"pod":"d"},"dt_txt":"2022-09-26 06:00:00"},{"dt":1664182800,"main":{"temp":285.57,"feels_like":285.22,"temp_min":285.57,"temp_max":285.57,"pressure":1001,"sea_level":1001,"grnd_level":998,"humidity":90,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":100},"wind":{"speed":4.15,"deg":260,"gust":9.9},"visibility":10000,"pop":0.98,"rain":{"3h":1.42},"sys":{"pod":"d"},"dt_txt":"2022-09-26 09:00:00"},{"dt":1664193600,"main":{"temp":287.34,"feels_like":286.54,"temp_min":287.34,"temp_max":287.34,"pressure":1000,"sea_level":1000,"grnd_level":997,"humidity":66,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":86},"wind":{"speed":3.71,"deg":319,"gust":7.9},"visibility":10000,"pop":0.96,"rain":{"3h":0.44},"sys":{"pod":"d"},"dt_txt":"2022-09-26 12:00:00"},{"dt":1664204400,"main":{"temp":287.88,"feels_like":286.79,"temp_min":287.88,"temp_max":287.88,"pressure":1001,"sea_level":1001,"grnd_level":998,"humidity":53,"temp_kf":0},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10d"}],"clouds":{"all":78},"wind":{"speed":5.73,"deg":6,"gust":7.8},"visibility":10000,"pop":0.3,"rain":{"3h":0.34},"sys":{"pod":"d"},"dt_txt":"2022-09-26 15:00:00"},{"dt":1664215200,"main":{"temp":285.12,"feels_like":283.86,"temp_min":285.12,"temp_max":285.12,"pressure":1003,"sea_level":1003,"grnd_level":1001,"humidity":57,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":89},"wind":{"speed":4.97,"deg":345,"gust":9.2},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-26 18:00:00"},{"dt":1664226000,"main":{"temp":283.7,"feels_like":282.27,"temp_min":283.7,"temp_max":283.7,"pressure":1004,"sea_level":1004,"grnd_level":1002,"humidity":56,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":44},"wind":{"speed":4.54,"deg":323,"gust":8.64},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-26 21:00:00"},{"dt":1664236800,"main":{"temp":281.94,"feels_like":279.23,"temp_min":281.94,"temp_max":281.94,"pressure":1005,"sea_level":1005,"grnd_level":1002,"humidity":61,"temp_kf":0},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03n"}],"clouds":{"all":26},"wind":{"speed":5,"deg":313,"gust":9.55},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-27 00:00:00"},{"dt":1664247600,"main":{"temp":280.76,"feels_like":277.88,"temp_min":280.76,"temp_max":280.76,"pressure":1006,"sea_level":1006,"grnd_level":1003,"humidity":52,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"clouds":{"all":7},"wind":{"speed":4.71,"deg":309,"gust":10.37},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-27 03:00:00"},{"dt":1664258400,"main":{"temp":280.22,"feels_like":276.89,"temp_min":280.22,"temp_max":280.22,"pressure":1005,"sea_level":1005,"grnd_level":1003,"humidity":70,"temp_kf":0},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"clouds":{"all":6},"wind":{"speed":5.43,"deg":294,"gust":10.88},"visibility":10000,"pop":0.02,"sys":{"pod":"d"},"dt_txt":"2022-09-27 06:00:00"},{"dt":1664269200,"main":{"temp":282.55,"feels_like":280.45,"temp_min":282.55,"temp_max":282.55,"pressure":1005,"sea_level":1005,"grnd_level":1003,"humidity":67,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":84},"wind":{"speed":3.92,"deg":286,"gust":11.25},"visibility":10000,"pop":0.08,"sys":{"pod":"d"},"dt_txt":"2022-09-27 09:00:00"},{"dt":1664280000,"main":{"temp":286.32,"feels_like":284.71,"temp_min":286.32,"temp_max":286.32,"pressure":1005,"sea_level":1005,"grnd_level":1002,"humidity":39,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":51},"wind":{"speed":7.3,"deg":309,"gust":11.34},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-27 12:00:00"},{"dt":1664290800,"main":{"temp":286.18,"feels_like":284.66,"temp_min":286.18,"temp_max":286.18,"pressure":1004,"sea_level":1004,"grnd_level":1001,"humidity":43,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"clouds":{"all":65},"wind":{"speed":6.11,"deg":297,"gust":11.63},"visibility":10000,"pop":0,"sys":{"pod":"d"},"dt_txt":"2022-09-27 15:00:00"},{"dt":1664301600,"main":{"temp":285.44,"feels_like":284.06,"temp_min":285.44,"temp_max":285.44,"pressure":1003,"sea_level":1003,"grnd_level":1000,"humidity":51,"temp_kf":0},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04n"}],"clouds":{"all":81},"wind":{"speed":3.04,"deg":253,"gust":8.1},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-27 18:00:00"},{"dt":1664312400,"main":{"temp":284.71,"feels_like":283.57,"temp_min":284.71,"temp_max":284.71,"pressure":1002,"sea_level":1002,"grnd_level":999,"humidity":63,"temp_kf":0},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"clouds":{"all":100},"wind":{"speed":4.24,"deg":266,"gust":9.02},"visibility":10000,"pop":0,"sys":{"pod":"n"},"dt_txt":"2022-09-27 21:00:00"}],"city":{"id":2643743,"name":"London","coord":{"lat":51.5078,"lon":-0.1279},"country":"GB","population":1000000,"timezone":3600,"sunrise":1663912073,"sunset":1663955883}}
The forecast temp seems to be at payload.list[n].main.temp and I'm guessing 288.22 is in Kelvins, or else it's pretty warm in London.
So you need to add up payload.list[n].main.temp for n=0 to n=11?
I am sure there is a nice Jsonata expression to do this but I generally reach for a Function node, something like this
const datacount = 12;
let total = 0;
for (let i = 0; i<datacount; i++) {
total += msg.payload.list[i].main.temp;
}
msg.payload = total / datacount;
return msg;
For the above data it gives me 288.2483333333334.
I use this information with an horizon of 15 hours in a function node exactly in same way, but if there is a Jsonata query doing the same, I would be curious to see it.
To get the average in celsius for next 24 hours the JSONata expression would be
$round(
$average(
[$$.payload.list[dt * 1000 > $millis() - 10800000]][[0..8]].main.(temp - 273.15)
)
,2)
Thanks but I cant get this to work, just getting "TypeError": Cannot read properties of undefined (reading '0')"
Since I'm a total n00b at this I'm probably missing something very obvious.
In Node-read I have created a function node which is feed from the OWM 5day forecast node
Use a debug node to inspect the message coming from OpenWeatherMap.
Is msg.payload.list an array?
What does each element contain?
Got it working, cheers!!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.