Shutdown a Windows system by openHAB

1,703 views
Skip to first unread message

robert...@gmail.com

unread,
Jun 24, 2014, 3:13:07 AM6/24/14
to ope...@googlegroups.com
Hello!

First of all, I am totally new at openHAB ;-)

My currently issue is following:

I want to switch on and off my HTPC (MediaPortal) via a HomeMatic wireless outlet (after a defined timespan).

My intention is to shutdown Windows first before I turn off the outlet.

Therefore my question is if there is any oportunity to shutdown a Windows system remotely?
Maybe by sending a command line command (shutdown-command), or is there a openHAB binding to control a Windows PC?

Kind regards,
Robert

Luke B

unread,
Jun 27, 2014, 7:36:33 PM6/27/14
to ope...@googlegroups.com, robert...@gmail.com
From another windows machine it's possible, just use:
shutdown /[r|s] /m \\ComputerName /force

where:
 /r is restart
 /s is shutdown 
 /m is the computer name
 /force optional forces shutdown even is users are logged on.

I believe this is over WMI so if there's any firewalls in the way you'll need to allow WMI traffic.

From Linux I believe you need to install the Samba package to get the 'net' command.
Then you can do net rpc shutdown -S ComputerName

Ben Jones

unread,
Jun 27, 2014, 10:13:48 PM6/27/14
to ope...@googlegroups.com, robert...@gmail.com
I run openHAB on an Ubuntu server and have the following script for shutting down PCs;

#!/bin/sh
# Shutdown script

ipaddress=$1
user=$2
password=$3

net rpc shutdown --comment "Shutdown request from openHAB..." --force -I $ipaddress -U $user%$password

I call this from openHAB via the EXEC binding;

Switch  NetworkPC   "PC"   { nh="192.168.1.25", wol="192.168.1.0#FF:FF:FF:FF:FF:FF", exec=">[OFF:/bin/sh@@-c@@/home/openhab/shutdown_pc 192.168.1.25 user password]" }

So this item has 3 bindings, 'nh' to monitor the state, i.e. determine if the PC is on/off. Then 'wol' which lets me turn the PC on via openHAB, OFF commands do nothing for 'wol'. And finally 'exec' which runs my script above and sends a shutdown RPC. 

So using this item I can monitor the PC state and boot it up as well as shut it down. 

robert...@gmail.com

unread,
Jun 28, 2014, 11:45:35 AM6/28/14
to ope...@googlegroups.com, robert...@gmail.com
Thank you, that's excactly what I am looking for!
Reply all
Reply to author
Forward
0 new messages