Wake on lan, shut off and status of Windows PC?

Hi,

When I used homebridge earlier, there was a program I could have running on my Windows PC that told Homebridge if the PC was on or off, and I could send a shutdown command.
Is it possible to make Home Assistant work like this?
So that if I start my PC manually it will get the status from it?

Thank you!

try the wake on lan switch.

For the off command use a shell command for netrpc shutdown. Examples below

https://github.com/SilvrrGIT/HomeAssistant/blob/master/switches.yaml#L74

https://github.com/SilvrrGIT/HomeAssistant/blob/master/shell_commands.yaml#L4

Will this get the state from the PC too? Even if I start the PC with the normal power button (not Home Assistant) will Home Assistant be able to get the state that it is turned on or off?
Thank you!

use the nmap device tracker to detect the prescence of your pc.

The wake on lan switch will ping your device to see if it’s on. The only downside is it will initially turn back off until your computer boots and the switch can register it’s on.

Therefore he can use the device tracker to see if the computer is online or offline.

That is built into the wake on lan switch. No need for the device tracker method.

You’re right. I don’t defined a turn_off method on my WOL switch, so it turns back off after hitting it on. Maybe this is the reason why my switch is always off.

I managed to make the wake on lan function work, and it will get the state too.
But shutting off is not working.
This is my shell command:
shell_command:
pc: ‘net rpc shutdown -I 192.168.1.3 -U USERNAME%PASSWORD’

And this is the switch itself:
- platform: wake_on_lan
name: PC
mac_address: “MACADRESS”
host: 192.168.1.3
turn_off:
service: shell_command.pc

If I try to run this on SSH from the NAS itself (which Home Assistant is installed to).
This is the result:
Unknown parameter encountered: “printer admin”
Ignoring unknown parameter “printer admin”
Could not connect to server 192.168.1.3
The username or password was not correct.
Connection failed: NT_STATUS_LOGON_FAILURE
Could not connect to server 192.168.1.3
The username or password was not correct.
Connection failed: NT_STATUS_LOGON_FAILURE

is your user name the one displayed at C:\Users? Mine is shortened in this directory and isn’t my full username.

The username that is displayed in C:\Users is my first name only. When I check out my username in the settings it is both my first and last name.
And if I try from SSH on my server with just my first name this is the result:
Unknown parameter encountered: “printer admin”
Ignoring unknown parameter “printer admin”
Could not connect to server 192.168.1.3
The username or password was not correct.
Connection failed: NT_STATUS_LOGON_FAILURE
Could not connect to server 192.168.1.3
The username or password was not correct.
Connection failed: NT_STATUS_LOGON_FAILURE

If I try with both first and last name, separated with a space I will get the question
“Enter Firstnames’s password:”
Which I enter, and then I get the same error:
The username or password was not correct.
Connection failed: NT_STATUS_LOGON_FAILURE

But the difference is that one is a recognized username and the others isnt. Even though it doesnt work anyway!

Do you have a password set for windows logon? Make sure you are using your password and not the PIN that can be used for logon (if on windows 10)

I have set Windows 10 up so that I don’t need to login when I start the PC. But I have a password and it is not a PIN.

Weird, now I succeeded when running via Putty from the server. But from Home Assistant it doesnt work at all.
Nothing happens!

What version of HA are you running and what was your install method?

Latest version, just updated. Installed on a Debian server.
By the way, can you put shell_command on configuration.yaml or do you have to create another file for it. I think there is something easy I have missed, as everything else works. And I now can use the exact same command on SSH.

do you have any quotes around your shell command?

If ‘single quotes’ try “double quotes” or vice versa. I don’t have my config handy to check my secrets file and see what I used.

I have tried both without success.

Now it got me thinking, maybe having Home Assistant installed in a Docker container causes problems? Maybe it wont let me run shell commands? I tried a simple test_cmd: touch /home/docker/.config/homeassistant/test.txt
And ran it from Home Assistant Services tab, and no file is created.

Any ideas?

hmm, sorry, no good with docker.

If you haven’t figured it out, a command in a docker container will run inside the container, not the host. So if you wanted to make a text file in /home/docker/.config/homeassistant, you’d probably want to use ‘touch /config/test.txt’ assuming you had ‘-v /home/docker/.config/homeassistant/:/config’ in your run command. I don’t think it’s possible to run a command as the host from a docker container (you could try ssh’ing into the host if necessary). The container acts as its own computer, not like a program on yours.