Item does not reflect status from exec binding with bash script

I’ve recently started my OpenHAB journey on a RaspberryPi. Although the learning curve is rather steep, I am really enjoying myself getting to know the platform by performing small experiments.

After successfully getting a Sonoff smart-relay (with Tasmota firmware) to work using the MQTT-binding, my next goal is to indicate whether there’s an active OpenVPN client to my OpenVPN server running on the same host. Everything seems to be working, but I just cannot get the status of my item on the sitemap updated.

I’m doing this using the exec-binding and two bash scripts.

The first script (“”) is to retrieve the current status from the OpenVPN server:

spawn telnet localhost 7505
set timeout 10
expect "OpenVPN Management Interface"
send "status 3\r"
expect "END"
send "exit\r"

The second script (“”) is invoking the first script with grep to output ‘ON’ or ‘OFF’ depending on the presence of a certain OpenVPN client name in the CLIENT_LIST:

/home/pi/./ |grep -q ^CLIENT_LIST.AndroidMotoE
if [ $? -eq 0 ]; then echo 'ON'; else echo 'OFF'; fi

I’ve tested the script, and it correctly reflects the connection status of the client. So far so good!
I’m using the 2nd script with the exec-binding to define a thing (’/things/VPNUserOnline.things’) :

Thing exec:command:vpnstatus [command="/home/pi/", interval=60, timeout=5]

And finally, I’m using this thing to indicate the status with an item (‘vpn.items’):

Switch vpnStatusSwitch "VPN User Status " <switch> { channel="exec:command:vpnstatus:output" }

At first the log showed that I was missing the REGEX transformation. After installing this using the PaperUI, I got no further messages. Raising the log level for the exec binding to DEBUG reveals the following message every 60s (which is expected from the configuration:

18:21:40.192 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Exec [OUTPUT]: 'OFF'
18:21:40.207 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Transformed response is 'OFF'

Similarly, when logged in to my OpenVPN server, the DEBUG info shows:

18:29:41.233 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Exec [OUTPUT]: 'ON'
18:29:41.249 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Transformed response is 'ON'

This tells me that the bash scripts and the exec-binding are working, but somehow the status of the item vpnStatusSwitch is not updated. When listing the items using the Karaf console, it also tells me that the status isn’t updated at all, since it is uninitialized:

vpnStatusSwitch (Type=SwitchItem, State=NULL, Label=VPN User Status , Category=switch)

Apologies for the long story, but does anybody have a clue why the binding seems to be working fine, but my item isn’t being updated?

Dear community, I’m still struggling with the issue as described in my previous post.

Is my question clear? Do I need provide other/more information?

Your feedback is appreciated; I’d really like to get this setup to work!

Allright, I’ve taken another angle at this problem, since the switch item just doesn’t seem to cope with the input from the script.

I’ve changed the type from the item now from Switch to String, just to see if the link between the Item and Thing is actually working:

String vpnStatusString "VPN user: [MAP(]" <network> { channel="exec:command:vpnstatus:output" }

And now it actually updates the information from the script, through my Thing to the String item as defined above. Since I wanted to use the dynamic icons, I’ve left the ‘ON’ and ‘OFF’ output of the script as it is, and added the icon to my item. Works well!

However, I wanted the textual description to be ‘online’ and ‘offline’ instead, so I made a mapping (/transform/‘’) as follows:


This also does the job, but somehow screws up the dynamic icon, which is based on ‘on’ and ‘off’ states.

Surprisingly, when working on the sitemap, I found that the valuecolor is evaluating yet again the ‘unmapped’ value of the String item. This is how I’m displaying the item on the sitemap:

Text item=vpnStatusString valuecolor=["ON"="green", "OFF"="red"]

So, does anyone have an idea on how to be able to use dynamic icons, with a MAP transformation for the actual text being displayed?

(and still I’d like to understand why all of this isn’t working with a Switch item to begin with)