Share via


Updating Users With Daily Weather Forecasts Using Logic Apps

Problem Scenario

ABC PVT LTD is a fictional services based company with a large employee base. As part of the employee convenience program, the company provides transport to the employees. To get the employees better prepared for the travel, the company has decided to send daily weather forecasts to the employees so that they can decide on the factors which will ease their travel  (e.g. carrying an umbrella if there is rain forecast or wearing light colored clothes if a warm or hot weather is predicted).

Proposed Solution

Using Microsoft Azure Logic Apps offering, the functionality can be achieved with ease and without too much development of code. This provides and opportunity to the company to go serverless and just pay for what they use on the Azure, no servers or their maintenance cost is required.  The proposed solution for this functionality can  be represented as per below diagram.

                                 

The Logic app functions on the customizable recurrence trigger which initiates an instance of the logic app which in turn calls the MSN weather forecast api and fetches the forecast details for a particular place. Once the forecast details are fetched the logic app then sends out the email notification which can include a single user or a distribution list.

Constructing The Logic App

Before constructing the Logic App, it is necessary that the developer has a subscription for Microsoft Azure. The subscription can be created on the Azure portal. For a free trial subscription,  Free Azure Trial can be referred.

Following are the steps

1) Create MailWeatherForecast logic app as shown below. Click On the Create button on the blade.

                                                                 

2) Once the logic app is deployed, open the Logic Apps designer and Put in a Recurrence trigger as shown below.

                                

3) Add the MSN Get Forecast for today as the action  post the recurrence trigger. Enter the location for which the forecast is required and the units in which it needs to be fetched( available units are Imperial and Metric).

                                

4) Add an action to send the mail to the user or a distribution list. Here Gmail connector is used. But other than Gmail, SMTP and Outlook connectors can be explored and use. Select the GMAIL -Send Email . Configure the Gmail connection and then set the properties for the connector as shown below.

                                                           

5) The code for the body part of the send email connector is as below. This can be pasted directly in the body tag in the Logic App code view.

 "<p>Hi,</p> 
<p>Weather forecast for @{body('Get_forecast_for_today')?['responses']?['source']?['location']} for @{body('Get_forecast_for_today')?['responses']?['daily']?['valid']} is as follows</p>
<p>Conditions: @{body('Get_forecast_for_today')?['responses']?['daily']?['pvdrCap']}</p>
<p>Chance Of Rain: @{body('Get_forecast_for_today')?['responses']?['daily']?['precip']} %</p>
<p>Max Wind Speed: @{body('Get_forecast_for_today')?['responses']?['daily']?['windMax']}</p> 
<p>To get full weather forecast follow below link.</p>
<p>@{body('Get_forecast_for_today')?['responses']?['source']?['clickThrough']}</p>
<p>\nRegards</p>,
<p>Weather Forecast Team</p>"

6) The Final Logic App design Looks like below.

                                        

7) Save the Logic App and start it.

Sample Test

Once the logic app is started , the recurrence trigger will initiate the logic app workflow once every day and then send the weather forecast to the intended user(s).

A sample mail received from the Logic App is shown below.

                                      

Conclusion

Microsoft Azure Logic apps coupled with the MSN forecast api can be used to set up a weather forecast alert system for the employees of ABC PVT ltd.

See Also

More information about logic apps and logic apps connectors can be found on below links.