Hello community,
after setting up scripts and items to start and shut down my Windows PC, I wanted to do the same with my Synology Diskstation.
As preparation, I made sure that user “Openhabian” can ssh to the Diskstation and login there as root without password using keys (setting up keys, put them in Synology’s authorized_keys file). With the following command, user “Openhabian” can connect to my Synology as root:
[16:12:14] openhabian@openHABianPi:~$ ssh root@192.168.75.10 -i /home/openhabian/.ssh/id_rsa_root
root@DiskStation:~#
Next, I extended the command to shutdown diskstation:
[16:18:36] openhabian@openHABianPi:~$ ssh root@192.168.75.10 -i /home/openhabian/.ssh/id_rsa_root sudo poweroff
After issuing this command, the Diskstation starts to shutdown. Everything ok so far.
Next, I set up a thing with EXEC command, containing the very same ssh-command:
Thing exec:command:synooff [command="ssh root@192.168.75.10 -i /home/openhabian/.ssh/id_rsa_root sudo poweroff", interval=0, autorun=false]
Items:
Switch Presence_DiskStation "DiskStation" <network> {channel="network:pingdevice:192_168_75_10:online" }
Switch Synology_ON_OFF "Synology" <network> ["Switchable"]
Switch Synology_ON "Synology ON" <network> {wol="192.168.75.255#00:11:32:2D:94:C5" }
Switch Synology_OFF "Synology OFF" {channel="exec:command:synooff:run" }
Rules:
rule "Synology onoff"
when Item Synology_ON_OFF received command
then switch (receivedCommand)
{
case ON: {
Synology_ON.sendCommand(ON)
logInfo("default.rules", "Synology_ON.SendCommand(ON) executed")
}
case OFF: {
Synology_OFF.sendCommand(ON)
logInfo("default.rules", "Synology_OFF.SendCommand(ON) executed") }
}
end
Sitemap:
Switch item=Synology_ON_OFF label="Synology Diskstation"
Log-Output when switching off:
2018-12-16 16:09:33.395 [INFO ] [smarthome.model.script.default.rules] - Synology_OFF.SendCommand(ON) executed
So I can see in the log that the command was running, but the Synology does not shut down. The WOL does work, by the way.
Now I wonder why the command
ssh root@192.168.75.10 -i /home/openhabian/.ssh/id_rsa_root sudo poweroff
is working when issued as user “Openhabian” on the command line, but not when used with the EXEC-Binding. The EXEC-Bindung itself is working, because my command for shutting down Windoes by net rpc shutdown works fine.
Any ideas?