Help Required - Turning On/Off a Windows PC/Server

  • Platform information:

    • Hardware: Raspberry Pi 2 Model B Rev 1.1
    • OS: Raspbian GNU/Linux 9
    • openHAB version: 2.2

I have created an Item in my items file

Switch   GF_LivingDining_Server           "Plex Server"                            <poweroutlet>           (GF_LivingDining, gnetwork)     { wol="" }

and an associated rule

rule "Switch the Plex Server off via Exec"
	Item GF_LivingDining_Server received update OFF
then {
	logInfo("switchOffPlexServer.rules", "Plex Server is being switched off")
	val String FeedbackScript = executeCommandLine('net rpc shutdown -f -t 0 -U USERNAME%PASSWORD -I', 10000)
	logInfo("switchOffPlexServer.rules", FeedbackScript)

My issue is this:

If the PC is initially OFF and I toggle the state of the Switch ‘GF_LivingDining_Server’ to ON then I can see in the Log file:

[INFO ] [nhab.binding.wol.internal.WolBinding] - Wake-on-LAN packet sent [, macaddress=xxxxxxxxxxxx]

and the PC successfully turns on.

If the PC is turned on and I toggle the state from ON to OFF in the UI then the PC successfully shuts down.

ALL good so far :grinning: and ALL working as expected . :grinning:

However the WOL does not work again once the PC has been turned off via the rule (it is being fired and I can see it in the OpenHab logs). If the PC is turned off by logging onto the PC and choosing ‘shutdown’ manually then the WOL works as expected.

Does anyone have any idea on why the rule to shutdown the PC is then stopping the WOL command? By the way the PC is running Windows 10.

Many thanks in advance for any pointers!

It looks right but two things to possibly try
a) Try a delay on the shutdown of, say, 30 seconds to allow Plex to exit cleanly.
b) Move the -I before the -U.

Just thought, isn’t the first item after the command the repeat interval? So are you repeatedly sending the shutdown command (admittedly after a couple of hours)? Perhaps try …,0,1000)?
None of this may make any difference!


Thanks for the ideas - Unfortunately it’s made no difference.

Just to confirm though, I had the second parameter as 1000 to wait to get the ‘Feedback script’ - is this not right?

==> /var/log/openhab2/openhab.log <==
2018-06-10 16:36:50.176 [INFO ] [del.script.switchOffPlexServer.rules] - Plex Server is being switched off
2018-06-10 16:36:50.793 [INFO ] [del.script.switchOffPlexServer.rules] - 
Shutdown of remote machine succeeded

I’m beginning to think that this is a Windows issue with the remote shutdown as it all works perfectly if shutdown locally!

The exec binding has the following format according to the docs.
Thing exec:command:uniquename [command="/command/to/execute here", interval=15, timeout=5, autorun=false]
so I think it needs to be
val String FeedbackScript = executeCommandLine('net rpc shutdown -f -t 0 -U USERNAME%PASSWORD -I,'0,1000)
I’m not sure whether it makes a difference to what’s happening for you…