I thought I might share my attempt at remote Shutdown/Restart/Sleep/Hibernate of a windows machine.
I installed a windows program called Airytec Switch Off, I use to schedule a shutdown of my machine on a timer if I need it to run for an hour or two after I go to bed. it can also function as a web server and creates a little web page accessible over LAN and with port forwarding over the net (HTTP). you can also password protect the web page to stop mischevious goblins from playing pranks.
Here is the Setup:
Download and install Airytec Switch Off.
Setup a task to automatically start the program on login using Task Scheduler Guide
Right-click the tray icon and go to options ā remote ā edit web interface settings. This opens another window. click the remote tab and enable a web interface and set a port number. if you are using home assistant remotely (away from home you likely have SSL so you donāt need to forward the port from this program)
Click on View Web Interface you can now access this page on any machine over the local network to control your PC.
(you may want to set your firewall to allow this program access to the home network)
Ok now for the home assistant configuration:
input_select:
pcoptions:
name: PC Power Options
options:
- Restart
- Shutdown
- None
- Sleep
- Hibernate
initial: None
icon: mdi:desktop-tower
shell_command:
shutdown_z800: 'curl -k (url of links from step 4)'
restart_z800: 'curl -k (url of links from step 4)'
sleep_z800: 'curl -k (url of links from step 4)'
hibernate_z800: 'curl -k (url of links from step 4)'
automation:
- alias: z800_restart
trigger:
platform: state
entity_id: input_select.pcoptions
to: "Restart"
action:
- service: shell_command.restart_z800
- alias: z800_shutdown
trigger:
platform: state
entity_id: input_select.pcoptions
to: "Shutdown"
action:
- service: shell_command.shutdown_z800
- alias: z800_sleep
trigger:
platform: state
entity_id: input_select.pcoptions
to: "Sleep"
action:
- service: shell_command.sleep_z800
- alias: z800_hibernate
trigger:
platform: state
entity_id: input_select.pcoptions
to: "Hibernate"
action:
- service: shell_command.hibernate_z800
In my setup, I also get a notification on telegram via IFTTT when any of these actions are performed.
And there you have itā¦ super easy and very useful.
āIām sorry I wrote you such a long letter; I didnāt have time to write a short one.ā
Blaise Pascal
ye for sureā¦ tbh I only implemented the drop down a few days ago, because I kept on pressing the restart switch by accident when using my phone. #fatfingers
Wow, great idea. Thanks for sharing!
I was using the WOL comonent for some time now but didnāt had an option to implement a shutdown sequence via Hass. As a workaround I was using AutoRemote and EventGhost but this is much less complex!
I have trouble getting it to work though. I implemented it like this:
My Hass is running on a Raspberry Pi on the same network as my desktop PC. The (internal) IP of my PC is 10.0.0.131.
The links in the āView Web Interfaceā look like this:
http://localhost:8000/?action=System.Sleep
What am I doing wrong here?
P.S I also tried without the ā()ā but with the same result.
hmm i can see how what i wrote can be confusing i will try to edit it though it may be too late to be able to edit the post since it has been so longā¦
i use secrets to hide the url because if i have samba turned on anyone on the network has access to the hass config and as such could get the url from the filesā¦ then my evil siblings would just spend the rest of their days turning off my computer while i am using it.
I have tried to implement it on my computer but for some reason the webserver can only accessed from that computerā¦ I will have to look more into that.
that seems quite odd. maybe itās a firewall issue?
For those having a lot of trouble with Airytec Switch Off, you might want to give this program a try SleepOnLan. Before i used home assistant i used this Raspberry Pi Remote Wake/Sleep-On-LAN Server Tutorial by Jeremy Blum for turning my pc on and off remotely. It worked really well but HomeAssistant is better
You are using IP, not localhost, so I will assume you are trying to control remote computer, in that case Airytec Switch Off would require a username and password.
You can setup the password on the Options tab of Airytec and then change your shell_command to :