So, I found this great project on github to turn off a windows machine and wanted to share it as it’s something I’ve wanted to do for ages.
go to the releases section and download the zip file and the rest should be easy
I’m using his MQTT system as well Works like a charm.
I added the MQTT command as the turn off for the WOL Switch thats connected to my PC.
On top i added some automation thats based on an open/close sensor thats connected to my Keyboard drawer. As soon as i pull out the Keyboard, the PC turns on, and when i hide it away, the PC turns off
- alias: 'Turn ON PC'
trigger:
platform: state
entity_id: binary_sensor.xiaomi_kontakt
from: 'off'
to: 'on'
for:
seconds: 2
action:
service: switch.turn_on
data:
entity_id: switch.gaming
- alias: 'Turn OFF PC'
trigger:
platform: state
entity_id: binary_sensor.xiaomi_kontakt
from: 'on'
to: 'off'
for:
seconds: 10
action:
service: switch.turn_off
data:
entity_id: switch.gaming
Very good,
for completition if you want to turn off pc even you are not logged into windows you can create a service with this exe using nssm https://nssm.cc/download.
Just tried and work good
Hi, I´ve tried to use this code as mentioned in the first post but that didn´t worked for me, I don´t know what is wrong. Standby, Shutdown and Hibernate woks withe the entity switch.pc.
But WOL doesen´t with this entity, I got WOL working with an entity of switch.windowswol.
I use a different script on my desktop PC (don’t quite remember which one), but this is the code I use. You just have to change the curl command to suite your needs:
I’m using a shelly 1 connected to the power button pins on the board. The shelly has tasmota so I can easily turn it on on home assistant.
If PC is off, switching it will turn on. When the Pc is on, it hibernates.
Basically I configured the windows PC to hibernate when the power button is clicked and if it’s on.
Very simple and I don’t need any additional software in the PC neither WOL compatible card.
Comment from an old Windows support guy, formerly managing over 10,000 Windows PCs…
Sleep and Hibernate cause more problems than they’re worth. Just shut it down and let it boot clean next time.
Yes, this is just my opinion. No doubt someone will chime in with an opposing view. I can only speak from my own experience over decades, starting with Windows 3.1. Take it or leave it.
Other question, do I have to open the 5001 port on my PC firewall? Because for now nothing works sadly
Is there anything to configure first in configuration.yaml to use curl commands? I have this error: Logger: homeassistant.components.command_line
Source: components/command_line/init.py:43
Integration: command_line (documentation, issues)
First occurred: 19:19:09 (2 occurrences)
Last logged: 19:20:24
The code is in my post you’re replying to. The script I was using at the time is this one (I believe):
In my code, it seems I was using a different port so beware that may need adjusting.
That’s about all I can contribute cause I’ve moved on to using IOT Link instead of the script.