Microsoft Teams Status

That sounds good, I’ll propbly hold off until then to try it then.

Thanks
Simon

I am very interested in this also. You may want to spin off another conversation thread. Also interested in your code that updates HA.

1 Like

New thread here: RTC Call Monitor - Add active voice/video call status to Home Assistant

I’ve been using this for about a month and it works well, but I am getting an issue where my status is not going back to ‘Not in a call’ when I close out a call. I have to kill Teams and reopen it to get things synced again. Has anyone run into this?

“access denied”

RTC Call Monitor - Add active voice/video call status to HA - Share your Projects! - Home Assistant Community (home-assistant.io)

working now, thanks.

So I tried this with dcnoren suggestions on my own computer and it is working. Next i tried it on my work computer and no luck. The biggest problem seems to be Constrained Language mode, after I was able to bypass execution policy. I found that using powershell v2 will get around the constrained language mode, as it didn’t exist in v2. But other functions such as get-content -tail wont work as tail was implemented in v3. I didn’t go through all of the command not found exceptions but there seem to be a few.

Anyone get this working in a super restricted environment? No admin rights, can’t run exe, and constrained language mode…

I have a (mostly) working script that runs under AutoHotKey that can pull the status from the log file and send it to a HA webhook. This works without any elevated permissions and can be run by AHK portable (nothing to install).

ajobbins/AHK-Teams-Presence (github.com)

Key limitation is that I haven’t got it getting the status on initial script load (as it’s just tailing the log). Can work around by toggling the status initially, but welcome someone with better coding skills than I working out how to get the last status on initial load.

I am moving jobs and won’t be using Teams much longer but hopefully this is useful for those like me who can’t get access to the Graph API and who don’t have local admin permissions.

4 Likes

does any of the solutions here work on a mac?

1 Like

I’m now using a Mac and have moved to using the HA Companion app which can create sensors to show when your mic and camera in use. The only issue is that there is a big with M1 Macs where the camera is currently always showing as on, but the mic sensor works fine

1 Like

yes i immediately found out about the mac app. i have been using HA for 3 years and did not even know the mac app was launched for a whole year now. this is amazing! the possibilities are endless: i can raise my desk, set the mood lighting etc when i unlock my macbook

1 Like

This is awesome. I just hooked my LED “On a Call” sign (LED Matrix "On a Call" Message Sign) to my Teams activity sensor!

1 Like

I created an IoTLink Addon for MS Teams. It uses @Egglestron’s approach (Tail + RegEx). If anyone is interested you can find it here: GitHub - ledhed-jgh/IoTLink-Addons: Addons for IoTLink

I prefer IoTLink because my automation stuff lives in an isolated VLAN and can’t communicate directly with my PC. I was already using it to shutdown my PC, so it made sense to create the Addon and use what was already there rather than create Scheduled Tasks or PowerShell services.

1 Like

Thanks for doing this. Does this addon constantly poll or check the log file and therefore consume cpu cycles that would impact overall pc performance?
thanks

Its fairly efficient from the small amount of testing I’ve done. The code I used to watch the log file comes from a code snippet called Tail .NET. Essentially it checks the size of the log file every 1 second and if the filesize has changed it only reads the changed data (rather than loading the entire log file which can be quite large). I expect it to consume similar resource as the PowerShell based solutions (which also tail the log file).

Gotcha, thanks

maybe someone know what to do …
I`ve try to do it like EBOOZ wrote… instruction looks very easy but got error with last command in PowerShell

PS C:\Scripts> Start-Service -Name "Microsoft Teams Status Monitor"
Start-Service : Service 'Microsoft Teams Status Monitor (Microsoft Teams Status Monitor)' cannot be started due to the
following error: Cannot start service Microsoft Teams Status Monitor on computer '.'.
At line:1 char:1
+ Start-Service -Name "Microsoft Teams Status Monitor"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
   ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

PS C:\Scripts>

Great idea using the Teams log, that’s exactly what I was looking for. However I came with a different way of extracting the status from Teams, I’m looking for “Setting the taskbar overlay icon”. Here is the Powershell script I created, it works well. I find that querying the log every 5 seconds and grabbing the last 2000 lines is sufficient so far.

$token = 'mytoken'
$headers = @{"Authorization" = "Bearer $token"; }

while ($true) {
    $tl = Get-Content "$env:APPDATA\Microsoft\Teams\logs.txt" -tail 2000 | ? { $_ -like '*Setting the taskbar overlay icon*' }
    $lastline = $tl[$tl.Count - 1]
    $i = $lastline.IndexOf('Setting the taskbar overlay icon - ') + 35
    $CurrentState = $lastline.SubString($i).Trim()

    $params = @{
        "state"      = "$CurrentState";
        "attributes" = @{
            "friendly_name" = "Microsoft Teams";
            "icon"          = "mdi:microsoft-teams";
        }
    }
    
    Invoke-RestMethod -Uri 'https://homeassistant:8123/api/states/sensor.teams_status' -Method POST -Headers $headers -Body ($params | ConvertTo-Json) -ContentType "application/json" 
    Start-Sleep 5
}

4 Likes

Like your solution. :+1:

Got this working on my work machine.
For anyone wanting to automate this.

  1. Open “Task Scheduler
  2. Create Task
  3. Give it a “Name” and importantly tick “Run with highest privileges
  4. Triggers tab
    a. New
    b. Dropdown “Begin task” set to “On log on
  5. Action tab
    a. New
    b. “Start a Program
    c. Program/script: “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe”
    d. Add arguments -NonInteractive -WindowStyle Hidden -File "C:\path\to\the\script\on\your\machine\teams_meeting_presence.ps1"

Note: you might need to look for Powershell on your machine with Get-Command powershell.exe from a powershell session.

3 Likes