How Can I Cleanly Shutdown HA In VirtualBox From Windows (The Host) With CLI?

I’ve noticed the HA Shutdown trigger does not fire when HA is shutdown using VirtualBox acpipowerbutton.

Is there a way that I can cleanly shut down HA (residing inside VirtualBox) using CLI from Windows (the host)?

You should be able to ssh into the VM from Windows and shut it down.

Thanks, but I need to be able to do this automatically with a cli command or such.

IF you set up trusted keys ssh could work for that. This is a Linux question not a Home Assistant one.

This is HAOS right? I’m using the provided ‘Official’ VirtualBox VM, which I thought was based on Home Assistant OS. I’m getting all these different layers mixed up. :weary:

Home Assistant OS is a pared down Linux variant. It still uses the Linux kernel & programs such as ssh.

You can ssh in to the OS, and simply issue ha host shutdown You can do this programatically.

Sounds like what I need. do you know of any examples I could use?

same time every day? use a cronjob with the shutdown command, but why have it off?

No set time, it’s an on demand thing.

I have some ‘clean up’ automation that I would like to run anytime HA shuts down.

The startup trigger works as expected.

If the HA OS would reliably catch the shutdown call via VirtualBox’s acpipowerbutton, this wouldn’t be necessary.

I could not figure out how to do this via a direct method, so I used MQTT and hassio.host_shutdown. Seems to work.

can also be done from config:

That’s hard to reach from outside HA, from the windows host.

Hmm, that is how I do it from my W10 host with VirtualMachine, i just open a browser…

Even works from my IPhone app…:thinking:

But from VirtualMachine console should work

ha host shutdown

I needed an automated solution.

I’m going to pursue the possibility of running a script that…

  1. runs at shutdown (My Win11 has a Group Policy Editor, which I can access by going to Control Panel and typing Group in the search field)
  2. calls putty.exe to run a txt file of CLI commands in which I have inserted ha host shutdown and some sort of command to execute a 3-minute delay (I’m new to this but it seems like it should be feasible)

If you don’t have Putty, go to Putty.org to find the latest download link.

I plan to try this out soon. If anyone has any thoughts feel free to chime in.

I use VMware, and i noticed that my HA vm will go to ‘suspend’ mode when the host reboots (it was W10, but i recently moved to Debian, still behaving the same though).

My guess is that the vmware image of HA has some version of vmware tools installed (as it also shuts down gracefully when i use the power off button within vmware)

I am not sure if virtualbox should have the same behavior, tries vbox once, but found it highly unstable….