nelsonamen
(Nelsonamen)
October 11, 2020, 11:57am
1
Hi
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"
host: 192.168.1.75
mac: 24-5e-be-15-58-0d
turn_off:
service: shell_command.turn_off_amenserver
shell_command:
turn_off_amenserver: ssh [email protected] 'echo mem > /sys/power/state'
Logger: homeassistant.components.shell_command
Source: /usr/src/homeassistant/homeassistant/components/shell_command/init .py:111
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 admin@192 .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.
Lucan
October 12, 2020, 10:25am
3
Maybe my Posting here is helpfull for you:
Hello togehter,
I just switched from OpenHAB to HomeAssistant (HassIO on Raspberyy PI4 4GB).
Now I try to adapt my OpenHAB switches etc. to HomeAssistant.
One of the “problems” I’ve run into is a switch to power on / off my synology nas.
It seemed to be quite complicated due to the lack of permissions etc… Also everything i read on did not realy work for me. So I got a bit deeper (first time to use docker etc.)
And found the following Solution for my problem which I will show you below.
C…
wovka
November 6, 2020, 10:53pm
4
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.
Terence_Ng
(Terence Ng)
October 10, 2021, 5:28am
6
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/
nelsonamen
(Nelsonamen)
October 10, 2021, 6:10am
7
I have the switch off working with ifttt
Terence_Ng
(Terence Ng)
October 10, 2021, 6:13am
8
but IFTTT is a cloud service and free version limited to 3 applets only. :-/
Terence_Ng
(Terence Ng)
October 10, 2021, 6:35am
10
very strange is that the same command previously was working fine. :-/
wovka
October 11, 2021, 11:49am
11
Hi @Terence_Ng ,
yes, I was able to solve the problem for me by enclosing the whole command in quotes:
shell_command:
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…
Terence_Ng
(Terence Ng)
October 12, 2021, 1:07pm
12
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.
Terence_Ng
(Terence Ng)
October 12, 2021, 1:26pm
13
Ok tested working. nelsonamen maybe you could give a try, as I believe local control is still better than cloud.
Hello,
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
pOpY
May 12, 2022, 5:43pm
17
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 id_rsa.pub and copy all text into the qnap webinterface like described by @innerlurken
than use the following shell_command for my arm based qnap:
shell_command:
turn_off_qnap: "ssh -i /config/ssh/id_rsa -o StrictHostKeyChecking=no -q [email protected] 'poweroff"
1 Like
Subbilein
(Subbilein)
October 21, 2022, 8:00pm
18
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:
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.
From there, I copy the private key (id_rsa) to the HA directory /config/ssh/…
and open the public key (id_rsa.pub) with editor and copy the content to the qnap as described by @innerlurken
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
Subbilein
Subbilein
(Subbilein)
October 22, 2022, 12:03pm
19
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
pOpY
October 22, 2022, 1:23pm
20
@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.