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

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

Set yourself unavailable with this open source PowerShell based Pomodoro timer

Update: An executable Windows app has been created based on this open source script to simplify the process. Read about it here

MVP Jan Egil Ring and I have created a GitHub PowerShell project called PsProductivityTools. There you will find a function called Start-Pomodoro with the following features

  • Count down for 25 minutes by default or a period specified by you
    • Start-Pomodoro -Minutes 10
  • The function will set your computer in presentation mode which will suppress all notifications and popups on your windows machine
  • Set your Skype for Business client in Do Not Disturb using a custom presence state called Pomodoro Sprint and set your personal note to when you will be available
  • You can mute and unmute your phone during the Pomodoro Sprint using IFTTT triggers
    • You need to have created the mute and unmute triggers, generated a webhook key and installed IFTTT on your mobile
    • Will write a tutorial in a later blogpost
  • It will make you available again after 25 minutes or your specified time, turning on notifications, making you available again in Skype for Business and unmute your phone. Awesome stuff :)

This is an open source project on GitHub so please feel free to add your own suggestions to the project.

How to get started

  1. Open PowerShell and run the following cmdlet
    • Install-Module -Name PSProductivityTools
    • if you need to update it later run Update-Module -Name PSProductivityTools and restart all PowerShell instances
    • You need to run PowerShell as administrator in order to install the module
  2. Now you can run Start-Pomdoro at any time from PowerShell
    • Start-Pomodoro
      • This will set your computer in presentation mode
    • Start-Pomodoro -Minutes 15 -EndPersonalNote “It’s a good day today”

What is the Pomodoro Technique?

The goal of the technique is to reduce the impact of internal and external interruptions on focus and flow. A pomodoro is indivisible. When interrupted during a pomodoro, either the other activity must be recorded and postponed (inform – negotiate – schedule – call back) or the pomodoro must be abandoned. The technique uses a timer to break down work into intervals, traditionally 25 minutes in length, separated by short breaks. These intervals are named pomodoros. Read more about the Pomodoro Technique here

Why the Pomodoro Technique?

If I can get one Pomodoro done in between meetings, workshops and calls, then I am happy. That Pomodoro is priceless and it helps me answer that long email, get started on that document or wrap my head around a problem. 25 minutes is long enough so that I can reach my flow state and short enough that I feel that I actually can do it. It may take between 5-10 minutes to reach the flow state. If I manage to interrupt myself with social media, coffee break or decide to do something else, then I may spend longer time in total on that email instead of just get it done during a Pomodoro. If you want to succeed with Pomodoro, you need to make yourself unavailable, but equally important, you need to make yourself available again when those 25 minutes have passed. That is why we created the Pomodoro PowerShell tool

What is flow?

Flow is the peak performance state where you feel your best and you perform your best. The good news is, it’s hackable. One of the hacks is inducing flow using the Pomodoro Technique. Read more about flow over at the Flow Genome Project

An important part of succeeding with the Pomodoro Technique is lists with your most important tasks that you can prioritize. I use OneNote for that. Check out how I do it in my OneNote LifeHacks YouTube series 

How to set custom presence states in Skype for Business on your Windows machine

This works on Windows 10, Windows 8, Windows 7, Lync and Skype for Business desktop clients. Requires administrative rights to your computer. If you are interested in setting Microsoft Teams status, check out how to set the custom Focusing status blogpost

Wouldn’t it be cool if you could change your presence state in Skype for Business to match you current task such as busy in a Workshop, Do Not Disturb in a Pomodoro Sprint or Away Getting Coffee?

Turns out, you can by creating an XML file and adding a setting in your local registry. How? The easy way is to download my script, change the custom presences that is predefined in the script and run it.

  1. Download the script from TechNet Gallery
  2. The default custom presence states are shown below
  3. To change the names you need to open the script and write your own presence states
    • Away does not work as a custom presence state, if you put that in no custom states will show up in the client
    • The presence states that works are: Online, Busy, and Do-Not-Disturb
  4. To run the script, just type the following in PowerShell in elevated mode from the location you saved it
    • .\Set-CsCustomPresence.ps1
    • It works for Lync and Skype for Business
    • It works for 64-bit and 32-bit office
    • It works for MSI installed Office and Click-to-Run Office
    • The xml file will get stored under c:\_CustomPresence\CustomPresence.xml if that is your systemdrive
  5. You need to sign out of the client and back in for the changes to take effect
  6. The presence states works in the following scenarios
    • On English Skype for Business clients for you and your colleagues
    • On Skype for Business clients in your local location retrieved using (Get-Culture).LCID
    • For everyone in your Colleagues relationship level as long as they are running a client language version specified above
    • If you want external contacts to see your custom presence state you need to elevate them as colleagues in the relationship pane
      • Understand that they will also see you as in a meeting, in a call, your note and your location as well
    • If you are in an environment with more than two languages for you Office deployment, make sure you add an LCID per language in the script

