Shutdown and Wake up your Windows PC from a Raspberry Pi

When using the command line switch it is required to also have the command_on set up.

I thought the same thing, however, one of the examples on the command line switch page only has a “command_off” option.

I also tried adding a command on just to test which didn’t solve it. Still get the same error notice.

Yes you are right. i did only look at the top of the page and saw Required and didn’t look further.
I thought it could be an easy fix.

But maybe it is still easy to fix. Can you try changing Desktop into desktop (no capital)?

1 Like

Tried that too. No dice.

Sorry i’m out of idea’s for right now.
But in my config it definitely needs to be an non capital name, otherwise it won’t pass the
hass --script check_config command.

Well Ive been making changes trying to get this switch to work and its working now. It was some combonation of the lowercase d and adding the on command and re-typing the whole thing that did it. Thanks Mister-Espria!!

Is there any way to maybe edit this command to hibernate a windows 10 PC instead of shutting it down?

I have been trying myself but no luck so far, also I do have hibernate activated on the intended PC and I have got the original command to work as intended.

I am doing this with an app called SleepOnLan that I put on the Windows PC (originally I said “install” but there’s nothing really to install, it’s just an executable unto itself, no installer), that lets me shut it down with URLs:

http://www.ireksoftware.com/SleepOnLan/

(I did use Task Scheduler on the Windows PC to make the thing launch on boot instead of on user login.)

Then the format for the switch is:

- platform: wake_on_lan
  name: PC
  mac_address: !secret htpc_mac
  host: !secret htpc_ip
  order: 1
  turn_off:
    service: shell_command.sleep_htpc_pc

…and the shell_command entry is:

sleep_htpc_pc: '/usr/bin/curl -X GET "http://<IP address>:7760/suspend"'

It works brilliantly, and you get sleep and hibernate and shutdown and pretty much everything else. So between this and my Amazon Echo Dots I don’t even have to be home to turn my PCs on and off as needed. :slight_smile:

3 Likes

Found a little workaround.

Instead of shutting my pc down, I hibernate it.
Using this https://github.com/SR-G/sleep-on-lan

I added the switches to my HA config, when I try to switch off the PC Iget the following error in my log.

17-03-20 19:46:22 ERROR (Thread-3) [homeassistant.components.switch.command_line] Command failed: net rpc shutdown -I 192.168.0.27 -U LeeG%Namdoog71

I typed the command in the command line

net rpc shutdown -f -I 192.##.##.## -U user%password

and I got the following message

pipe winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND

Ive set everything up as per the instructions above, not quite sure what these messages mean, or how to solve them.

I would edit your post to remove your password…

When you typed it in to the command line did you add your specific information? Your actual IP address and user name and password?

Also, be aware the user name you sign in under (display at login) may not be your username that windows uses. Look at c:/users for the name that windows uses.

Very cool. Will try now

How to do it?

Start the Task Scheduler by running:
taskschd.msc /s
Use the Make basic task scheduler or what it is called in english. It will allow you to select programs you want to execute on startup and so on.

I receive this when I try to launch the command from other PC

ERR_INVALID_HTTP_RESPONSE

Did it work before you added it to Task Scheduler?

  1. Start SleepOnLan
  2. Open terminal on the machine you have HASS running on.
  3. Run this command: /usr/bin/curl -X GET "http://<IP address>:7760/suspend" but with the IP of the machine you are trying to suspend. Also be sure to check if the user that HASS is running under is able to run that curl command.

suspend was giving

pi@raspberrypi:~ $ /usr/bin/curl -X GET "http://192.168.1.12:7760/suspend"
Request accepted for execution: suspend

More info: http://www.ireksoftware.com/SleepOnLanpi@raspberrypi:~ $ 

but nothing on the NUC. I tried hibernate and is working. Why is working from the pi with the curl command, and not from a computer in the network with http …

Well now it works with hibernate, and also turning it on from it. So I am not digging why suspend is not working.

Upgrading the NUC ethernet drivers from some months ago to the latest march 2017 finally now wake-on-lan it works (I have this NUC since 2 years and never worked the wake on lan).

I linked it with Alexa: is cool now to say: " Alexa, turn on/off NUC", and it works!!!

Just having problem in Alexa recognizing NUC … I have to spell it N U C

I’ve followed your guide but when trying on homeassistant i have this error on configuration.yaml

Failed config
switch.command_line:
platform: command_line
switches: [source /home/homeassistant/.homeassistant/configuration.yaml:91]
PC: [source /home/homeassistant/.homeassistant/configuration.yaml:92]
offcmd: net rpc shutdown -I 192.168.0.30 -U user%password

Successful config (partial)
switch.command_line:ù

of course i put the right user and password. i’ve tryed it trought command line and it works but not in home assistant. where’s the problem?

Hello, I’ve also followed the guide, but I keep getting the following error:

2017-07-16 12:05:25 ERROR (MainThread) [homeassistant.config] Invalid config for [switch.command_line]: [PC] is an
invalid option for [switch.command_line]. Check: switch.command_line->switches->PC. (See ?, line ?). Please check the
docs at https://home-assistant.io/components/switch.command_line/

My config for the commandline switch looks like:

- platform: command_line
  switches:
      PC:
         command_off: 'net rpc shutdown -I 192.168.X.X -U [username]%'

I have no password on the NUC,

I’ve tried without the username and without the ‘%’ .
Nothing worked so far.

I’ve also tried a blank ‘command_on’ as I do not want the ‘on’ command to do anything.

Does anyone have an idea where I’m going wrong?

Thank!