How I display my Team status in Homeassistant

Homeassistant Sep 27, 2022

Homeoffice is wonderful, but sometimes when you are on a call in Teams my wife comes in and tell me some private stuff. Instead of try to stop the discussion with heavy gestures to tell her that she be quiet, I want to have a elegant solution.

I want to give you a nice Guide, on how to gather the Teams status and forward it into a pixelit display.

Displaying your Teams status (Busy, Available, Do Not Disturb, Away, etc) within Home Assistant is pretty awesome. It allows you to build automations that reference your status to do certain things.

For example, if your status is Busy, you could change the color of an RGB bulb to red so your kids or family members know you are on a call or in a meeting. If you answer a call, your music stops.

In my case I want to control al LED Display (based on PixelIt) that will display a Message “On Air”.

Little Teaser… this will be the result:

Here are several ways you could view your Microsoft Teams presence status inside Home Assistant I prefer to use the simplest one, the PowerShell way

Reminder: You’ll need to be a local administrator of your computer to configure this option.

For this option, we are using a Powershell script created by EBOOZ called TeamsStatus. This script monitors logfile from your Teams application located at %appdata%\Microsoft\Teams\logs.txt. I tried this out for a while and I think that's very stable and getting the states and calling state very precisely.

Part of this setup involves creating a few sensors in your configuration.yamlfile and copying a Powershell file to your computer.

The sensors that get created are:

  • sensor.teams_status
  • sensor.teams_activity

The sensor.teams_status will display the availability (presense) of the Teams desktop application from your taskbar.

The sensor.teams_activity will display if you are in a call or not.

Step 1: Generate Long-Lived Access Token in Home Assistant

First, you’ll need to generate a long-lived access token from Homeassistant. WIth this it is possible to send the “Telemetry” to homeassistant. To do this, click your profile picture in Home Assistant:

Then, scroll to the bottom until you see the Long Lived Access Tokens section.

Click Create Token and name it TeamsStatus. (Screen below ist in unfortunately in german)

Copy the generated token to your clipboard and save it somewhere temporarily. This code will not displayed anymore

Step 2: Create Sensors in configuration.yaml

Next, edit your configuration.yaml file from your homeassistant and add the following sensorsand input_text.input_text:

After this restart Home Assistant.

Step 3: Create Scripts folder for Powershell TeamsStatus script

Next do Navigate to this URL, and click the green Code button. Then Download Zip.

Please extract the content into the “C:\HomeassistantSkripts” Folder

After this, you must edit the file Settings.ps1 and add your Home Assistant token, your Windows username, and the URL of Home Assistant. Then save the file.

Tip: To get your local username, you can execute the command whoami in the shell

Step 4: Run Powershell script as Admin

Next, start an elevated Powershell ISE window.

First, change the directory to C:\Scripts

Then paste this:

Click “Yes to All” on the Execution Policy Change window.

Step 5: Add Entity to Home Assistant

Next, simply add the sensor.teams_status and sensor.teams_activity entities to an Entities card in Lovelace.

If all goes well, it should look like this and report the correct status!

Start Powershell Script Automatically After Computer Reboots

So, now that we got everything working — the last step is to run this PowerShell script automatically after your computer restarts. Otherwise, you’ll get a status unknown , or it’ll retain the status it last detected.

There are a few ways to do this, but using Windows Task Scheduler is the easiest route. This way will not shown up the console window and does not disturb me in my daily work.

Let’s start to add these in the Task scheduler

  1. Search Windows for Task Scheduler
  2. Right-click Task Scheduler Library > Create Task
  3. Give it a name like “Start TeamsStatus”.
  4. Set to “Run whether user is logged in or not”
  5. Set to “Run with Highest privileges”
  6. Configure for Windows 10
  7. On the Triggers tab, set to At System Startup.
  8. Under Actions tab, choose Start a Program.
  9. Program/script: C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe
  10. Add arguments: C:\Scripts\Get-TeamsStatus.ps1

Now, the next time you reboot your computer, the script will start running automatically!

The only gotcha is that you also must have Teams running! If not, the script can’t find the log files it needs. If you have Teams running and it’s active in the taskbar, it updates the HA sensors quicker. However, if it’s just running in the background, it’ll still update, but not quite as quickly.

Create Teams Presence Automations

The last step is to create an automation that will turn display the Status on my PixelIt display when I am on a call.

To create these automation, just go to Configuration > Automations > Create New Automation.

Now under Trigger, I use a state trigger like the following:

After that, I use a call service activity and send a message to the mqtt like this:

As a payload, I send the following JSON content.

This will send the “Pixel Image” to the display like this:

Wrapping Up

This was another really fun project to dive into, so hopefully, you guys found it useful!

Understandably, not everyone will be able to use this (especially if their corporate laptops are locked down with Standard user rights), but for those of you who’ve installed Teams on their personal computers and VPN in — it works out great!

You can extend this automation to reduce the volume of your radio and so on. If the webcam or microphone is turned on, then turn on a light. You see, you are now very flexible to use this.