FloKra 958c653cf9 onShutdown.ps1: added check if there is a Windows Update reboot required. As in this case the update will be installed on shutdown, the Tasmota-Powerdown command is then omitted. Requires PSWindowsUpdate to be installed. | 2 years ago | |
---|---|---|
.. | ||
README.md | 2 years ago | |
onShutdown.ps1 | 2 years ago |
PowerShell script for Windows 10 to send MQTT messages on Shutdown and Restart.
Intended to switch off a Tasmota plug, delayed, after shutdown, but NOT on restart.
This script checks if there is a Event 1074 (source: User32) in the System Event Log, that is less than 15 seconds old. If so, it checks the content of this event, which contains the info if we are about to "power off" or "restart".
The script must be set as shutdown script via Windows Group Policy (local GPO).
V2 now checks if there is a Windows Update reboot required. As in this case the update will be installed on shutdown, the Tasmota-Powerdown command is then omitted. Requires PSWindowsUpdate to be installed.
Install-Module -Name PSWindowsUpdate
Starting it via Task Scheduler on Event 1074 unfortunately does not work, as the script is getting killed before it actually has done anything most times. Via Group Policy, the shutdown will be delayed until the script has finished its work.
In order to implement the "delayedOff" function, a rule has to be added to the Tasmota device.
Add it via console on Tasmota´s Web Interface:
rule1 on event#delayedOff do RuleTimer1 25 endon on rules#Timer=1 do power1 0 endon
Enable the rule:
rule1 1
In this example, Relais 1 is switched off 25 seconds after the event "delayedOff" was triggered.
Now the delayedOff-function can be triggered via MQTT:
topic: cmnd/[TasmotaTopic]/event
payload: delayedOff