Hi Guys,
I thought I’d share with you my trivial solution to shutting down windows computers with a docker image of HA.
Previously I used net rpc, but this is not part of standard H-A docker at the moment, so here is how I do it now:
Step 1:
create a shell_command to create a file with name of PC.eg:
shell_shutdown_htpc: /bin/bash -c ‘echo shutdown >> /config/shutdown/hptc’
Step 2:
create a batch file on the PC to query the location of the file created in Step 1 and shutdown if it contains correct word inside:
@echo off
SET MYFILE="\x.x.x.x\appdata\home-assistant\config\shutdown%ComputerName%"
:START
findstr /m “shutdown” %MYFILE%
if %errorlevel%==0 (
IF EXIST %MYFILE% DEL /F %MYFILE%
timeout /t 10 /nobreak > NUL
%windir%\System32\rundll32.exe powrprof.dll,SetSuspendState
) else (
timeout /t 10 /nobreak > NUL
GOTO START
)
Step 3
Schedule the service to run the batch at start-up. Personally I use nssm.exe (google it), and run as user (as it won’t be able to delete the file if run as system account). I chose to do it this way so that i can shut down machine even if it is not logged in.
Step 4
- platform: wake_on_lan
name: htpc
mac_address: xx:xx:xx:xx:x:xx
host: 192.168.x.xxx
turn_off:
service: shell_command.shell_shutdown_htpc
Hope this helps someone out.
Nik