Skip to content

Instantly share code, notes, and snippets.

@kmplngj
Created June 27, 2022 13:13
Show Gist options
  • Save kmplngj/811622e1af4037a0c5331f870fb82de7 to your computer and use it in GitHub Desktop.
Save kmplngj/811622e1af4037a0c5331f870fb82de7 to your computer and use it in GitHub Desktop.
Home Assistant Switch to start/shutdown VmWare ESXi VM
# needs SSH active on ESXi host
# needs SSH public key from HomeAssistant in ESXi ssh authorized_keys config '/etc/ssh/keys-<username>/authorized_keys' Have a look here: https://kb.vmware.com/s/article/1002866
# get VM ID on ESXi commandline by 'vim-cmd vmsvc/getallvms' You need to set this in the scripts commands where 00 is shown
# needs VMware Tools installed on the VM you want to control
# change in Switch: ESXi ip address, VM ID, switch name and switch friendly name
switch:
# https://www.home-assistant.io/integrations/switch.command_line/
- platform: command_line
switches:
windows11_vm:
friendly_name: Windows 11 VM
command_on: ssh -i /config/.ssh/id_rsa root@192.168.xyz.zz -o StrictHostKeyChecking=no -q 'vim-cmd vmsvc/power.on 00'
command_off: ssh -i /config/.ssh/id_rsa root@192.168.xyz.zz -o StrictHostKeyChecking=no -q 'vim-cmd vmsvc/power.shutdown 00'
command_state: ssh -i /config/.ssh/id_rsa root@192.168.xyz.zz -o StrictHostKeyChecking=no -q 'vim-cmd vmsvc/power.getstate 00 | awk "END{print}"'
value_template: '{{ value == "Powered on" }}'
icon_template: >-
{% if value == "Powered on" %} mdi:toggle-switch
{% else %} mdi:toggle-switch-off
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment