Bluetooth Ping

Tags: #<Tag:0x00007f617351efd8> #<Tag:0x00007f617351ef10>

Hello,

I am currently working on getting the presence detection via bluetooth ping to work. I used this tutorial: https://klenzel.de/3328

I’ve got /scripts/bt.sh with this code:

#!/bin/bash
 
#1=Tobias, 2=Theres
case $1 in
   1) MAC="60:F4:45:XX:XX:XX" ;;
   2) MAC="11:22:33:XX:XX:XX" ;;
esac
 
if /usr/bin/l2ping -c 1 $MAC &> /dev/null
   then
      echo "ON"
   else
      echo "OFF"
fi

when I am using the raspberry console it is working pretty well:

[12:04:39] openhabian@openHABianPi:~$ sudo ./scripts/bt.sh 1
ON

The problem is that it is not working when I am using the same command via user openhab:

[12:09:06] openhabian@openHABianPi:~$ sudo -u openhab ./scripts/bt.sh 1
OFF

I already edited the visudo, as you can see here:

[12:11:15] openhabian@openHABianPi:~$ sudo -u openhab sudo -l
Matching Defaults entries for openhab on openHABianPi:
env_reset, mail_badpass, secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
User openhab may run the following commands on openHABianPi:
(ALL) NOPASSWD: ALL

I think that the problem is l2ping. As sudo it is working well, but it is not as user openhab.
I just have no idea how to change this, as giving openhab complete sudo rights (I know that I should restrict them later on), did not change anything.

Does anyone have an idea?

As far as I remember, the key to get it working was in in this comment. (Note that there is a typo in the suggestion for the sudoers file; it has to be usr not usb). And your user openHAB has to be in the group „dialout“

Ah, for some reason I missed " /usr/bin/sudo"… After adding it, it works great now. Thanks a lot!