I’d like to add a beautiful way to debug the command when something doesn’t work. The exec binding includes an output channel that contains the last output.
By binding output to an item, you will se the output of the executed command in the common log.
By using the expire binding, it can reset afterwards so that the same output will show up for each execution in the log.
Working example for OH3, where the service now is called “openhab.service” without the “2”:
Prerequisite: Install the exec binding.
Terminal:
> sudo visudo /etc/sudoers.d/010_pi-nopasswd
Cmnd_Alias SHUTDOWN_CMDS = /bin/systemctl restart openhab.service
openhab ALL=(ALL) NOPASSWD: SHUTDOWN_CMDS
misc/exec.whitelist:
sudo /bin/systemctl restart openhab.service
things/system.things
Thing exec:command:openhab_restart [command="sudo /bin/systemctl restart openhab.service", interval=0, autorun=true]
items:
Switch openhab_restart "Restart Openhab" {channel="exec:command:openhab_restart:run"}
String openhab_restart_output "Restart Openhab" {channel="exec:command:openhab_restart:output",expire="1s,command=done"}
Number openhab_restart_exit "Restart Openhab" {channel="exec:command:openhab_restart:exit",expire="1s,command=0"}
sitemap:
Switch item=openhab_restart mappings=[ON="Restart"]