Shutdown Pi using exec binding in OH2.1 (openhabian)

I am running openhab 2.1, installed via openhabian on a raspberryPi 3.

In OH 1 I had the following item which was working fine:
Switch ShutdownPi “Shutdown Pi” (gPi) {exec=">[ON:sudo shutdown now]"}

In OH2 I have the following setup but nothing happens when I press the switch:

Thing exec:command:shutdownpi [command="sudo shutdown now"]
Switch ShutdownPi "Shutdown Pi" <computer> (gPi) {channel="exec:command:shutdownpi:run"}

Any idea?

Thanks and Regards,

You have given the openhab user sudoer permissions to run shutdown without requiring a password?

@Alexaas maybe the first link allready helps you.
If it still does not get executed you can take the long way with a rule, similar setup as the second link.
The long way may also help you debugging by logging the returned massage from the command line.

Thanks. That worked. BUT it ended in an endless loop because everytime openhab started up the Thing was executed and the pi restarted or was shutdown :slight_smile: I had to be fast to fix this…

I knew there was a reason I’m not very positive about OH shutting down the system it is running on.

There are some ways I think you can address this problem but it is going to require you to abandon theExec binding in favor of using executeCommandLine from a Rule.

Essentially you need to convert your Switch to a proxy and create a rule that only triggers when that Proxy Item receives a command ON.

That should take care of the loop.

Yes, I already had the same idea. Thanks