Download the script here and use PowerShell to control your presence using the Lync 2013 Client SDK described here

You can now control you custom presence states using PowerShell, if you have installed the SDK, using the Publish-SfBContactInformation.ps1 found on GitHub here with this syntax

Publish-SfBContactInformation -CustomActivityId 1 -PersonalNote "Getting Stuff Done" -Location "@HomeOffice"

You are now ready to use this in a Pomodoro context, read how to get started with the open source PowerShell based Pomodoro timer here: https://msunified.net/2013/11/25/lock-down-your-lync-status-and-pc-notifications-using-powershell/

Office Communicator Custom Presence States

Any Post starting with this disclaimer means that this post was not written by me however I liked it and added to my blog. I will also include the link to the original or similar post to provide credit to the original author

http://technet.microsoft.com/en-us/library/bb963925.aspx
http://blogs.technet.com/toml/archive/2007/11/30/oc-custom-presence-states.aspx 
http://blog.tiensivu.com/aaron/archives/1341-Little-known-Office-Communicator-2007-feature-Custom-Presence-States.html
http://blogs.technet.com/brettjo/archive/2008/08/19/communicator-and-ocs-tech-tip-8-custom-presence.aspx

Office Communicator 2007 offers a few user defined areas, the Note, your location and Custom Presence

Please note something important – there is no defined custom presence that includes the Yellow (away) status. The reason is that it is not supported as it was deemed to be a value that you wouldn’t set yourself but would be set based on your activity. I would agree with that for Away but Be Right Back I can set but it is what it is. What happens if you set one of the states to the Yellow (away) states – none of the custom presence items show.

Another item to note that can be a bit annoying – you can’t sign in with the custom presence, you have to sign in with a standard state and then change. My approach is to pick the state that matches what I will eventually select with my custom text.

Universal limitations

  • You can only define up to 4 custom entries.
  • Maximum length of the custom presence description is 64 characters.
  • XML customState availability can be set to “online”, “busy” and “do-not-disturb”.
  • If you want the custom states set for everyone on the computer system instead of the current user, you need to change the .REG file from HKCU to HKLM. (Mostly only useful for TS servers)

Here is syntax for presence.xml used for what you see and a reg file syntax is also included. Please note that you can put the xml anywhere just update the reg file syntax for the correct path.

NOTE: The LCID=”1033″ specify the language of the clients you want the custom presence to be displayed . 1033 is english, if your contacts have clients with different languages you need to find the corresponding language code. See list of locale ID (LCID): http://msdn.microsoft.com/en-gb/goglobal/bb964664.aspx You can have multiple languages for the same state so that it works for different clients. If you use the program that you can download at the bottom of this post you need to manually change the LCID in the generated xml

<customStates>
    <customState ID=”1″ availability=”online”>
        <activity LCID=”1033″>Out and about – use mobile</activity>
        <activity LCID=”1044″>Out and about – use mobile</activity>
    </customState>
    <customState ID=”2″ availability=”Busy”>
        <activity LCID=”1033″>Down in the lab – use mobile</activity>
        <activity LCID=”1044″>Down in the lab – use mobile</activity>

    </customState>
    <customState ID=”3″ availability=”busy”>
        <activity LCID=”1033″>Reviewing program documents</activity>
        <activity LCID=”1044″>Reviewing program documents</activity>

    </customState>
    <customState ID=”4″ availability=”do-not-disturb”>
        <activity LCID=”1033″>Executive Briefing with Customer</activity>
        <activity LCID=”1044″>Executive Briefing with Customer</activity>

    </customState>
</customStates>

and here is the syntax of the reg file

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Communicator]
@=””
CustomStateURL”=file:///C:/Users/toml/Documents/presence.xml

image_4 

 

A program has been written to automate this process

Setting the Pre-Req’s on Vista and MOC R2

Amending the registry:

1) Start –> RegEdit.exe

2) Navigate (by double clicking) to the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Communicator

3) Change the EnableSIPHighSecurityMode key name to be 0

4) Right click EnableSIPHighSecurityMode –> Modify –> change it to 0 –> OK

It should look like this:

image

5) Close the registry editor.

Go here to download the tool: http://www.confusedamused.com/notebook/communicator-2007-custom-presence-tool/