[SOLVED] Power on/off Synology Diskstation with Openhab2

Hello guys,
I am pretty new to openHAB and still trying to figure out the easy things.
Have spent a lot of time googling for hints/howtos.

Setup: Raspberry pi running openHABian
Synology DS215j

What I want to accomplish:
Use a simply switch, that tells me if synology is ON /OFF and that I can use to turn it ON or OFF.
What have I accomplished so far?

Status as well as WOL work.
I can shut down the Synology with a bash script which I put in the openhabian home folder /home/openhabian on the raspberry pi.
[I had to configure passwordless ssh and enable all administrators to run the poweroff command on the Synology.

So when running the bash script via PuTTy on openhabian the Synology shuts down.
I seem to be able to run the script:

items file:

        Switch DS215j "Diskstation DS-215j" {	
				exec=">[OFF:'bash ./synology.sh']",

I have included the commented part as I tried to use a simple thing for the command

Thing exec:command:synoff [command="./synology.sh" ]

Both (running thing or direct exec) give the following error

An exception occurred while executing ‘./synology.sh’ : ‘Cannot run program “./synology.sh”: error=2, No such file or directory’

So it must be that openhabian uses a different user or starts in a different folder - I assume.
Additionally the script seems to run every 1 minute although the station is online and I did not use the button.





did not do the trick either

I would greatly appreciate a hint in the right direction (link to existing topic) or direct help.
Thanks for your time.




why .sy ? Type-o ?
In case yes, I wrote that I already tried
with the same outcome.
or are you referring to the . in front of /home ?
I now tried that as well. same outcome.

Yes typo, sorry
Corrected above
Try moving the script into /etc/openhab2/scripts

2018-12-03 01:16:02.796 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while executing ‘./synology.sh’ : ‘Cannot run program “./synology.sh”: error=2, No such file or directory’

Did that now as well. I am just wondering as the .scripts file in the folder says all files in that folder have to be .script…

But I assume the command is not the problem.
The script is executable since I can manually run it when logging into the pi via PuTTy as user openhabian.

You also need to change the path:

exec=">[OFF:'bash /etc/openhab/scripts/synology.sh']",

The alternative is to remove the bindings in the item and use a rule:

rule "turn of nas"
    Item DS215j received command OFF
    executeCommandLine("/etc/openhab/scripts/synology.sh", 5000)

Thanks again for all your help.
No matter which path I use the error message always states ./synology.sh

Tomorrow i will try using the rule/rules.

Well, the error message came from a broken thing, which I could not delete/modify. It did not come from my script/s.

Problem however is that I still cannot run the command due to missing rights. I guess the problem is described here:
Openhab is not running the commands as user openhabian, but as user openhab

Now I will try to set up keys for user openhab so it is possible for openhab to login to the synology. Or I try to run the command as user openhabian

Actually my script only consists of 1 line, so I might be able to run that as another user…

ssh -p xxx openhab@192.168.178.xx sudo poweroff

So. I have solved the issue. Since I figure that I am not the only person having these problems I will write down a detailled guide in this post.

Since I dont have time now I will just write quick notes what/how I did it.

  1. Create a user Openhab on Synology with admin rights
  2. via editing sudoers file I granted all users the right to use poweroff command without password (on synology)
  3. used this guide to setup the ssh-key files https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/
  4. copied the ssh. files on my Pi (running openhabian) from user openhabbian home folder to openhab home folder
  5. logged into synology with "sudo -u openhab ssh openhab@synologyIP or directly executed the command sudo poweroff (I mainly did this to have the user in the accepted list and to test if all worked).
  6. then I set up my items/sitemaps/ with help of this post:
    Wol & exec binding -> power On and Off Pc
    with a slight variation
    case 2 in the rules file I used the following instead:
    executeCommandLine(“ssh openhab@synologyIP sudo poweroff”, 5000)

Create a new thread in the categoty tutorials/solutions, please
And link to it in this thread.

I will do. Detailled guide will be updated in this Tutorial/post