Removed API monitoring and updated ReadMe

pull/22/head
EBOOZ 4 years ago
parent 1bac638146
commit bbcda22f77

@ -26,9 +26,6 @@ Param($SetStatus)
# Import Settings PowerShell script # Import Settings PowerShell script
. ($PSScriptRoot + "\Settings.ps1") . ($PSScriptRoot + "\Settings.ps1")
################################################################
# Don't edit the code below, unless you know what you're doing #
################################################################
$headers = @{"Authorization"="Bearer $HAToken";} $headers = @{"Authorization"="Bearer $HAToken";}
$Enable = 1 $Enable = 1
@ -45,54 +42,15 @@ If($null -ne $SetStatus){
$params = $params | ConvertTo-Json $params = $params | ConvertTo-Json
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityStatus" -Method POST -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($params)) -ContentType "application/json" Invoke-RestMethod -Uri "$HAUrl/api/states/$entityStatus" -Method POST -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($params)) -ContentType "application/json"
break break
} }
# Create function that will be used to set the status of the Windows Service # Clear variables
Function publishOnlineState ()
{
$params = @{
"state"="updating";
"attributes"= @{
"friendly_name"="$entityHeartbeatName";
"icon"="$iconMonitoring";
"device_class"="connectivity";
}
}
$params = $params | ConvertTo-Json
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityHeartbeat" -Method POST -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($params)) -ContentType "application/json"
$params = @{
"state"="on";
"attributes"= @{
"friendly_name"="$entityHeartbeatName";
"icon"="$iconMonitoring";
"device_class"="connectivity";
}
}
$params = $params | ConvertTo-Json
Invoke-RestMethod -Uri "$HAUrl/api/states/$entityHeartbeat" -Method POST -Headers $headers -Body ([System.Text.Encoding]::UTF8.GetBytes($params)) -ContentType "application/json"
}
# Start the stopwatch that will be monitoring the status of the Windows Service
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
# Set the Windows Service heartbeat sensor at startup
publishOnlineState
$CurrentStatus = "" $CurrentStatus = ""
$CurrentActivity = "" $CurrentActivity = ""
# Start monitoring the Teams logfile when no parameter is used to run the script # Start monitoring the Teams logfile when no parameter is used to run the script
DO { DO {
# Set the Windows Service heartbeat sensor every 5 minutes and restart the stopwatch
If ([int]$stopwatch.Elapsed.Minutes -ge 4){
$stopwatch.Restart()
publishOnlineState
}
# Get Teams Logfile and last icon overlay status # Get Teams Logfile and last icon overlay status
$TeamsStatus = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 500 | Select-String -Pattern ` $TeamsStatus = Get-Content -Path "C:\Users\$UserName\AppData\Roaming\Microsoft\Teams\logs.txt" -Tail 500 | Select-String -Pattern `
'Setting the taskbar overlay icon -',` 'Setting the taskbar overlay icon -',`

@ -3,10 +3,9 @@ We're working a lot at our home office these days. Several people already found
Microsoft provides the status of your account that is used in Teams via the Graph API. To access the Graph API, your organization needs to grant consent for the organization so everybody can read their Teams status. Since my organization didn't want to grant consent, I needed to find a workaround, which I found in monitoring the Teams client logfile for certain changes. Microsoft provides the status of your account that is used in Teams via the Graph API. To access the Graph API, your organization needs to grant consent for the organization so everybody can read their Teams status. Since my organization didn't want to grant consent, I needed to find a workaround, which I found in monitoring the Teams client logfile for certain changes.
This script makes use of three sensors that are created in Home Assistant up front: This script makes use of two sensors that are created in Home Assistant up front:
* sensor.teams_status * sensor.teams_status
* sensor.teams_activity * sensor.teams_activity
* binary_sensor.teams_monitoring
sensor.teams_status displays that availability status of your Teams client based on the icon overlay in the taskbar on Windows. sensor.teams_activity shows if you are in a call or not based on the App updates deamon, which is paused as soon as you join a call. sensor.teams_status displays that availability status of your Teams client based on the icon overlay in the taskbar on Windows. sensor.teams_activity shows if you are in a call or not based on the App updates deamon, which is paused as soon as you join a call.
@ -23,9 +22,6 @@ input_text:
teams_activity: teams_activity:
name: Microsoft Teams activity name: Microsoft Teams activity
icon: mdi:phone-off icon: mdi:phone-off
teams_monitoring:
name: Microsoft Teams monitoring
icon: mdi:api
sensor: sensor:
- platform: template - platform: template
@ -40,35 +36,20 @@ sensor:
value_template: "{{states('input_text.teams_activity')}}" value_template: "{{states('input_text.teams_activity')}}"
unique_id: sensor.teams_activity unique_id: sensor.teams_activity
binary_sensor:
- platform: template
sensors:
teams_monitoring:
friendly_name: "Microsoft Teams monitoring"
device_class: connectivity
value_template: >-
{% set lastChange = as_timestamp(states.binary_sensor.teams_monitoring.last_changed) %}
{% set now = as_timestamp(now()) %}
{% set noUpdateForMins = (now - lastChange) / 60 %}
{% if noUpdateForMins > 5 %}
off
{% else %}
{{states('input_text.teams_monitoring')}}
{% endif %}
icon_template: "{{state_attr('input_text.teams_monitoring','icon')}}"
unique_id: binary_sensor.teams_monitoring
``` ```
* Generate a Long-lived access token ([see HA documentation](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token)) * Generate a Long-lived access token ([see HA documentation](https://developers.home-assistant.io/docs/auth_api/#long-lived-access-token))
* Copy and temporarily save the token somewhere you can find it later * Copy and temporarily save the token somewhere you can find it later
* Restart Home Assistant to have the new sensors added * Restart Home Assistant to have the new sensors added
* Download the files from this repository and save them to C:\Scripts * Download the files from this repository and save them to C:\Scripts
* Edit the Get-TeamsStatus.ps1 script and: * Edit the Settings.ps1 file and:
* Replace `<Insert token>` with the token you generated * Replace `<Insert token>` with the token you generated
* Replace `<UserName>` with the username that is logged in to Teams and you want to monitor * Replace `<UserName>` with the username that is logged in to Teams and you want to monitor
* Replace `<HA URL>` with the URL to your Home Assistant server * Replace `<HA URL>` with the URL to your Home Assistant server
* Adjust the language settings to your preferences
* Start a elevated PowerShell prompt, browse to C:\Scripts and run the following command: * Start a elevated PowerShell prompt, browse to C:\Scripts and run the following command:
```powershell ```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Unblock-File .\Settings.ps1
Unblock-File .\Get-TeamsStatus.ps1 Unblock-File .\Get-TeamsStatus.ps1
Start-Process -FilePath .\nssm.exe -ArgumentList 'install "Microsoft Teams Status Monitor" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { . C:\Scripts\Get-TeamsStatus.ps1 }"" ' -NoNewWindow -Wait Start-Process -FilePath .\nssm.exe -ArgumentList 'install "Microsoft Teams Status Monitor" "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { . C:\Scripts\Get-TeamsStatus.ps1 }"" ' -NoNewWindow -Wait
Start-Service -Name "Microsoft Teams Status Monitor" Start-Service -Name "Microsoft Teams Status Monitor"

Loading…
Cancel
Save