How i turn off Qnap from ssh

How i turn off Qnap from ssh, if i use the Terminal & SSH with ssh [email protected] ‘echo mem > /sys/power/state’ works

  - platform: wake_on_lan
    name: "teste"
    mac: 24-5e-be-15-58-0d
      service: shell_command.turn_off_amenserver
  turn_off_amenserver: ssh [email protected] 'echo mem > /sys/power/state'

Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/
Integration: Shell Command (documentation, issues)
First occurred: 12:43:32 (1 occurrences)
Last logged: 12:43:32

Error running command: ssh [email protected] 'echo mem > /sys/power/state', return code: 255

NoneType: None

The issue is, that the shell command gets executed from within the docker container and not within the host.

The easiest approach is to generate ssh keys, copy the private key to your HA config directory and copy the public key to the QNAP. Then change your Shell command to this:

command: 'ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] .168.1.75 echo mem > /sys/power/state'

Where you replace /root/.ssh/id_rsa with the directory you mounted the private key to in the config folder.

Maybe my Posting here is helpfull for you:

hi @Burningstone,

I’ve followed your instructions exactly, unfortunately I get the same error message as nelsonamen posted at the beginning:

Error running command: ssh [email protected] 'echo mem > /sys/power/state', return code: 255

NoneType: None

if I execute the command directly via the CLI, that’s no problem
any ideas?

When you SSH from the host to the QNAP, do you need to enter a password? If yes, then you didn’t copy the public key to the QNAP.
You also didn’t change the command as far as I can see, the command needs to include the location of the ssh keys and strict host key checking needs to be off.

May I know did you manage to solve this? I am having exactly same problem, no problem with CLI but cannot through the switch in HA/

I have the switch off working with ifttt

but IFTTT is a cloud service and free version limited to 3 applets only. :-/

Only need One :crazy_face:

very strange is that the same command previously was working fine. :-/

Hi @Terence_Ng,

yes, I was able to solve the problem for me by enclosing the whole command in quotes:

  turn_off_qnap: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] 'echo mem > /sys/power/state'"

I hope this helps you too…

Hi Wovka,

It seems doesnt help, I still encounter the same error, FYI my previous working command with quotes.

My Current command (copy paste)
turn_off_qts: "ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] ‘echo mem > /sys/power/state’"

Error running command: ssh -i /root/.ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] 'echo mem > /sys/power/state', return code: 255

I suspect the id_rsa file must be in this path /config/ssh/id_rsa, i will try again later.

Ok tested working. nelsonamen maybe you could give a try, as I believe local control is still better than cloud.


I was searching for al long time for this.
But I am new on SSH.

How do you make the key to get HA connect to the Qnap?

I am a little bit further. But stuck on how to copy the key to the Qnap.

Can someone help me further?

Incase others come here later trying this, on QNAP nas you can add the key via the web UI, after logging in on the top right where the user name is displayed, click the user name to bring up a small menu, then click options, a new window will appear, the second tab is called SSH keys, you can add it that way, tho you have to copy and paste the text not transfer the file.

Also for those who have a QNAP NAS with an ARM CPU like I have, then you may find that the above commands does not work, i had to change it, ‘echo mem > /sys/power/state’ will come up with an error of no file or directory with that name, all i put was ‘poweroff’

Hope that helps anyone else trying to get this to work

Thanks to all of you, that worked like a charm for my qnap!

To generate the keys i did:

  • ssh into HA
  • cd config/
  • mkdir ssh
  • ssh-keygen -b 2048 -t rsa
    enter /root/config/ssh/id_rsa
  • cat and copy all text into the qnap webinterface like described by @innerlurken

than use the following shell_command for my arm based qnap:

  turn_off_qnap: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] 'poweroff"
1 Like

Hello pOpY,

thanks a lot for the description.
But i can’t get it going.

I have a QNAP TS251+ and Home Assistant OS running.
The wake_on_lan switch works fine, but only for starting the QNAP.

I have some problems to establish the ssh connection.

Thats my setup:

  1. I generated the private key and the public key in the “SSH Terminal Addon” in HA.
    These keys are then in the /root/.ssh directory.

  2. From there, I copy the private key (id_rsa) to the HA directory /config/ssh/…

  3. and open the public key ( with editor and copy the content to the qnap as described by @innerlurken

  4. now I try to connect via ssh in “SSH Terminal Addon” to the Qnap: ssh [email protected] and I get the following message:


what do I wrong? any ideas?

thanks in advance


Now it works.

I use now the following Shell command for the QNAP TS 251+, if someone need it too.

turn_off_qnap: “ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] ‘/sbin/poweroff’”

Thanks @all.

1 Like

@Subbilein nice that you got it working.
Yes, the poweroff binary maybe live in different locations based on type of the qnap or firmware version.