Provide cloudless Windows10 Notifications with the use of Windows PowerShell. Inspired by an article “Netzwerkpost” published in c’t 8/2020 p. 158. https://ct.de
First, we need Windows PowerShell with the module „BurntToast” installed: https://github.com/Windos/BurntToast. Verification: The following PowerShell command produces a two-line Notification:
Toast -Text "Hallo", "Do you read me?"
Next, we need to setup a UDP connection between Home Assistant and the Windows 10 engine:
A simple ps1-script listens on UDP port 514 for incoming notifications:
# original file published by c't: notify.ps1
# Stellen Sie hier den Port ein, auf dem das Skript lauschen soll
param( $address="any", $port=514 )
# Speicherort des Powershell-Skripts herausfinden
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
# UDP-Socket öffnen
$endpoint = new-object System.Net.IPEndPoint([IPAddress]::$address, $port)
$udpclient = new-object System.Net.Sockets.UdpClient $port
# Begruessung ausgeben
Write-Host -ForegroundColor Cyan "*** UDP Notification-Receiver, listens on port $($port) ***"
# Eingehende UDP-Pakete verarbeiten
while( $true )
{
if( $udpclient.Available )
{ # UDP-Paket auswerten und Benachrichtigung anzeigen
$udpmessage = $([Text.Encoding]::UTF8.GetString($udpclient.Receive([ref]$endpoint)))
# Modification: Define first 25 character of UDP string as Title, and the rest as Message
$title = $udpmessage.Substring(0,25)
$message = $udpmessage.Substring(25)
Toast -AppLogo $ScriptDir\ha.png -Silent -Text $title , $message
}
# Abfrageschleife verzoegern, um CPU-Auslastung auf ein Minimum zu reduzieren
Start-Sleep -s 2
}
Specify the logo and IP to your needs. For continuous use, call this this script in Autostart.
On the Home Assistant side: Provide in configuration.yaml a new Notification definition, using pipes:
notify:
- name: win10desktop
platform: command_line
command: "cat | nc -u 192.168.178.19 514"
An action call in automation.yaml will generate a notification:
action:
- service: notify.win10desktop
data:
message: "Warnung: Wasser im Keller Dringend nachschauen"
The result: