At the quick press of the power button, my htpc starts up and activates its screen (aka TV). Same thing turns it off again. No problem.
Now, with a voice assistant (and my being very lazy… ), it would be nice to ask Assist to both turn it on and off. “On” is simple to to do - just add a power plug and let Assist turn it on. For “OFF”, however, just cutting power from a pc is a bad idea.
Have a look at hass agent.
This runs on the pc you want to control, it creates entities in HA and it is possible to execute command on the pc such as gracefully close programs before a shutdown of power cut.
The smart plug is redundant.
You will need a ping sensor, a WoL command, and one of the ways to shut down your computer (you can find on this site).
All of this is assembled into a template switch.
switch:
- platform: template
powerpc:
turn_on:
action: wake_on_lan.send_magic_packet
data:
mac: xx:xx:xx:xx:xx:xx
turn_off:
action: button.press # I'm using the hass.agent (Windows only) to shutdown
data: {}
target:
entity_id: button.main_pcoff
friendly_name: "PCswitch"
value_template: "{{ (is_state('binary_sensor.mainpc', 'on')) }}" # state of ping sensor
Thank you both for your suggestion! At first, I thought that this is the solution I am after. Very elegant!
At closer inspection, it appears to only work with a specific, proprietary, closed source operating system.
I was totally unaware of that. I just use Linux for simplicity - not very proficient. That other OS is just too complicated for me. You need to know stuff about the registry and how to construct weird hex codes to put there when it’s not behaving. Way beyond me.
When experimenting to set this up, connecting to local hosts via the terminal, it seems that HA is unable to resolve names. I found the following:
Where on earth does that IP come from?!?
This is how it is set up:
What is going on here and why is name resolving not working?
I still have the issue of name resolution not working. This automation, using IP addr, will only work until DHCP changes it, but that’s a separate problem. For now, I consider this victory. WoL has been around for a looong time. Not knowing better, I have just ping:ed the host for testing WoL and, of course, it never worked… This time, with a proper wakeup sequence, it worked on the first try - yay!
I can now say “OK Nabu, turn on the TV” AND “OK Nabu, turn off the TV” and it works!