Set the custom Focusing status in Microsoft Teams from PowerShell using Power Automate

Update 05.10.20: I have created a free way to do this using Microsoft To Do task as a trigger. No need for code adjustment, just download and use it. Read more here! If you want to use premium Power Automate trigger and PowerShell to set the status keep on reading :)

I am a Pomodoro Technique enthusiast. During a Pomodoro sprint it is important to mute distractions. This worked fine with custom presence states in Skype for Business, which is one of my most popular blog posts to date, on a daily basis. With Microsoft Teams, this has been a challenge, until now.

The Focusing custom Teams status can only be set by MyAnalytics via a calendar event called ‘Focus time‘. I have not been able to recreate this calendar event type manually, so it must be something in the header. During a ‘Focus time calendar event, the Teams client sets the status to Do Not Disturb with a custom name called Focusing. I don’t like the current way MyAnalytics schedules this event since it is two hours long and weeks in advance. I need a way to set this status at the time I am focusing, to mute distractions and tell my peers that I am in a focus, deep work, flow Pomodoro sprint.

The result using my Pomodor PowerShell timer

The Teams Focusing status fits well with the PowerShell Pomodoro Timer. As you see, it may take up to 3 minutes for the status to update, but I take what I can get :)

How I solved it

I trigger a Power Automate flow using a HTTP request trigger using Invoke-WebRequest in PowerShell. The flow takes two inputs, duration and a secret. If the secret is correct, to make sure the flow can’t be easily hacked, it gets my calendar and searches for calendar event with subject ‘Focus time’. It takes the first entry and changes start time and stop time for the event using the duration I have set, usually 25 minutes. Now I have a ‘Focus time’ calendar event that is set at the same time as my Pomodoro sprint with the same duration. After 1-3 minutes, my status will be updated to Focusing. After 25 minutes, plus 1-3 minutes, my status will be reset. BOOM, how cool is that!?

Prerequisites

  • Calendar must be in Exchange Online
  • You must have MyAnalytics as part of your license and enabled
    • Schedule 1 period with MyAnalytics to get the calendar event
    • Available in Enterprise SKU’s
  • You must have Power Automate license and ability to use Premium triggers
    • The trigger used is HTTP request and is a Premium trigger
    • You may find that you can use other free triggers as well
    • Premium triggers are included in Dynamics 365 SKU’s
    • Premium triggers are not included in Microsoft 365 SKU’s
    • The standalone $15 Per User plan can run Premium triggers
  • If you want to use a trigger included in your Office 365 plan, check out my other method, using Microsoft To Do task as trigger

Creating the calendar event and importing the Power Automate flow

  • Create the calendar event in MyAnalytics
  • Import the flow in your Power Automate
    • Download the RescheduleFocusTimeCalendarEvent.zip file here
    • Navigate to your personal Power Automate dashboard at https://flow.microsoft.com/
    • Go to My flows in the left menu and click Import
    • Click Upload and choose the zip file
    • To be able to complete the import you must click the wrench in the first line and choose Create as new under Setup
    • Next you must create the Outlook connector by clicking on the wrench in the second line for Related resources
      • Click Create new
      • Scroll down to Office 365 Outlook, click Create and authenticate as your user
      • Now you have created the Outlook connector, go back to the flow import website and select you new connector and Save
      • Import the flow by clicking Import
      • The import should be successful, navigate to My flows
    • Edit your new flow called RescheduleFocusTimeCalendarEvent
    • Now, let’s go through it and update the flow for your environment

Configuring the Power Automate flow

Click Edit on the flow and expand When a HTTP request is received and copy the HTTP POST URL and save it for later

Expand Condition and change MySecret to your own and take note of it

If no is there to trigger if the secret is wrong, it is a small security measure so that people not easily can steal you flow URL, but they also need the secret, or you can change it if it does get lost

Under If yes, expand Connections, click connect and delete the current guid, then you will be able to choose your calendar

Click advanced options in Get Events (V4) and validate that we are finding calendar events with subject ‘Focus time’ and we are getting the first entry. This means it does not matter how many events of ‘Focus time’ you have in your calendar. Expand Current time and Get future time. Future time is controlled by the duration variable we sent to the HTTP trigger.

Expand Apply to each and Update event (V4). Again, you need to choose your calendar. Id is the ‘Focus time’ calendar event, Subject is the same, Start time is our current time, End time is our future time and choose your timezone

That’s it! You are now ready to invoke your flow. In PowerShell you need to run the following code

[int]$Minutes = 25 #Duration of your Pomodoro Session, default is 25 minutes
[string]$Secret = "MySecret" #Secret for the flow trigger
[string]$AutomateURI = "YourFlowTriggerURI" #The URI used in the webrequest to your flow


