Hi,
I try to add a Button in my sitemap which run a simple Shell script on local Raspberry when the button is pressed. The script must run as user “root”, so a ‘sudo …’ must be added (or I have to add this part in the shell script).
(The EXEC binding is installed in oH)
I’m not shure, must I create a rule to realize this?
Let’s step back. You would be well served to review the concepts section of the Docs because your question belies a lack of understanding of the important concepts that make up openHAB and how they work together.
You need to:
Create an Exec binding Thing
Create one or more Items associated linked to the Channel(s) of the Thing
The sudo part is kind of essential in this solution. Without it, it will not work because openHAB would need to provide a password to execute the script which cannot be done. Hence, you need to configure the OS such that it knows that it does not require a password when the openhab user uses sudo to execute your script.
Later you may want to provide a button in HABPanel as well, but it is easier to first get it to work using a sitemap.
Be sure to also checkout the docs from the exec-binding. It contains examples (unfortunately not using sudo) and more information about other channels made available by the exec-binding, e.g. how to get the output of the executed script.
So,
this is working now,
a “Switch” is executing a script which runs under user “root” !
But my "Switch should not a “switch”, should be more a “Push button” (not be “ON” after “clicking”.
(or going in state “off” after 2 seconds, but how? . New rule?)
At the end I have 4 different scripts which should be started, so I think a bether solution is to use one “button” with 4 options instead for single switches.
In a sitemap I have this for a rollershuter (and lamps), to select a specific value with pressing the wanted selection. See example-picture.
But this switch should be not in the sitmap, must be in sub-screen.
Actuall I put this single switch (in your example “openhab_restart”) in my “gVswitches” group.
Is it possible to create a switch with 4 selections (and every selection start a different script, maybe with a case-part in a rule (case: 1=start-script1; 2=start-script-2, …))
Also after pressing one from the (4) options, the value must/should not be stored and shown as “active” (pressed) in the display: all 4 options should be going into state “inactive” (Off).
And Rich, you are right, I try do understand more and more in oH … learning with examples like these are very good! My problem was the “Virtual” action, because I had no physical item to send a value, now I see: I can use a channel-binding to execute a shell-script.
I’m currently at work, so I can’t provide you with a full answer.
Fixing the button to stay off should be easy to accomplish adding the autoupdate parameter to your item and setting it to false (although I have never used it with a channel before, only with a binding as show in the documentation).
Parameter autoupdate=“false” works as you expected, thanks! Switch is going to “off” again after pressing.
(I only had to install the RegEx-Transformation, this is needed for this parameter (?!))
My other question (push-button with 4 selections to start 4 different scripts) is still waiting for help (maybe you have later an ideo), or others …