Display Rain in Google Calendar

Display Rain in Google Calendar

December 28th, 2022 / 263 words / 2 min read


As I've started to use Google Calendar to schedule more and more of my life, I've found that during the winter, it's really useful to know when it'll be raining. Of course this can be achieved through a variety of weather apps and websites, but it's a hassle to have to open an app, see when it's going to rain, and then update events accordingly. It would be much easier if hourly rain showed up as an event within Google Calendar!

So, I decided to attempt to create a solution with OpenWeatherMap and Google Apps Script. It turned out to be much simpler than I thought!

You can view a gist with the full code here, but here's a quick rundown of how the script works:

  1. All events are cleared on the "Rain" Google Calendar.
  2. The script calls OpenWeatherMap's onecall API to get the next 48 hours of hourly weather data.
  3. The script then loops through every hour.
    1. If rain starts in a given hour, the timestamp is stored as the start of a "rain period".
    2. If rain continues in a given hour, the duration of the current "rain period" is extended.
    3. If rain stops in a given hour, the current "rain period" is uploaded to Google Calendar.
  4. If the current rain period hasn't stopped, the script uploads it to Google Calendar.

Using Google Apps Script, the script is automatically run every hour, so the forecast stays current. Unfortunately, OpenWeatherMap only provides the next 48 hours of hourly data for free, but this small script is still useful for some scheduling in the near future.

Loading comments...