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
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 hours.
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).
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).
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.
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
So here's an overview of this Flow...
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.