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
}