May 16

Sunrise forecast using the AerisWeather API

The sunrise marks the beginning of a brand new day. The ever-changing nature of weather means each new day brings with it the need for a new forecast. Whether you’re deciding what to wear for your morning run or wondering what the skies will be like as you photograph the sunrise, the weather is important. Our Aeris Weather API can provide the tools needed to find the sunrise forecast. This article will provide an example of how to use the Aeris Weather API endpoints to find the sunrise forecast.

Sunmoon Endpoint

Our sunmoon endpoint provides a potpourri of information about the sun and the moon. Anything from sunrise/set, twilight, moonrise/set and the phase of the moon.  In our example, we are going to grab the sunrise times for the next week. We will be using the filter parameter to return just the sunrise time. The example shows two different time formats that are supported (dateTimeISO 8601, and UNIX timestamp). Here is an example of grabbing the sunrise time for the next 7 days.


The JSON object returned should look like this.

Example of sunrise API Output for creating a sunrise forecast.

Example of Sunrise API Output

That’s the first part of the puzzle. We have the sunrise time but how do we find what the sunrise forecast looks like? We can use the forecasts endpoint and insert our results from the sunmoon endpoint.

Forecasts Endpoint

The forecasts endpoint returns a plethora of information for given points and is available in daily, day/night, and custom intervals. For this example, we will be using a 1hr filter. The following will return the entire forecasts endpoint result for the first sunrise time from the above snippet and labeled as   in this example.

There, we’ve now grabbed the sunrise time and used that to glean the sunrise forecast.  Let’s combine everything in a little script to demonstrate further what we’ve accomplished.

Sunrise forecast using the Aeris Weather API

We’ve gone over how to find the sunrise forecast using the sunmoon and forecasts endpoints. You can also do the same for the sunsets and see what the forecast is for viewing a full moon. The possibilities are endless with the Aeris Weather API. You can get started building on the aforementioned possibilities today by signing up for a free developer account.

Happy coding!

Share this post:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.