executeCommandLine simple OH3

Hi,

I’m very new to openhab and I don’t have a lot of experience with programming in general. I picked openHAB to be able to run a simple RF-python script from my RPI. It works very well on a system level but not inside of openhab. I’ve read through the documentation and spent several days trying to wrap my head around both the execbinding and the executeCommandLine within rules. I made a simple rule trying just to run it and see if the command is getting executed at all but no luck there. Things I’ve checked:

Running the command on system level as openhab user. (Works)
added the command in the whitelist
added NOPASSWD for openhab user
Made a sh script running the python scripts instead of running it directly.

Here is my simple rule for checking if the command even gets through:

triggers: []
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: HYLLA
      command: executeCommandLine(Duration.ofSeconds(5), "bash",
        "/home/openhabian/test.sh")
    type: core.ItemCommandAction

Maybe I’ve just understood this completely wrong but then i might need some pointing in the right direction.

THX!

This will send the string " executeCommandLine( etc." to an Item named HYLLA.
What type of Item is that, what are you expecting it to do with that text string?

I think there is a bit of muddle here.

You can pre-configure Exec binding things and channels to call scripts, passing parameters derived from Item state as needed. You’d use those by linking channel to Item and, say, commanding the Item ON.,

Or, within the body of a scripted rule, the part where you can add stuff up or make log messages etc., you can ad-hoc use the action executeCommandLine() to call an external script, passing any parameters you can build.
Whitelisting is not required here.

Alright, then I guess I’ve been going in the wrong direction a little bit. I started with the exec binding at first which seemed more appropriate for my needs. Didn’t get that that up and running either though…:

Binding:

UID: exec:command:HYLLA_ON
label: Command
thingTypeUID: exec:command
configuration:
  transform: REGEX((.*))
  interval: 60
  autorun: true
  command: bash /home/openhabian/test.sh
  timeout: 15

I tried adding a run channel to that exec:command:HYLLA_ON:run. Then I set up cell in a test page that sends an on command to that item. The Item gets the command and changes to an ON - state but nothing at all happens with the command.

You configured it to run every 60 secs, you didn’t need to command anything.
If it was successful, you should see your Item linked to the run channel change state each minute. You’d need to look in your events.log for that, because its probably all over in few milliseconds and you won’t see that on a UI.
If you expected some result returned, you’d need tolink a String type Item to the output channel. Always worth doing anyway, as that’s where error messages will end up.

Ah, okey! But then the item state should change between on and off every 60th second?

I added an output item to it but nothing. It’s reporting NULL and I’ve even tried super simple echo commands to get an output but there is nothing.

As you want to run a bash shell script I would suggest to insert a command that creates some output like date and time. Redirect it to a file so that at every execution a new entry is appended:

date >> /tmp/debug.txt

You may add the path to the date executable in front of it to make sure that it is always found.
In case the debug.txt file is never updated your bash is not executed.

Your bash file is located under the user openhabian. Check if the openhab user which OH service runs under has read and execute permission ( although execute should not be required as you execute the batch command ).

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.