In the past couple of weeks, Microsoft has finally made available features they presented over 6 months ago; namely the ability to set your work location.
First this was available in Outlook on the web (formerly known as Outlook Web Access, or OWA), and then last week in Microsoft Teams.
This is a very handy solution in the hybrid world of work, and many people are now well established in a rhythm for when they are in the office vs. when they are working from home (or elsewhere).
Personally, I only work from the office on Wednesday – so it made it quite easy for me to schedule:
The Challenge
But… what if I change the day I come in? Or what if I decide to come in an extra day one week? Or two days?
How will the system handle that???
I mean, I could simply remember to set my location at the time in either Outlook on the web or the Microsoft Teams desktop client to show where I am that day… but what if I forget?
Or IÂ could wait for Microsoft Places to one day be released and help with this world-ending issue.
But what if my colleagues, thinking they’re going to have an online meeting with me, aren’t aware that I’m sitting a few desks from them, and we could in fact be meeting in person?
Can you imagine??? Surely this would cause a tear in the fabric of space and time!!!
Thankfully, if you want to go full nerd (as I like to), then you can automate this – especially if you use Home Assistant.
Even if you don’t, you can still achieve the same luxurious automation but with a different trigger method.
Let’s have a look, shall we?
(Also, while you’re reading on… have a think about how much time I’ll save by having this automation work vs. how much time it took me to figure this out, build it, test it, and write this blog.)
The Solution
Scouring through Microsoft Graph documentation I couldn’t see anywhere to set working location, and realistically the average user wouldn’t be able to do anything using Graph without IT admin involvement.
Moving on, I inspected the web traffic when setting the working location in Outlook on the web and found that I would most likely need to perform the update using PowerShell – another dead-end.
Doing the same for Microsoft Teams in a browser, I noticed that changing the working location was calling a web-based URL that I’d seen before…
And then it hit me! I’d previously used that URL to set my Microsoft Teams status message to show what I was playing on Spotify, or to have Alexa change my presence to Do Not Disturb. (Both crucial functions, make sure you check them out!)
So, using the same approach I should be able to set my work location as the endpoint called is https://emea.presence.teams.microsoft.com/v1/me/workLocation.
(NOTE: my account is in EMEA, so you may need to change the start of the URL to something else – the previous blog posts explain this.)
I also discovered that payload being sent when I changed my work location took the form of: {location: 1, expirationTime: “Mon, 05 Jun 2023 13:59:59 GMT”}
Working through the different options, I’ve mapped out that:
0 = Clear
1 = Office
2 = Remote
Now that we’ve worked what to send and how to send it, let’s head into the kitchen!
Changing my working location through a Power Automate workflow
Here’s how the workflow works:
- Trigger the workflow with a payload of my location
- Add 12 hours to the current time of the workflow run (to give sufficient time to last until the end of the day, on the chance I may come in early or leave late)
- Convert the time into full date/time pattern as that’s what is required for the request
(At this point, I know that the previous two steps could be achieved in a single compose but I’m not exactly paying by the action here, so am happy to “wear the cost” of extra actions in exchange for visual simplicity.) - Initialise the variable for the location, as this is set within the Switch
- The Switch sets the location to a numeric value that corresponds with “Office” or “Remote” in code, based on where Home Assistant tells it to
- Send the HTTP request to the Microsoft Teams presence endpoint by cheating and using a SharePoint HTTP request action with our location variable and dynamically generated end time
Expanding out the trigger, I have included a JSON Schema for the payload:
Expanding out the time calculations:
While I’m in GMT+10, I noticed in my research that it uses GMT time in the payload – so I kept it that way.
Initialising the variable and putting in a switch condition for the value:
And the final step, hijacking the “Send a HTTP request to SharePoint” action to send the request to the Microsoft Teams presence endpoint:
It’s all very well and good to have figured this out, but how will I trigger it automatically and send the right location?
I thought initially of a scheduled workflow instead that would somehow retrieve the location of my Windows device from Microsoft Graph – but again, I didn’t want to abuse my Global Admin rights to get that data.
Instead, I realised that I already had location states set in Home Assistant based on map zones – so when I’m within 100m of my office the state of the Loryan Actual Location entity I’ve configured is set to “Work”.
(I use this entity as an amalgam of both GPS-based location tracking, as well as room-based tracking.)
Triggering this from Home Assistant
In the configuration.yaml file I configured a RESTful command to call my Power Automate workflow trigger and send the payload with my location:
If I wanted to manually call this service, here’s what it would look like:
So, over in my automation I configure it to be triggered based on the entity location being set to “Work”:
Summary
And there you have it.
The moment I walk within range of the office, even on a day when I’m scheduled to be working from home – these two automations will set my work location to show that I’m in the office, just in case nobody else in our single office space was aware of my presence.
So worthwhile, so valuable, so much time saving and experience improving!
Also published on Medium.
Discover more from Loryan Strant, Microsoft 365 MVP
Subscribe to get the latest posts sent to your email.
Since Microsoft added this location functionality I’ve been thinking about doing something like this, thanks for saving me some of the leg work 🙂
For me though, what I’d like to do is check the machine’s IP and, if it’s in an office range, set to ‘Office’, otherwise set to ‘Remote’.
For testing and ease of initial deployment I was trying to get this as a scheduled task on machine unlock (would pick up people who work from the office for only part of the day etc.) or even every hour or so and send the appropriate request. Unfortunately though this seems to run into an 401 authorization error, even if I try to use a valid certificate – fairly predictable I guess, given I’m probably doing something wrong (very likely!) and/or the chance that Microsoft may just block non-365 applications from updating this.
Will look at expanding your Power Automate workflow to do something similar. Thanks again.
I was originally going to do this based on certain sign-on events in AAD, and if the user was on a computer (vs a phone), and based on their IP address or WiFi network, but thought that might be seen as a bit too invasive. :-/
yea its a shame they cant lean on IP addresses etc as that is how we did it in Skype for business and it worked a treat
Thanks for this! I found it helpful. 🙂
Ha! I had the same idea! That what it means to be a “lazy admin”: work smart, not hard…. I took the Power Automate flow a little further and added a condition to only change working location if Out of Office is not enabled. Thanks for this!
I adapted this solution to recognise Wifi name via PowerAutomate and update Teams work location. It worked for a while, but now I keep getting a non-authorised error, which I assume is because the URL (https://emea.presence.teams.microsoft.com/v1/me/workLocation.) is not working anymore. Any other ideas to make it work?
I believe the API doesn’t work any more as it’s not working for me either. At some point I’ll see if I can get it working another way.
Try https://presence.teams.microsoft.com which works for me.
Skype for Business had this built-in. It used the network you were connected to to decide which location to show.
Yeah, if defined. And it didn’t handle “home”, but otherwise you’re right.
It’s a shame we’re still waiting for functionality we had previously.
Hi Loryan, very good content. I’m trying to do the same out of power automate, tried a lot of different strategies to get a valid token but any attempt fails with a 401 anauthorized. Any Idea about how I should configure che Azure app reg and the related authentication scope I’d use? please have a look to my question on stackoverflow. https://stackoverflow.com/questions/78760595/change-ms-teams-working-location-programmatically
Thanks a lot.