Have OpenHAB trigger expect scripts? Multiple commands via telnet to change status


I’m hoping to have some suggestions and advice on how to succed controlling some outlets with OpenHAB trough telnet, which requires multiple commands in order to do so. All outlet’s are connected to a centralbox, which i can then control trough telnet or SSH (I’m using telnet for keeping it as simple as possible - the system is going to be local only.)

Currently i have made expect scripts for all outlets to control them, since they require multiple commands.

I have made 2 script’s for each, 1 for ON, 1 for OFF. The system can’t send eventupdates, unless it’s asked for it to do (so it won’t send a message back, if i turn the outlet on manually etc. - only if it’s requested for it’s current status)

In order for me to switch the outlet on, i would telnet and do the following (lowercase is my input, UPPERCASE it’s the system’s reply to each command):

Telnet haus 54001…

'logon user password secret'
'put %devicename% 1'

Since all outlets are hooked up to the centralbox i’m controlling, only the devicename would change, together with the 1 or 0 (for on or off). If i wanted to get the status for the device, i could simply type ‘status %devicename%’ instead. The current status for the outlet’s however doesent really matter to me in this case.

My thought was to have OpenHAB to somehow trigger one of my expect scripts i have to change the outlet’s status.

Do you have any suggestions on how to proceed to have OpenHAB being able to trigger these two expect scripts, 1 for on and 1 for off, or any other solutions perhaps?

The ultimate goal is to have Alexa integrated with OpenHAB, and have Alexa trigger the outlets on/off via OpenHAB.

From the description, it sounds like you could do this with the Exec binding. You didn’t say which version of OH you are using. For OH2, I recommend creating a single script that takes “ON” or “OFF” as an argument (which could invoke one of the two existing scripts).

I’m actually trying to figure out if i can use the Exec binding and how it works. Scrolling the internet trough after examples on how it’s used, and how i should set it up :slight_smile:

The commands needs to be done on the same telnet session, so it won’t be able to have 1 telnet session loggin in, and another setting the command (in case that’s how the exec binding works)

I’m using OH2, freshly installed on a old RPI2, to keep things seperate from other installs untill i have it up and running :slight_smile:

So i tried using the Execbinding. Not really going good for me, also there seems to be two different versions of it requiring different setup?

I went and added a Item:

name: TV
label: TVTest
Type: String

Then i went and added an exec binding command:

In the exec binding, i did:

Name: TVbinding
thingID: TV
Location: Livingroom
Command: /home/pi/test/Single.sh (Script below)
Transform: REGEX((.*))
Interval: 0
timeout: 15

I’m not really sure about the commandpath and what’s transform is for (The path is right, but if it’s typed the way it’s supposed to)

Then i went on and linked Output and Input to the Item ‘TVTest’.

This is my Single script. It works if i call ./Single.sh -INput and ./Single.sh -OUTPUT (It calls one of my two expect scripts for on/off)


case $1 in


Any advice on what i’m missing here?

There’s two versions of many bindings, due to two versions of Openhab. Many 1.x bindings are usable in OH2, to add confusion. Obviously, use the version-appropriate documentation.
Take care when looking at older examples especially, which may not be specific about being for OH1

Have you read the documentation for the binding or just try to use the UI? The documentation describes how to pass the item state to the command arguments. The transform is used for the script output and the default REGEX((.*)) will not do any transformation, which is probably want you want for now.

Keep in mind that the script must be executable by the OH process user which is often not the same as your login user.

I’d recommend to anybody trying to use the Exec binding that they watch their log files closely and even learn how to turn the binding log level to the debug level. Otherwise, you’re not going to get much feedback about why it’s not working. Also, the more details you can give about what’s not working will help others help you solve the problem.

Here’s the OH2 Exec binding documentation: