The Home Assistant Proxmox VE Integration only creates sensors for VM states, and does not yet provide a way to control those VMs. If you want to simply shutdown/startup a VM from Home Assistant, the rest_command
is your friend:
rest_command:
command_vm:
url: https://192.168.1.196:8006/api2/json/nodes/abathur/qemu/{{ vmid }}/status/{{ command }}?{{ params }}
headers:
authorization: PVEAPIToken=TOKEN_NAME_GOES_HERE=UUID_GOES_HERE
method: POST
verify_ssl: false
Create the API key in the Datacenter > Permissions > API Tokens. I had to uncheck Privilege Separation
. Replace the token name and UUID in the authorization header with what Proxmox spits out.
This will create a command_vm
service in Home Assistant you can use in automations. I use it to:
- Shutdown crypto mining VMs when incoming solar energy drops below a kW/h.
- Reset frozen MacOS vms after a few minutes of ping failure
The HASS service needs 2 data parameters, while a third called params is optional:
service: rest_command.command_vm
data:
vmid: 125
command: suspend
params: todisk=1
vmid
is the qemu vm you’re commanding. command
is any of the appropriate status changes from the PVE API. Finally, params
are any extra data payloads to include, like timeout.
The params
should be formatted as url params, so multiple would be included like:
params: timeout=600&forceStop=1
boolean values should be sent as 1/0, since ’true’ is sent as a string. You can control LXCs similarly, see the API docs for more rest_command
ideas:
https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}