Hi,
I treated myself to a few little things. For example, I use the network binding for all devices in the network to display their availability. Openhabian runs on several Raspberry Pi’s and I distribute their system states via a rule and MQTT. So I thought it would be cool if I could switch off and restart these Raspberry Pi’s and start, stop and restart openHAB on them. Operating the openhab service even works this way. What surprises me is that the command to shut down and restart the Raspberry Pi via the terminal works, but clicking in openHAB does nothing. This is despite the fact that both were actually implemented according to the same principle.
It has nothing to do with the exec.whitelist:
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo shutdown -h now'
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo reboot'
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl start openhab2.service'
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl stop openhab2.service'
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl restart openhab2.service'
So If I run inside the terminal
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo reboot'
it worked. Also of course:
/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl restart openhab2.service'
Okay, I have now simply changed the password to openhabian. I think it was the default password, wasn’t it?
Inside my thing file I created:
Thing exec:command:openhabianShlPiGeneral_shutdown [command="/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo shutdown -h now'", autorun=true]
Thing exec:command:openhabianShlPiGeneral_reboot [command="/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo reboot'", autorun=true]
Thing exec:command:openhabianShlPiGeneral_start [command="/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl start openhab2.service'", autorun=true]
Thing exec:command:openhabianShlPiGeneral_stop [command="/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl stop openhab2.service'", autorun=true]
Thing exec:command:openhabianShlPiGeneral_restart [command="/usr/bin/sshpass -p openhabian /usr/bin/ssh -t -o StrictHostKeyChecking=no openhabian@192.168.0.11 'sudo systemctl restart openhab2.service'", autorun=true]
Then inside my items:
String ShlPiGeneral_Shutdown "shlPiGeneral Shutdown" (gSystemInfoShlPiGeneral) { channel="exec:command:openhabianShlPiGeneral_shutdown:input" }
String ShlPiGeneral_Reboot "shlPiGeneral Reboot" (gSystemInfoShlPiGeneral) { channel="exec:command:openhabianShlPiGeneral_reboot:input" }
String ShlPiGeneral_Start "shlPiGeneral Start" (gSystemInfoShlPiGeneral) { channel="exec:command:openhabianShlPiGeneral_start:input" }
String ShlPiGeneral_Stop "shlPiGeneral Stop" (gSystemInfoShlPiGeneral) { channel="exec:command:openhabianShlPiGeneral_stop:input" }
String ShlPiGeneral_Restart "shlPiGeneral Restart" (gSystemInfoShlPiGeneral) { channel="exec:command:openhabianShlPiGeneral_restart:input" }
And at least the sitemap:
Text label="shlPiGeneral" {
Switch item=ShlPiGeneral_Shutdown icon="exec_restart" label="shlPiGeneral herunterfahren" mappings=[ON="Herunterfahren"]
Switch item=ShlPiGeneral_Reboot icon="exec_restart" label="shlPiGeneral neustarten" mappings=[ON="Neustarten"]
Switch item=ShlPiGeneral_Start icon="exec_restart" label="shlPiGeneral openHAB" mappings=[ON="openHAB starten"]
Switch item=ShlPiGeneral_Stop icon="exec_restart" label="shlPiGeneral openHAB" mappings=[ON="openHAB stoppen"]
Switch item=ShlPiGeneral_Restart icon="exec_restart" label="shlPiGeneral openHAB" mappings=[ON="openHAB neustarten"]
}
I am still using openHAB 2 in the latest version on both devices. It is started from an Ubuntu 18.04 VM and yes, there is a Raspberry Pi 3 Model B+ on the other side.
I am puzzled by the fact that I can execute the command from the terminal of the VM and the openHAB service works, but reboot and shutdown somehow do not.
Thanks in advance.