#Invoking PowerAutomate to change set current time on your Focus time calendar event, default length is 25 minutes
    $body = @()
    $body = @"
        { 
            "Duration":$Minutes,
            "Secret":"$Secret"
        }
"@
Invoke-RestMethod -Method Post -Body $Body -Uri $AutomateURI -ContentType "application/json"

Go back to Power Automate and validate that the flow ran, check your Outlook calendar that the ‘Focus time’ event was moved to now and wait up to 3 minutes to see your status change. When the calendar time is over, your status will be reset and you are available again.

The practical approach with the Pomodoro PowerShell timer

With the ability to control the status in Teams, I believe the Pomodoro PowerShell timer is feature complete. One thing is to be unavailable and reduce distractions, but it is very important to automatically become available again. The reason for WHY you would use this kind of timer and automation is to avoid getting distracted which breaks your flow and deep work. Research shows that it takes between 7-30 minutes to get back in to flow after you have seen just one email or message. Here is what the script does

  • Starts presentation mode to block popups on your computer
  • Hides badges on taskbar so that you do not get distracted by seing that you have a new mail, task or chat
  • Opens you favorite flow and deep work Spotify playlist so that you do not spend time figuring out what to listen to
  • Uses IFTTT to mute your phone, works with Android and iOS
  • Finally set your status in Teams to Focusing
  • After the Pomodoro sprint is over, everything will be turned back on again

Below is a sample code to run the Start-SimplePmodoro.ps1 script which you can download from GitHub

