Remote Shutdown/Restart/Sleep/Hibernate PC

Hi, I’m not sure I understand your question. your link just goes to the home assistant website.

@bilalY i ask you if your project run on hass . io did you have hassbian? I use hass. io , hass.io doesnt have sudo commands.

oh, i see. ye I’ve only ever used hassbian so I have no idea about hassio. sorry, i can’t be of much help to you.

Hey thanks for the input, it works like a charm.

For any1 interested, i have combined it with a WOL command on a switch:

switches.yaml:

  - platform: wake_on_lan
    name: My PC
    mac_address: "00-00-00-00-00-00"
    host: xxx.xxx.xxx.xxx
    icon: mdi:desktop-classic
    turn_off:
      service: shell_command.sleep_my_pc

Problem arised when I tried adding further functionality, i.e. turn off the monitors (with the help of nircmd.exe)

The predefined commands of the airytec thingy (say the preinstalled one that launches calculator) do work when calling them from the tray icon but do not work from the web interface that airytec is providing nor when calling them from HA.

They do create a process (calc.exe) in the task manager but the actual window never appears.

Problem is also described here

I realise this is probably a windows problem but, got any ideas?

Hi to all.
If you have any problem (like curl not works or similar) try to force manually on Windows Firewall (if enabled) app rules (Local and not) add the executable path (ex. C:\Program Files\Airytec\Switch Off\swoff.exe ) and try to modify config.yaml without () after curl .
It works for me!

c ya

Don’t think my issue is on curl, the command runs but I only get the calculator on windows as a process and k thing pops up.
I think it’s some issue of airytech

Hi,

it works on hass.io as well.
Generally, shell commands work on SSH for hass.io, only likes of sudo etc. don’t.

Back to hass.io, I followed the instruction, set up password for Airytec in Options, I couldn’t see View web interface link otherwise. Created firewall rule for port 8000 (not sure if necessary tho).
Left automation: code part as it is, and for shell command:

shutdown_z800: 'curl -u User:password -k http://yourip:8000/?action=System.Shutdown'

etc.

Works like a charm.

Many thanks to bilalY.

3 Likes

But I have the next problem. If I turn off the PC using Airytec (via hass.io) then my PC (Win 10) will not turn on via WOL, only turns on with a physical button. If I turn off the PC using the start menu, then my PC (Win 10) will turn on via WOL.

I found I had this problem also but my friend doesn’t have this issue, it’s possible it is somthing to do with the WOL implementation in the system itself. To be honest I never shut down using airytec. If I’m away from home I use WOL to turn on the machine then I access it with TeamViewer which I have setup to autostart. When I am done I perform a shutdown from the start menu. the whole purpose for me with this is the ability to reboot the machine if there are any problems with remote access caused by a crash etc.

Thank you bilalY for the answer. At the moment I use this same circuit (with Teamviewer), but I wanted automation. Now, I use hibernation instead of turning off (this is for automation).

Hi…I tried the OP method and it did not work. I have to add program switchoff into the Windows Firewall to allow its access; then it works smoothly…thanks a lot.

Hello guys!

Have you tried this app instead of Airytec? A lot more capable and flexible…

https://iotlink.gitlab.io/

Thanks!

6 Likes

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