Exec binding will not what I want it to do

Hello,

I am struggling with exec binding 2.4
First of all my script is execute able by openhab user and if I am doing

sudo -u openhab bash /docker/config/openhab/conf/scripts/relais_aus.sh

it is switching the ring relais.

This is my config:
Things:

Thing exec:command:tuerklingel_ein         [command="bash /docker/config/openhab/conf/scripts/relais_an.sh", interval=0, autorun=true, timeout=10]
Thing exec:command:tuerklingel_aus        [command="bash /docker/config/openhab/conf/scripts/relais_aus.sh", interval=0, autorun=true, timeout=10]

items:

Switch    Klingel		"Klingel"    <switchtv>		(gGA,gGA_Aussen)
Switch    Klingel_AN_schalten		"Klingel AN"		{ channel="exec:command:tuerklingel_ein:run" 
Switch    Klingel_AUS_schalten		"Klingel AUS"		{ channel="exec:command:tuerklingel_aus:run" }

rule:

rule “Klingel anschalten-ausschalten”
when
Item Klingel changed
then
if (Klingel.state == ON) Klingel_AN_schalten.sendCommand(ON)
else Klingel_AUS_schalten.sendCommand(ON)
end

Please help me, because I tried the whole day to get this running …

Thanks

What are those || characters doing there?

These are copy errors by visual studio I am going to correct the post

No ideas where my mistake can be?

Usually permissions with exec.
What do events.log and openhab.log tell you?

Have tried to use the absolute path in your Thing. I do it in this way:

Thing exec:command:cpu_temp "OH2-PI Temperatur" @ "Kinderzimmer" 
                    [command="/bin/bash /etc/openhab2/scripts/cpu_temp.sh", interval=120, timeout=30, transform="REGEX((.*?))"]

Does it help ?

no unfortunately not

This is events log
2019-07-16 21:45:53.651 [ome.event.ItemCommandEvent] - Item ‘Klingel’ received command ON
2019-07-16 21:45:53.657 [vent.ItemStateChangedEvent] - Klingel changed from OFF to ON
2019-07-16 21:45:53.660 [ome.event.ItemCommandEvent] - Item ‘Klingel_AN_schalten’ received command ON
2019-07-16 21:45:53.661 [nt.ItemStatePredictedEvent] - Klingel_AN_schalten predicted to become ON
2019-07-16 21:45:53.665 [vent.ItemStateChangedEvent] - Klingel_AN_schalten changed from OFF to ON
2019-07-16 21:45:53.680 [vent.ItemStateChangedEvent] - Klingel_AN_schalten changed from ON to OFF

Why is it switching twice?

Because of autoupdate, the source of the ‘prediction’. You can disable that for this Item just to avoid the nuisance logging.

Anything in openhab.log ?

only my loging
2019-07-16 21:43:05.141 [INFO ] [home.model.script.KLINGEL RULE] - ANOFF
2019-07-16 21:43:05.142 [INFO ] [home.model.script.KLINGEL RULE] - AN - IF erfüllt
2019-07-16 21:43:05.146 [INFO ] [home.model.script.KLINGEL RULE] - AN - nach Kommando
2019-07-16 21:43:57.288 [INFO ] [home.model.script.KLINGEL RULE] - ANON

Are you running openHAB in a docker container? If so, are you executing the command above inside the container or outside the container?

If the answer to the first question is ‘yes’, and the answer to the second question is ‘outside’ then try the following things file:

Thing exec:command:tuerklingel_ein        [command="bash /openhab/conf/scripts/relais_an.sh", interval=0, autorun=true, timeout=10]
Thing exec:command:tuerklingel_aus        [command="bash /openhab/conf/scripts/relais_aus.sh", interval=0, autorun=true, timeout=10]
1 Like

You are so close to the point.
My container is now able to switch the relais by using ssh but the openhab switch isn’t.

I have to check the rule again, I guess.

But many thanks for pushing into right direction

How about changing the rule to use exec action, instead of binding. This allows you to get results info. (Once its sorted out you can go back to using binding)

rule "Klingel anschalten-ausschalten"
when
   Item Klingel changed
then
   var execresult = "timed out"
   if (Klingel.state == ON) {  
      execresult = executeCommandLine( "bash /docker/config/openhab/conf/scripts/relais_an.sh",  3000)
   } else {
      execresult = executeCommandLine( "bash /docker/config/openhab/conf/scripts/relais_aus.sh",  3000)
   }
   logInfo("test". "result: " + execresult
end

Sorry for the long time of not answering but some more important issues happened.

I tried it and it brought me to a new error which I am not able to solve.

If I am running the script within the container as root
it is looking for key files in this directory:
Found key in /root/.ssh/known_hosts:1

But if I am running the script via button from openhab panel:
debug1: Trying private key: /openhab/.ssh/id_rsa
debug1: Trying private key: /openhab/.ssh/id_dsa
debug1: Trying private key: /openhab/.ssh/id_ecdsa
debug1: Trying private key: /openhab/.ssh/id_ed25519
debug1: Next authentication method: password
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.

ssh command is identically, because the file is passed to the container

docker host and container are having user openhab AND in both home dir is a .ssh folder
permissions are ok and for openhab user …

quite strange …

I’ve no idea what any of that means, it does not come from exec binding.

I found the solution.

It is written in the ssh debug …

The files id_rsa* files have to be in /openhab/.ssh directory not in /home/openhab …

Now it is running.

Sometimes it is helping to talk about :slight_smile: