OK Nabu, turn off the htpc?

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… :wink:), 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.

Does anybody have a solution for this?
//

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.

1 Like

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 
1 Like

Thank you both for your suggestion! At first, I thought that this is the solution I am after. Very elegant! :smiley:
At closer inspection, it appears to only work with a specific, proprietary, closed source operating system. :nauseated_face:

So, I am still looking for solutions… :thinking:

As a user of a *nix system you should know that you can simply send the shutdown command via ssh. :slightly_smiling_face:
The other logic remains unchanged.

1 Like

Thank you mchk!

I was totally unaware of that. :smiley: 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. :grimacing:

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:
Markering_272
Where on earth does that IP come from?!?
This is how it is set up:
Markering_273
What is going on here and why is name resolving not working?

I feel fumblier than ever!
/Fumble

It’s quite involved. Or, rather, I spent a lot of time on it. There is a guide here
But it lacks critical details for Linux. They can be found here

Here is the section in my config.yaml, in case it helps someone:

switch:
  - platform: wake_on_lan
    name: "lassie"
    mac: xx:yy:zz:ae:b7:21 
    turn_off:
        action: shell_command.turn_off_lassie
shell_command:
    turn_off_lassie: "ssh -i /config/.ssh/id_ed25519 -o UserKnownHostsFile=/config/.ssh/known_hosts [email protected] 'sudo poweroff'"
    friendly_name: "TV"
    value_template: "{{ (is_state('binary_sensor.TV', 'on')) }}" # state of ping sensor 

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! :star_struck:

/Fumble