# Openweathermap Historical Data

**URL:** <https://discourse.nodered.org/t/openweathermap-historical-data/49930>\
**Category:** Feature Requests\
**Created:** [19 August 2021 20:51 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930 "2021-08-19T20:51:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fixjunk](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@fixjunk](https://discourse.nodered.org/u/fixjunk)\
**Post date:** [19 August 2021 20:51 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/1 "2021-08-19T20:51:44Z")

</div>

OpenWeatherMap (OWM) has historical data available but there's no option in the current nodes for obtianing it.

I use this node as part of an automated watering system. I can reliably check for future rain and decide on watering but I can't easily find out if it _already_ rained. I have noticed that I'm watering after flash flood warnings.

So rather than adding historical data to NodeRED, I'd rather just call the OWM API and find out how much rain we've had in the last day and then decide if I want to water.

Looks like all it needs is an additional UTC Unix value that falls in the last five days (which I'm sure someone more clever than I am can turn into a relative "days, hours, minutes ago" entry in the node).

fixjunk.

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [19 August 2021 23:19 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/2 "2021-08-19T23:19:49Z")

</div>

The [weather display](https://flows.nodered.org/flow/d7af9f5d6f6923324466c58ea4f0655f) I found and use doesn't need and specific weather node, just runs off the API data

> [@fixjunk](#):
>
> Looks like all it needs is an additional UTC Unix value that falls in the last five days

Just subtract the equivalent time of a day in UNIX time.

JavaScript uses milliseconds, so first convert todays UNIX timestamp to milliseconds then delete the equivalent of 24 hours (in milliseconds that is 86400)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/2/e2e7af406ec2c5c64aded9b48c7928d752bd924e.png)

```auto
[{"id":"34fa6b955b5a850f","type":"function","z":"3df5b2d46b354704","name":"Yesterday","func":"let past = msg.payload - (86400) * 1000 // Convert UNIX to milliseconds and remove one day\nmsg1 = {payload: past};\nlet pastday = new Date(past).toLocaleString(\"en-US\");\npastday = pastday.replace(\",\",\"\"); // OPTIONAL Remove Commas\nmsg2 = {payload: pastday};\nreturn [msg1,msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":540,"wires":[["21b7b709900ee1bd"],["72dff8d4f9293e7b"]]},{"id":"33e0242831cabb83","type":"inject","z":"3df5b2d46b354704","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":500,"y":540,"wires":[["34fa6b955b5a850f","1c0b31c42a8e5cc0","beeb57da5e0ce076"]]},{"id":"21b7b709900ee1bd","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":520,"wires":[]},{"id":"1c0b31c42a8e5cc0","type":"function","z":"3df5b2d46b354704","name":"Today","func":"let past = msg.payload\nmsg1 = {payload: past};\nlet pastday = new Date(past).toLocaleString(\"en-US\");\npastday = pastday.replace(\",\",\"\"); // OPTIONAL Remove Commas\nmsg2 = {payload: pastday};\nreturn [msg1,msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":670,"y":380,"wires":[["4728f80a8e9a1d25"],["428439e2b8e1ea46"]]},{"id":"4728f80a8e9a1d25","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":360,"wires":[]},{"id":"beeb57da5e0ce076","type":"function","z":"3df5b2d46b354704","name":"Two days ago","func":"let past = msg.payload - (86400*2) * 1000 // Convert UNIX to milliseconds and remove two days\nmsg1 = {payload: past};\nlet pastday = new Date(past).toLocaleString(\"en-US\");\npastday = pastday.replace(\",\",\"\"); // OPTIONAL Remove Commas\nmsg2 = {payload: pastday};\nreturn [msg1,msg2];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":700,"wires":[["570e0444de929f21"],["b0c7410ab8cd31cb"]]},{"id":"570e0444de929f21","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":680,"wires":[]},{"id":"428439e2b8e1ea46","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":420,"wires":[]},{"id":"72dff8d4f9293e7b","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":580,"wires":[]},{"id":"b0c7410ab8cd31cb","type":"debug","z":"3df5b2d46b354704","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":830,"y":740,"wires":[]}]

```

Now feed that number into the API for historical data.

You will have to account for each additional past day and submit the request up to five times for the 5 day history.

> **[Historical weather API - OpenWeatherMap](https://openweathermap.org/history)**
>
> We provide hourly historical weather data for cities via History API for 37,000+ cities.

---

<div class="post-metadata">

**Author:** ![fixjunk](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@fixjunk](https://discourse.nodered.org/u/fixjunk)\
**Post date:** [20 August 2021 00:19 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/3 "2021-08-20T00:19:47Z")

</div>

thanks @Gunner I will look into it.

I don't need a dashboard, but that's ok.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [20 August 2021 15:26 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/4 "2021-08-20T15:26:09Z")

</div>

The `node-red-contrib-moment` node is very handy for doing offset datetime calculations, too.

So for example, you can ask for a date 5 days ago -- no data arithmetic involved, and no worrying about leap seconds, timezone offsets, and daylight savings adjustments.

---

<div class="post-metadata">

**Author:** ![fixjunk](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@fixjunk](https://discourse.nodered.org/u/fixjunk)\
**Post date:** [20 August 2021 19:30 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/5 "2021-08-20T19:30:33Z")

</div>

@Gunner Between the weather display example and the previous dates functions, I managed to cobble together a very useable subflow that appears very similar to the existing openweathermap nodes. You put in the same basic data (lat, long, api, units, etc.) plus add a "Days ago" selection from 1 to 5.

when it receives a timestamp, it generates a weather report for the date a number of "days ago" and outputs it. I then sum up the rain.1h data and have my previous day rainfall total.

perfection!

---

<div class="post-metadata">

**Author:** ![fixjunk](https://avatars.discourse-cdn.com/v4/letter/f/e47c2d/32.png) [@fixjunk](https://discourse.nodered.org/u/fixjunk)\
**Post date:** [14 October 2021 14:24 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/6 "2021-10-14T14:24:18Z")

</div>

@Gunner

I have noticed today that without any changes to my API call, OWM historical data has been reporting rain at certain times when there was no rain...

here's a nearby example:  
[https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=39&lon=-77&appid=2a9f71f67144ad1076b1db7308123ff6&units=imperial&lang=en&exclude=minutely&dt=1634134779](https://api.openweathermap.org/data/2.5/onecall/timemachine?lat=39&lon=-77&appid=2a9f71f67144ad1076b1db7308123ff6&units=imperial&lang=en&exclude=minutely&dt=1634134779)

There was no rain at those coords but OWM shows several entries for rain. It's actually worse at my exact lat/long (but I don't want to share them) and it's negatively impacting my automatic watering system.

Have you had any issues like this? Could it be a local station error? This has been going on for a few days...

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [14 October 2021 23:46 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/7 "2021-10-14T23:46:03Z")

</div>

I honestly don't track reality with the history on my setup...

Your supplied Lat/Lon just allows the API to find the closest available data source to it, but most of these reports will come from specific locations, like airports, and it is entirely possible to have notable differences in types of weather across a local area, say a city.

---

<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:** [13 December 2021 23:46 UTC](https://discourse.nodered.org/t/openweathermap-historical-data/49930/8 "2021-12-13T23:46:56Z")

</div>

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