Synology NAS - SSH Shutdown issue

I tried to avoid this with a python script, but I can’t execute it… “python3 command not found”
I need to install python on Hassio???

I just used Python… I’ll need to check that tomorrow and let you know…

This was the shell command I created that works.

# Clear Out Gmail Alarm Notifications
  removealarm: python /config/

I then have a button card in lovelace I can use to call it.

No python command for me.

core-ssh:~# python /config/script/                               -bash: python: command not found
core-ssh:~# python3 /config/script/                              -bash: python3: command not found

If I try to execute my

  turn_off_nas: python3 /config/script/

I get this error:
Error running command: python3 /config/script/, return code: 1 NoneType: None

Same issue with python instead of python3…

The right way to install python on Hassio?

I tried also with python_scripts:

but if I execute my script (

import subprocess
import sys
cmd = "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /root/.ssh/id_rsa [email protected] 'sudo /sbin/shutdown -h now'"
x = subprocess.check_output(cmd, shell=True)

I get this error:

Error executing script: __import__ not found
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/python_script/", line 166, in execute
    exec(compiled.code, restricted_globals, local)
  File "", line 1, in <module>
ImportError: __import__ not found

Solved following this guide:

Could you tell us, how you did it?
I try to find the guide, but the link is broken.
Thank you


Please could you share with us the shell command that you use inside the

I would like to create the same in order to shutdown my SynologyNass



Can you give us more information? I tried to follow the guide that you reference

Problem for me is that i not able to connect SSH over port 22222 to the RaspberryPI host.
I follow the procedure to import the authorized_keys via USB but all the time i get the same problem
Conection Refused!!!

For me that´s means that the Raspeberry host not allow SSH conection over this port!
:frowning: I just spend hours to implement but no clear information or idea about what is the missing point here…

import imaplib
box = imaplib.IMAP4_SSL('', 993)
typ, data =, 'ALL')
for num in data[0].split():, '+FLAGS', '\\Deleted')

Thank´s for sharing but this is not valid for me :frowning:
I need something to shutdown my Synology Nass from the HA

Hi, I use a simple ssh shell and sshpass to shutdown my Synology Nas.

#! /bin/bash
sshpass -p "thepassword" ssh -t  [email protected] "echo thepassword | sudo -S poweroff"

Just replace thepassword and user by your own credentials

Are there any prequisites to do on the NAS?
I typed in the command, there were no error messages, but nothing happened with the NAS

NAS Side:

Make sure the SSH service is enabled on your NAS
Control Panel > Terminal & SNMP > Terminal > Enable SSH
Make sure the user you use has admin role

On HA side:
First of all try just a normal SSH session to the NAS from your HA shell.
Most probably you will first be prompted to accept the NAS as a valid host (security fingerprint)
After this fingerprint acceptation the sshpass command should work fine

Ah, thank you. It was the hint with connecting from the HA shell to the NAS first to accept the security fingerprint.

  - platform: command_line
        command_on: 'wakeonlan 00:11:32:1A:A2:70'
        command_off: 'sshpass -p "password" ssh -t [email protected] "echo password | sudo -S poweroff"'

Hm, it works manually over the linux shell.
But with the above configuration, i can only start the NAS, but the ‘off’ command seems to be ignored. Anything missing or is this the wrong approach with a command-line switch?

I also tried this way, but no effect either:

  diskstation3_shutdown: '/usr/bin/sshpass -p "password" ssh -t [email protected] "echo password | sudo -S poweroff"'

  - platform: wake_on_lan
    mac: "00-11-32-1A-A2-70"
    name: diskstation3
      service: shell_command.diskstation3_shutdown

I always had problems with HA and quotes in shell_command and prefer to use bash script ran by HA.
This is why you have #! /bin/bash at first line.
I suggest you try the same approach…

I´m quit unfamiliar using bash scripts - I just tried putting your two lines of code into “” and put that file into /config/scripts and replaced the shell_command into:

  diskstation3_shutdown: bash /config/scripts/

Should this work? Unfortunately it´s still not shutting down.

Make sure the script works by executing manually from the shell
you may need to trim the #! /bin/bash depending on your platform.
Verify the path for bash in linux console and adjust accordingly if different

whereis bash
bash: /bin/bash /etc/bash.bashrc /usr/share/man/man1/bash.1.gz

This is an extract of my configuration.yaml and it works like a charm:

  - platform: template
        friendly_name: Synology NAS
        value_template: >-
          {% if is_state('timer.nas_delay', 'idle') %}
          {{ states("binary_sensor.nas_ping") }}
          {% else %}
          {{ states("input_boolean.nas_power_status") }}
          {% endif %}
          - service: shell_command.nas_command_on
          - service: input_boolean.turn_on
              entity_id: input_boolean.nas_power_status
          - service: timer.start
            entity_id: timer.nas_delay
          - service: shell_command.nas_command_off
          - service: input_boolean.turn_off
              entity_id: input_boolean.nas_power_status
          - service: timer.start
            entity_id: timer.nas_delay
        icon_template: mdi:network-attached-storage

timer: # It takes 50 seconds for my NAS to connect / disconnect from the network
    duration: '00:00:50'

input_boolean: # This stores the temporary  power state while we are waiting for the ping to update
    name: NAS Power Status

  - platform: ping
    name: nas_ping
    scan_interval: 2
    count: 2

        nas_command_on: /config/
        nas_command_off: /config/

I have no clue… :sob: I can execute the script manually from the shell and it works.
within home assistant, nothing happens exept always the same error code in the log:
(I tried several configs)

This might be a stupid question, but i just don´t know better. Which shell is being used to execute the command? I have installed ubuntu, and on top of that, Home Assistant with docker.
Is this the ubuntu shell, or the Home Assistant CLI the command runs in?

2020-05-11 12:19:13 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash /config/scripts/`, return code: 127
2020-05-11 12:45:49 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `/bin/bash /usr/share/hassio/homeassistant/scripts/`, return code: 127
2020-05-11 13:07:09 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `./config/`, return code: 127
2020-05-11 13:13:51 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `bash /config/`, return code: 127