Script computer on and and Script computer off?

Here’s my deal. I want to have a reference to a computer name and a switch associated with it. When the computer pings, I want it on. When it doesn’t ping I want it off. Here’s the thing though. When it’s off and I MANUALLY trigger it on, I want it to run a shell script I define. Similar to the turn_off on the wake_on_lan module. If it’s on and I MANUALLY switch it off, I want to run another script to turn off the computer. I tried this with success with the wake_on_lan module but won’t work for virtual machines that are off. Any help would be appreciated.

What hypervisor are you running? Hyper-V, VMware, VirtualBox, etc? I believe the latter two have the ability to enable WOL. You can look at this for Hyper-V

https://deploymentpros.wordpress.com/2016/11/28/wake-on-lan-for-hyper-v-guests/

Thanks for the reply. I am currently using VMware Workstation Pro 15.5. Note I did find one theoretical solution that hasn’t been updated since 2011 or something. It found all my virtuals but did not respond to WOL requests.

I wasn’t aware you could listen for WOL requests on one computer across multiple Mac Addresses but maybe there is a way to code something like this. A listener with hard coded addresses it listens for and scripts that trigger to launch a given virtual machine. Probably beyond the scope of HA. :slight_smile:

I saw that, but didn’t seem to have a CLI to it. Not seeing too much success with WOL and VMs

I am assuming your HA is on Linux.

You could run a MQTT on your Windows workstation: https://github.com/msiedlarek/winthing

Then setup a command in the winthing.ini to start the VM via VMware Workstation CLI: https://www.vmware.com/support/ws5/doc/ws_learning_cli_vmrun.html

So for the HA side, you could have a input_boolean switch that would it run a command to send a MQTT payload to the WinThing running on the PC that has VMware Workstation.

Thanks for the info. Going to absorb your response more when I get home from work. For reference the tool I referenced is odd. If I download their WOL client it actually works, sees the request and launches all be it hidden which is annoying. If I use another 3rd party app it doesn’t respond to it. This is both local so no firewall issues or anything. Not sure if it’s something to do with the apps if they are using the IP of the machine or the subnet to connect but when I would try it with their app it worked. When I tried it with the third party app with either 255.255.255.255 or 192.168.0.255 for the broadcast address or even the IP of the box, with the appropriate mac address of course, it would fail.

OK so that was interesting. So installed the above WOL app again. Installed a DOS command line app and did:

WolCmd.exe 000C2994370A 192.168.0.8 255.255.255.0 7

So basically:
Mac Address: 000C2994370A
IP of Host Server: 192.168.0.8
Broadcast Address: 255.255.255.0
Port: 7

It works so this shows it does indeed work. However in HA I do:

- platform: wake_on_lan
  name: "ServerName"
  mac: "00:0C:29:94:37:0A"
  host: 192.168.0.8
  broadcast_address: 255.255.255.0

Nothing happens. Now here’s the thing. The switch is in the on position already as the host server is obviously on that VMware is on. So I switch the switch off and on again. Nothing happens. Now is it actually even trying to send the command? No idea.

Geezes. I just figured it out. The default ports for WOL are 7 and 9. 7 being the usual primary one from what I can see. Looks like the HA WOL platform is hard coded to 9. I switched it in the app and it’s triggering now.