Remote Shutdown/Restart/Sleep/Hibernate PC

I tried to add computer control options to home Assistant,
I can’t control PC, but after entering the command in the terminal add-on everything works.

fragment of configuration.yaml

input_select:
  pcoptions:
    name: Laptop
    options:
      - Restart
      - Shutdown
      - None
      - Sleep
      - Hibernate
    initial: None
    icon: mdi:laptop

shell_command:
  shutdown_z800: 'curl -k http://192.168.1.23:8000/?action=System.Shutdown'
  restart_z800: 'curl -k http://192.168.1.23:8000/action=System.Restart'
  sleep_z800: 'curl -k http://192.168.1.23:8000/?action=System.Sleep'
  hibernate_z800: 'curl -k http://192.168.1.23:8000/?action=System.Hibernate'

automation:
  - alias: z800_restart
    trigger:
      platform: state
      entity_id: input_select.pcoptions
      to: "Restart"
    action:
      - service: shell_command.restart_z800
  - alias: z800_shutdown
    trigger:
      platform: state
      entity_id: input_select.pcoptions
      to: "Shutdown"
    action:
      - service: shell_command.shutdown_z800
  - alias: z800_sleep
    trigger:
      platform: state
      entity_id: input_select.pcoptions
      to: "Sleep"
    action:
      - service: shell_command.sleep_z800
  - alias: z800_hibernate
    trigger:
      platform: state
      entity_id: input_select.pcoptions
      to: "Hibernate"
    action:
      - service: shell_command.hibernate_z800   

Don’t think this is the related error. Do you see this once you click execute on any of the available options?

Let’s try this.
Clear the log, choose, shutdown option and refresh the logs. Do you see there anything?

Logbook: Laptop changed to Shutdown

Have you checked your config and reboot HA?

1 Like

hey my friend,if you restart from windows its show a real time status in home assistant?,i mean,you can know via home assistant if your windows[pc] is restart ?

For what it’s worth I want a different route that seems to work well and doesn’t require running services on your computer of mqtt. It does not offer as many features as other options however. I have the following.

  1. A binary ping sensor for my computer
  2. A low privilege user that has access only to one folder
  3. That folder has one program in it: psshutdown
  4. Ssh set up on that machine (I use bitvise)
  5. A shell command for connecting to ssh and exciting psshutdown -d -t 0 to sleep the machine
  6. A shell command to use ether-wake to WoL the machine (be sure to specify the network interface to use)
  7. A template switch to run either of those commands. A button card tied to the binary sensor entity for state. The card executes the switch.toggle service on my template switch.

Ssh is very secure, so that makes it more secure than some other options. I created a user specifically for home assistant, as I mentioned it has access only to the One directory. I also specified that this user can only log in from the IP associated with home assistant, disabled password off, and forced public key auth.

1 Like

Ive managed to get this to work by adding it to the configurations.yaml. Unfortunately, it has stopped all the other automations from working!

Im not sure what i did wrong, Configurations file is as below, any ideas?

Loads default set of integrations. Do not remove.

default_config:

Load frontend themes from the themes folder

frontend:
themes: !include_dir_merge_named themes

Text to speech

tts:

  • platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

##################################
input_select:
pcoptions:
name: Desktop QDOIK1E Power Options
options:
- Restart
- Shutdown
- None
- Sleep
- Hibernate
initial: None
icon: mdi:desktop-tower

shell_command:
shutdown_z800: ‘curl -k h t t p://XXX.XXX.XXX.XXXX:8000/?action=System.Shutdown’
restart_z800: ‘curl -k http ://192.168.0.136:8000/?action=System.Restart’
sleep_z800: ‘curl -k http ://192.168.0.136:8000/?action=System.Sleep’
hibernate_z800: ‘curl -k http ://192.168.0.136:8000/?action=System.Hibernate’"

automation:

  • alias: z800_restart
    trigger:
    platform: state
    entity_id: input_select.pcoptions
    to: “Restart”
    action:
    • service: shell_command.restart_z800
  • alias: z800_shutdown
    trigger:
    platform: state
    entity_id: input_select.pcoptions
    to: “Shutdown”
    action:
    • service: shell_command.shutdown_z800
  • alias: z800_sleep
    trigger:
    platform: state
    entity_id: input_select.pcoptions
    to: “Sleep”
    action:
    • service: shell_command.sleep_z800
  • alias: z800_hibernate
    trigger:
    platform: state
    entity_id: input_select.pcoptions
    to: “Hibernate”
    action:
    • service: shell_command.hibernate_z800