[SOLVED] Controlling a command line through exec command

Hello everybody,

So I am using the openhabian on my RPI. I have a multiplexer relay board connected to my computer, as the board is created by the company for internal use, so it is not available to the outside public. However, the board is being controlled by the command line. I have connected my board to my computer through a com port and then I have accessed it serially through putty and I can control it on my computer through the command line there. However, I was hoping I can integrate and control this command line through my openhabian simple GUI. Would it be possible somehow?

I know that I need to install the exec binding, but how can I access this specific command line of this multiplexer board, that is something I would need some ideas on.

Thank you for your attention. All help is greatly appreciated.



Based on my little experience you have a couple of ways to manage it:

First Option: Create an exec command on openhab for every specific command you would use (hard to mantain e fills your openhab of specific exec things)

Second Option: You can create a script that supports arguments so you can manage all the commands you need to use based on the argument passed, then in openhab you can create
a single exec command thing with /path/to/my/script/myscript %2$s
The final part “%2$s” allows openhab to pass arguments.
So you can dynamically call the exec binding with a rule passing the argument you want (or create dummy items/switches to trigger the command you like manually).

ps. if your board already support just one command with arguments you don’t even need to create a script but just use that command.

Hope it helps.


The Exec binding is easy enough to configure in PaperUI.

Have you tried adding a Exec Binding Thing and seeing how you get on?

As long as the permissions are set correctly within your raspberry pi, the command should work.

  • Keep in mind, you / openHAB2 can’t interact with the command once it’s running. (Because there isn’t a TTY console for the openHAB ‘user’)

  • you can send variables to the Thing command by using the input channel and putting %2$s in the command line instruction
    I.E. sh test_script.sh content=%2$s

  • You can’t use sudo to elevate commands because the openHAB2 user is not part of the sudoer group (you can’t enter the password anyway)

  • The output channel will capture the output from the command, so could be used in rules
    I.E. I have a generic TCP command for a multi output ethernet relay board, which returns the current state of every relay channel, regardless of what command is send.
    So a simple rules splits the output to update switch states.

1 Like

It sounds like it’s a serial device connected to the same computer that’s running OH so the Serial binding sounds like it might be appropriate.

1 Like

Hello, Yes, you have recognized the situation. So yes, I have installed the serial binding and I have tried to test it by making the following item:

Switch hostusb “HOST USB” { serial=“COM11@115200,ON(u1),OFF(u0)” }

But it does not really do anything to be honest. Do you think I am doing something wrong? I am SSH-ing in to the openhabian through putty and connecting the board serially to my computer. Just stating it for reference. The COM port is 11 and baudrate which I am using is 115200. And u1 and u0 are the commands to switch between two modes of USB, one is the USB Host, which I switch to by sending u1 as the command in the terminal window and u0 makes it off. This is how I control the board on my pc.

I hope you get the overall picture?

Again, all help is greatly appreciated.

many thanks!


I don’t think it’s clear what is running where. You are talking about com ports which are a Windows only concept. And you are talking about ssh’ing to an openHABian machine through putty which is a Linux machine.

So where is this serial device? If it’s plugged into a Windows machine then it is not plugged into the same machine that openHAB is running on, which was an important stipulation I made in my original reply.

Thanks a lot. That was the problem. I needed to connect my board to the raspberry pi. Now the binding works correctly and I am able to send the commands to the command line.


1 Like