Start-SimplePomodoro `
-SpotifyPlayList spotify:playlist:XXXXXXXXXXXXXXXXXX `
-IFTTTMuteTrigger pomodoro_start `
-IFTTTUnMuteTrigger pomodoro_stop `
-IFTTTWebhookKey XXXXXXXXX `
-Secret YourFlowSecret  `
-AutomateURI YourAutomateURI `

Why is it important to automatically become available?

You have been gone for 25 minutes, use the pause to check if anyone has been trying to reach you, re-prioritize your tasks, get more coffee and then dive in to a new Pomodoro sprint. After 25 minutes it is OK to get distracted, but if nothing happens, just stay in the flow you jump started and get stuff done. Download the Pomodoro PowerShell timer from GitHub

Updated my #Pomodoro #PowerShell timer

Ever been so busy you can’t get anything done? What do I do during those times? Spend time optimizing my productivity routine of course. June 2020 was super busy period for me and I found that my PowerShell Pomodoro timer needed some tuning to be easier to use. Download the updated script from GitHub. I have done the following changes

  • Hide Badges on taskbar buttons
  • Create a shortcut to start it in a fast and simple way
  • Fixed so that presentationsettings.exe works in 64bit PowerShell
  • Read my original post about this script
  • Pomodoro is a technique to induce flow in a busy workday through single tasking. Read more at the end of this blogpost

Hide badges on taskbar buttons

Instead of stopping Microsoft Teams, I hide the badges on taskbar buttons such as Outlook, Teams and Microsoft To Do. You must have access to changing the registry for this to work which was the best approach I could find.

#Hide badge or stop Teams
if ($Teamsmode -notmatch "HideBadge"){
    #Stop Microsoft Teams
    Write-Host "Closing Microsoft Teams" -ForegroundColor Green
    Get-Process -Name Teams -ErrorAction SilentlyContinue | Stop-Process -ErrorAction SilentlyContinue
}
else{
    #Hiding badges on taskbar buttons such as Outlook, Teams and ToDo
    Write-Host "Hiding badges on taskbar buttons" -ForegroundColor Green
    Set-Itemproperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced' -Name 'TaskbarBadges' -value '0'
    Stop-Process -ProcessName explorer
}

During hide badge you will not see status in the taskbar icons, which helps you keep focus during the Pomodoro sprint.

When the Pomodoro sprint is finished, it will show badges again

Showing badge on taskbar app is new in Microsoft To Do and can be turned on or off under settings, I prefer to turn it off

Create a shortcut to start it in a fast and simple way

In order to start the script in an fast and simple way, you can create a shortcut to the script.

  1. On you desktop, right click and select new shortcut
  2. In the shortcut target box, type the following:
    • powershell.exe -noexit -ExecutionPolicy Bypass -File
  3. File is the path where you stored the Start-SimplePomodoro.ps1
    • “C:\Users\UserName\OneDrive – CloudWay\Dokumenter\GitHub\MyScripts\Start-SimplePomodoro\Start-MySimplePomodoro.ps1”
  4. I have crated an Icon you can use for the shortcut which you can find on GitHub
  5. If you pin it to you taskbar, you can easily start your Pomodoro sprint

Fixed so that presentationsettings.exe works in 64bit PowerShell

I use presentationsettings.exe to put the computer in presentation mode which supresses popups from all you applications and Windows 10. This is an 32bit application. I found that 64bit PowerShell could not find this due to the feature, File System Redirector. I found a workaround and incorporated it in the script so that it works wherever you are running it

Write-Host "Starting presentation mode" -ForegroundColor Green
if (Test-Path "C:\Windows\sysnative\PresentationSettings.exe"){Start-Process "C:\Windows\sysnative\PresentationSettings.exe" /start -NoNewWindow}
else {presentationsettings /start}

By pointing 64bit PowerShell to the path C:\Windows\sysnative\ I was able to run 32bit apps like PresentationSettings.

The result

Download the script from GitHub

The goal is to induce the flow state in a busy workday

Multitasking is a myth. The goal is to reach the flow state by focusing on one task at a time. Have you ever started writing an email, thought you sent it and eagerly waiting for a response, only to find it incomplete and unsent at the end of the day? This is one of the perils of multitasking.

The Pomodoro Technique is a great methodology to induce flow in a busy workday. It is all about avoiding distractions for 15-25 minutes and focus on one task at a time. This is a short enough period in the day that you can squeeze it in before a meeting. It is incredible what you can get done 15-25 minutes. The goal is to not get distracted and it takes about 7 minutes of focus before you reach your flow state.

If you want to succeed with Pomodoro, you need to make yourself unavailable. Equally important, you need to make yourself available again when those 25 minutes have passed. That is why we created the Pomodoro PowerShell tool, and why I love the simplicity of this approach.

Watch an outtake from my session at Microsoft Ignite 2017 on single-tasking

Learn more on my thinking around single-tasking and tools available to succeed with the flow state, from this outtake of my OneNote LifeHacks talk at Microsoft Ignite 2017

Happy deep work!

Announcing the Pomodoro Windows app

August 2017 MVP Jan Egil Ring and I launched an open source PowerShell based Pomodoro timer. This is a great way to get stuff done, but difficult to get started with. Andreas Kang Schøyen over at Lillevik IT has done something about that and created an executable program that sets up the integrations and timer.

How it works

When downloading and installing the app, it will automatically integrate with your Skype for Business 32 bit application and your Windows OS making it capable to:

  • Set you to “do not disturb” in Skype for Business with a custom presence state called Pomodoro Sprint
    • The app cotains the SDK dll’s for the Skype for Business client, so no extra installs to control presence
  • Write a note of your choosing during the the Pomodoro sprint and adding the time when you will be available
    • It even counts down the last 15 seconds, so that people waiting to reach you that you are about to become available
  • Write a note of your choosing after the Pomodoro sprint is complete
  • Set your computer in to presentation mode which suppresses popups
  • Start your favourite Spotify playlist for productivity
  • Make you available again when the sprint is finished

The app supports automatic updates and the roadmap includes IFTTT ingration so that you can mute your phone during the pomodoro sprint. See full roadmap here

PomodoroV2

The goal is to induce the flow state in a busy workday

Multitasking is a myth. The goal is to reach the flow state by focusing on one task at a time. Have you ever started writing an email, thought you sent it and eagerly waiting for a response, only to find it incomplete and unsent at the end of the day? This is one of the perils of multitasking.

The Pomodoro Technique is a great methodology to induce flow in a busy workday. It is all about avoiding distractions for 15-25 minutes and focus on one task at a time. This is a short enough period in the day that you can squeeze it in before a meeting. It is incredible what you can get done 15-25 minutes. The goal is to not get distracted and it takes about 7 minutes of focus before your reach your flow state.

If you want to succeed with Pomodoro, you need to make yourself unavailable. Equally important, you need to make yourself available again when those 25 minutes have passed. That is why we created the Pomodoro PowerShell tool, and why I love the simplicity of this app.

Read more and download the exe and MSI version of the app here: http://pomodoro.lit.no

Watch an outtake from my session at Microsoft Ignite 2017 on singletasking

Learn more on my thinking around singletasking and tools available to succeed with the flow state, from this outtake of my OneNote LifeHacks talk at Microsoft Ignite 2017

Complete lists of your tasks is key to success

An important part of succeeding with the Pomodoro Technique is lists. Lists enables you to choose the task that lifts the most weight off your shoulders at that point in time. I use OneNote to capture all my ideas and actions, enabling me to create that finite list of tasks. Check out how I do it in my OneNote LifeHacks YouTube series