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
- Sysinternals Suite
- Pstools
- Psexec.exe needs to be in your system environment path
- HASS running on a Windows Machine
Steps
- Download both of the linked files and place them in C:\pstools on the PC you are running HASS on
- 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