[SOLVED] Openhab binding te923 needs sudo rights. How to?

Hi,
I have installed a binding called te923 from github. It uses a shellscript to read data from my weather station which is connected to my raspbianpi via usb.

I can run the script manually via ssh, so I see that it works. But I have to run it as sudo.

In the openHAB paper UI, I have added the the binding and the thing successfully, but I cant read any data. The error message is the same that I see when I try to run the script without sudo

error: Unexpected answer from cmd command line: Error while setting configuration (-1). Error while setting configuration (-1). - Size is 1 and should be 22

So i am assuming that I somehow have to give openhab sudo rights? Or change the permissions on the shell script?

Let me add that I am not at all experienced with linux.

You need to change to permission of the shell script and add openhab

sudo chown openhab /your/path/to/script.sh

Thanks, this sounds like what I was searching for. Unfortunately it did not solve my problem.
edit: is it possible that “openhab” is not the right user? How would i find out?

Can you publish your script, please?

Hi, you were able to compile te923 and are able to get data from the te923con right?

Did you tried in a shell

(become root)

sudo su
(Get process of openhab)
ps -edf | grep openhab

The first line should be “openhab” (the running user)

Try to run as openhab user

su openhab --preserve-environment

Try to run a similar command to this one with this user

/home/gabriel/bin/te923tool/te923con
You should get something like
1525764272:23.95:50:i:i:21.80:50:25.30:46:i:i:18.40:62:913.0:i:3:0:i:i:i:i:0

If you are not able to do that my binding will not work.

What do you get?

(Sorry for the lack of support of this plugin, but I haven’t seen many people interested)

You will probably need to grant openhab some permissions.

To give a specific group access to a USB device you have to add a rule to udev in /etc/udev/rules.d/. Add a file called CHOOSEANAME.rules that contains something like this line:

SUBSYSTEM=="usb",ATTRS{idVendor}=="abcd",ATTRS{idProduct}=="1234",MODE="0660",GROUP="mygroup",SYMLINK+="mydevice%n"

Search the web for a detailed tutorial on udev rules and maybe symlinks.

The not preferable way is granting sudo.

https://community.openhab.org/t/openhab-sudo-exec-binding

Thanks to all for your replies.

  • I have verified that the user is ‘openhab’ as described by gabriel.klein
  • I ran the script as ‘openhab’ and I am still getting the error message.
openhab@openHABianPi:/home/openhabian$ sudo /opt/te923/te923con
1525789026:20.40:55:19.10:58:26.10:35:19.60:60:i:i:i:i:1010.5:i:2:0:9:0.8:1.3:30.0:1629
openhab@openHABianPi:/home/openhabian$  /opt/te923/te923con
Error while setting configuration (-1).

I am now trying to understand and follow what Josar posted, but It might take me a while.

I would add a udev rule which adds the device to the dialout group.
as shown above, last post and link.

Then add the user openhab to the dialout group and restart.

sudo adduser openhab dialout

After restart show the groups of the user openhab

sudo -u openhab groups

then try to use the comand as the user openhab like this

sudo -u openhab /opt/te923/te923con

if this works then it should also work from within openhab.

Hello, please use the following approach instead of this binding as it’s cleaner. (I wrote the binding).

Hello,

i have a Problem with TE923 on the Openhab2 Paper UI

Status: OFFLINE - CONFIGURATION_ERROR Unexpected answer from cmd command line: Error while setting configuration (-1). Error while setting configuration (-1). - Size is 1 and should be 22

Putty is ok
[21:09:49] openhabian@RaspberryPi:~$ sudo te923con
[sudo] password for openhabian:
1561318231:23.50:62:20.60:56:i:i:i:i:i:i:i:i:1019.1:i:5:0:3:0.0:0.0:21.1:2336

Please Help
Thank you

The user “openhabian” probably has no access to te923.

(If openhabian is the user running openhab2)