cancel
Showing results for 
Search instead for 
Did you mean: 

Time to make the donuts!

Hi, Flow fans! 

 

My name is Sandy Ussia, and this is my first post in the Flow Community blog, though I've been fairly active in the past year answering questions in the forums and speaking about Flow at SharePoint events. My favorite thing is puzzling out how to do something, as long as it can be done without getting into code Smiley Happy

 

I ran across this question in the Flow Community forums recently, and thought it was a very interesting problem: How can I run a Flow at sunrise each day? Perhaps you need a reminder of something each day based on the sunrise (or sunset)... milk the cows, say your prayers, make the donuts...whatever. It's simple enough to have a Flow run at a certain time each day, using the Recurrence trigger, but how to have it run based on a changeable thing like the time the sun rises wherever you happen to be?

 

The idea I had was to make use of the MSN Weather connector, which among other things can tell you the sunrise time today. So... every Flow must have a trigger of some sort, something that sets it off. Unfortunately, the two triggers available with the MSN Weather connector are only related to the current weather (i.e. When the current conditions change, and When the current weather changes). However, the sunrise and sunset times (and lots of other things) are available in the weather forecast coming from this connector. But that's an Action: Get forecast for today. Meaning it can only be used within a Flow that's already been triggered. So for a trigger, I chose Recurrence - what I did here was set it to trigger daily at some hour before sunrise, e.g. 4am. You just need to be sure to select your time zone (I happen to be in Costa Rica right now), and select an hour from the checkboxes it gives you in At these hoursDaily at 4a.png

 

Next is the MSN Weather action Get forecast for today. Here, you specify the location, and the unit of measure you want to use (Imperial or Metric, i.e. F vs C temp). You can just type in a city and country, or enter a longitude and latitude, or various other things (there's a tip in the box about that).Get forecast for today.png

This action returns all sorts of interesting information!  

 

In the next step, I found I needed to do a bit of trickery with the value that came back from MSN Weather for the sunrise time. It came back in a format like 2018-04-16T11:25:50+00:00, but the following step needed it to be in standard UTC format like 2018-04-16T11:25:50Z. So the Compose action uses an expression to modify the text: 

substring(body('Get_forecast_for_today')?['responses']?['almanac']?['sunrise'],0,19)

I created the expression by using the Expression Builder, but the above is what comes out of it. Basically, I'm getting the first 19 characters of the sunset time, i.e. removing the +00:00 from the end. In Expression Builder, I selected the substring function, and then inside the () I went back to Dynamic Data and selected the Sunrise time from the Get forecast for today action. The substring function then requires a beginning position (0 in this case, for the first character) and a number of characters after that (19 in this case, counting the characters up to the + in the datetime coming back from MSN Weather).

 

 

Compose sunrise time.png

 

 

The next action is Delay Until, which pauses the Flow until a certain time. Here, the time is the Output of the Compose step, with a Z added to the end to meet the format requirement.Delay until sunrise.png

 

Something to be aware of is that all datetime outputs of a Flow action are in UTC time. So while the sunrise value of the MSN Weather action was 11:25, that equated to the actual sunrise time here in Costa Rica of 5:25am.

 

And then after that you can do whatever actions you want to do. I just sent myself a mobile notification, which buzzed my phone at 5:25am as the sun was coming up over the mountains and the birds were singing Smiley Happy

 

Send notification.png

So here's an overview of this Flow... Trigger on sunrise overview.png

 

 

 

I hope this has been useful to get you thinking of some other similar scenarios when there isn't the exact trigger available that you need.

 

Comments
Anonymous

Hello Sandy!

 

I was creating my own Flow that would send a notification at sun rise and sunset just to test out the parrallel branches. When my flow failed because of the timestamps not being in the proper format I looked to the community and found your solution. As I was editing mine to reflect your solution, I thought of a way to possibly simplifiy it another step.

composing_versus_concatenation.PNG For sunrise's alert I have your suggested solution of composing the substring and then having delay until call on the substring. On sunset's side of the Flow I used 

concat(substring(body('Get_forecast_for_today')?['responses']?['almanac']?['sunset'],0,19), 'Z')

to add the 'Z' to the rest of the timestamp all at once. 
 
Just thought I'd share back with you!
Hazel

Nice, @Anonymous 🙂

Oh, hey! You're from near my hometown of Pittsburgh! (though technically I no longer live there)

Meet Our Blog Authors
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Cambridge UK Power Platform User Group Leader, Technical evangelist and speaker. Always says yes to coffee! #LetsGetCoffee
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor
  • I am building business processes and applications that are easy for users' to stick to, so they can follow and understand them. In overall I transform processes to be more reliable and effortless. I am a proud co-organizer of SharePoint Saturday Warsaw and active community member, blogger and international speaker.