Hibernate and Wake up your Windows PC

Hibernate a remote Windows PC from HASS or automate! This can be modified to work with Linux but the offcmd in step 3 is slightly different. If you are running HASS on something other than Windows you can still get the general idea from the code below.

Requirements

  1. Sysinternals Suite
  2. Pstools
  3. Psexec.exe needs to be in your system environment path
  4. HASS running on a Windows Machine

Steps

  1. Download both of the linked files and place them in C:\pstools on the PC you are running HASS on
  2. Add a new switch for the PC you want to hibernate
- platform: wake_on_lan
  mac_address: "00:00:00:00:00:00"
  name: "Main PC"
  host: "192.168.x.x"

3 . Add a switch to hibernate the PC you specified above

- platform: command_switch
  switches:
    Main_PC_Power:
      offcmd: psexec -s -i \\PCNAME shutdown.exe /h
      initial: 'on'

4 . Add a template switch that copies the state of your WOL switch but when it’s turned off toggles your shutdown switch.

- platform: template
  switches:
    copy:
      value_template: '{{ states.switch.main_pc.state }}'
      turn_on:
        service: switch.turn_on
        entity_id: switch.main_pc
      turn_off:
        service: switch.turn_off
        entity_id: switch.main_pc_power

By doing this HASS frontend will show if the PC is hibernating or not. Whenever it’s hibernating the switch will show off, just slide to the right to wake the PC up, or vice versa. You can also now use these switches to automate your PC if you’d like it to hibernate when you are not home for example.

###  Hibernate Main PC When Not Home  ###
- alias: Hibernating PC
  trigger:
    platform: state
    entity_id: device_tracker.NAME
    from: 'home'
    to: 'not_home'
  action:
    service: switch.turn_off
    entity_id: switch.main_pc_power

###  Wake Up Main PC When Home  ###
- alias: Waking PC
  trigger:
    platform: state
    entity_id: device_tracker.NAME
    from: 'not_home'
    to: 'home'
  action:
    service: switch.turn_on
    entity_id: switch.main_pc
4 Likes

is this compatible with windows 10

Yes, I have it running on Windows 10.

what i should have typed was can this be run/triggered remotely?
i have HASS running on a Pi3 and want to hibernate my main PC when i leave the house.

I’m not sure I follow, if you’re asking if this can be run with automation, you can see my code for how I am automate hibernating my PC when I am not home via the status of my device_tracker. I use OwnTracks so I have it setup to Hibernate when I am out of the neighborhood and to wake up when I pull into the neighborhood.

If you are asking for the specific command you need to send from your Pi3 to your Windows 10 machine, I don’t know the exact command off the top of my head.

You could try
On your pi3 sudo apt-get install samba-common

And for your switch

- platform: command_switch
  switches:
    Main_PC_Power:
      offcmd: net rpc shutdown -f IPADDRESS -U USERNAME%PASSWORD
      initial: 'on'

You may have to verify if that offcmd is right, but you get the general idea.

This probably won’t work on:
Linux based HASS server waking up Windows7 & Windows10 clients…?

It will, the command to hibernate is just different. You essentially are sending the same command as you would send to hibernate your Windows box from a Linux box. You can google your distro to see what command you need.

Here is a general example: http://www.howtogeek.com/109655/how-to-remotely-shut-down-or-restart-windows-pcs/

1 Like

A neat way of doing this from Linux to Windows 10 is using OpenSSH in Windows The ON being provided by regular Wake-on-Lan.

- platform: command_line
  switches:
    jon_hibernate:
      command_on: "ssh jon@hostpc1 shutdown.exe /h"
    doe_hibernate:
      command_on: "ssh doe@hostpc2 shutdown.exe /h"
- platform: template
  switches:
    pc_doe:
      value_template: '{{ states.switch.doe_pc.state }}'
      turn_on:
        service: switch.turn_on
        entity_id: switch.doe_pc
      turn_off:
        service: switch.turn_on
        entity_id: switch.doe_hibernate
- platform: template
  switches:
    pc_jon:
      value_template: '{{ states.switch.jon_pc.state }}'
      turn_on:
        service: switch.turn_on
        entity_id: switch.jon_pc
      turn_off:
        service: switch.turn_on
        entity_id: switch.jon_hibernate
2 Likes