OH2 bluetooth with exec binding and Contact

I’m trying to configure OH2 to detect my phone via bluetooth using exec binding. My idea is to use external script to toggle “Contact” when my phone is near by. Here is my config:

Here is my shell script that takes BT mac addres as argument and returns OPEN or CLOSE depending if the phone is near by.

#!/bin/sh
sudo /usr/bin/l2ping -c 1 $1 > /dev/null 2>&1
if [ $? -eq 0 ]
then
        echo OPEN
else
        echo CLOSED
fi

Here is my command definition:

Thing exec:command:l2ping_omadon [command="/etc/openhab2/scripts/l2_ping.sh 1C:1A:C0:1D:46:9F", interval=15, timeout=5]

and here is my items configuration:

Group gMobiles
Contact iphone5s "My iPhone 5S" <apple> (gMobiles) { channel="exec:command:l2ping_omadon:output" }

I can see in the log script is working:

20:58:17.402 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Exec [OUTPUT]: 'OPEN'
20:58:17.410 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Transformed response is 'OPEN'
20:58:37.616 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Exec [OUTPUT]: 'CLOSED'
20:58:37.625 [DEBUG] [hab.binding.exec.handler.ExecHandler] - Transformed response is 'CLOSED'

But the Contact never changes state, it is always NULL:

openhab> smarthome:items | grep iPhone
iphone5s (Type=ContactItem, State=NULL, Label=My iPhone 5S, Category=apple, Groups=[gMobiles])

Am I doing something wrong or exec binding in OH2 just can’t set Contact state?

Thanks

See

For an alternative and already coded solution see:

Hi Rich.

Thanks for the tip. I already made two scripts that are using REST API and MQTT and they are working fine but I was just wandering what I’m doing wrong with exec binding.