Windows Hibernate/sleep via Openhab

Hey there =)

I am trying to get my windows pc to sleep via Openhab. I am using a script pcshutdown.sh

#!/bin/sh
 .# Shutdown script
 
ipaddress=192.168.178.57
user=XXX
password=XXX

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

Shutting down the computer works just fine, however I’d like to put it to sleep. Replacing the

shutdown

with

shutdown /h

just shuts the pc down and doesn’ care about the /h

or

shutdown -h

gives me the error

./pcshutdown2.sh: 2: ./pcshutdown2.sh: .#: not found
Usage:
net rpc shutdown
    Shut down a remote RPC server

Another aproach would be to run nircmd on windows and send a request (with SSH?) to the windows server to start the exe with an argument that send the pc to sleep.
However I’d rather use the first way since this is almost completed. Do you have an idea on how to use the net rpc so it will send the pc to sleep?

Hi Felix,
Did you find a solution to your problem? I tried your script on my Windows Home Server, but I get an error permission denied. Do you know how to fix this?

Hey Henrik,

unfortunately I didnt find a solution yet… I want to look into the problem again in the near future. However I dont have the time and motivation to deal with this ^^

Got more details? When are you running into the issue? While using ssh on your system?

Try chmod 777 for the script (if not done yet). This command gives the permission to run the script for all available users

are you trying to get your pc to hibernate or to shut down?

Hi Felix, thank you for your reply. I am trying to shutdown (power off) my Windows server. I will try the chmod777. I think the access denied comes from the Windows server. If I try the shutdown from Windows I get the same access denied, but if I net use to the server I can shut it down.

Can you clarify what you mean by that? What kind of error messages do you get by which method?

I use withing for this. It connects your computer via mqtt to openHAB, no scripts required.

I’m on my phone at the moment, but a quick forum Search will soon get you an example of two I’m sure of item setups.

Hi Felix, sorry for my late reply. I had to reinstall OpenHAB. It started to ack strange. I can shutdown the Windows computer now, but can’t start it (wake on lan) if the power to the PC has been off. If I start the computer by the button and shut it down. I can wake it as long the power hasn’t been switched off. I use the example from https://www.openhab.org/addons/bindings/wol1/

Hey Henrik,

althought this has nothing to do with the topic of shutting down this probably has to do with your settings in the BIOS or in Windows. For the BIOS settings check google. For windows you have to look into the network card settings in the device manager (right click on the windows start menu button).

If you have further questions you should be looking into another forum since this isn’t an OpenHAB problem.

Felix

Hey Felix, thank you for your info. All the settings has been made and it works as long as the power stays on. The problem is that a PC even turned off uses power. That is the reason I turn the power via an Sonoff. I have chosen another solution for wake / shutdown. I will instead use an Wemos D1 with a relay to short the power button for 1 second. This way is almost failproof.
/Henrik

Hey there =)
today I found the solution on how to do it. I created an article: Put your Windows PC to Sleep or execute anything else with OpenHAB

Have a good day!