Enhancing Your Power Automate Flow to Retrieve Actual Opening Hours

Enhancing Your Power Automate Flow to Retrieve Actual Opening Hours

I’ve received a lot of positive feedback on my previous post about checking opening hours, along with numerous requests for a way to retrieve the actual opening hours instead of just the status. I was hoping for some function on this within release wave 1 2025. But as I could not find anything concerning this,

In response to the questions, I’ve revisited Power Automate to make some modifications to my original workflow. This post is an extension of my earlier one, which you can find here: https://sjoholt.com/opening-hours/

Updated Workflow Overview

For detailed steps, please refer to the original post, found here:

The updated flow now includes several enhancements:

Key Updates

  1. Incorporation of ‘Do Until’ Loops: These loops follow changes in the TimeCode.
  2. Definition of Four New Variables:

New variables

The initial value of startTime is set to:

 @{startOfDay(utcNow())}

which starts the check at 00:00 on the current date. If your opening hours never start before a specific time, it’s better to use that as the starting point. For example, to start the check at 6 AM UTC, use something like:

addHours(startOfDay(utcNow()), 6)

Finding the Start of Opening Hours

The overall view of the step can be seen here:

This section creates an input and checks the resulting TimeCode. If the chat is not open at the tested time, it increments the startTime parameter and tests again until it finds the opening time.

Creating the Opening Parameter

The opening parameter is created with:

{
  "StartDate": "@{variables('startTime')}",
  "EndDate": "@{variables('startTime')}",
  "CalendarIds": [
    "@{outputs('Get_the_calendar')?['body/calendarid']}"
  ]
}

We then use the same unbound action as before with this input and parse the JSON with the following schema:

{
  "type": "object",
  "properties": {
    "@@odata.context": {
      "type": "string"
    },
    "CalendarEvents": {
      "type": "string"
    }
  }
}

Implementing Conditions

We implement a condition to check the result from the parse. Here is an overview of this flow step:

We use the same length check as earlier to ensure our parse contains the TimeCode. If not, we set tempTime to startTime and update startTime with an incremented time from tempTime.

If the JSON returns a value, we check if the substring is 0, indicating the chat is open. If the chat is open, we have found the opening hours and can proceed to the next step. If the returned value is not 0, the chat is not open at the specified time, and we increment the time again using the same step as the previous condition.

Expressions Used

  • Compose: Get Timecode for opening hours
split(body('Parse_JSON_2')?['CalendarEvents'], 'TimeCode":')[1]
  • Compose: For printable results
substring(outputs('Get_TimeCode_for_openinghours'), 0, 1)
  • check if TimeCode is correct
substring(outputs('Get_TimeCode_for_openinghours'), 0, 1)
  • Set tempTime: To startTime
variables('startTime')
  • Set startTime: From increment of tempTime
addMinutes(variables('tempTime'), 30)

To exit the loop we set the variable tempBoolean, we now have our opening time stored in the variable startTime

Finding the End of Opening Hours

Next, we set the initial value of endTime equal to startTime and follow a similar procedure to find the end time. The overview can be seen here:

For the condition check in block Condition 4, we have the following Power Automate setup, with minor but important changes from the opening hours process.

If the JSON does not return a valid value, the calendar is not open at the provided time, and we have our closing time response for the final step. If the JSON returns a valid response, we check if the calendar is open or closed. If the returned value is 1, the calendar is closed, and we have our closing time.

Legg igjen en kommentar

Din e-postadresse vil ikke bli publisert. Obligatoriske felt er merket med *