How to make symlinks for usb ports in linux (EXTRA_JAVA_OPTS)

Because I did not find a fully working tutorial myself. I am writing this tutorial how I succeeded.

SSH in to openHABian.
Unplug all usb devices.
And run the command.

sudo lsusb -v | grep 'idVendor\|idProduct\|iProduct\|iSerial'
[17:27:23] openhabian@openhabian-server:~$ sudo lsusb -v | grep 'idVendor\|idProduct\|iProduct\|iSerial'
[sudo] password for openhabian: 
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0003 3.0 root hub
  iProduct                2 xHCI Host Controller
  iSerial                 1 0000:00:15.0
  idVendor           0x0403 Future Technology Devices International, Ltd
  idProduct          0x6001 FT232 USB-Serial (UART) IC
  iProduct                2 RFXtrx433
  iSerial                 3 A11HEJ4V
  idVendor           0x0403 Future Technology Devices International, Ltd
  idProduct          0x6001 FT232 USB-Serial (UART) IC
  iProduct                2 FT232R USB UART
  iSerial                 3 AK061I02
  idVendor           0x0bda Realtek Semiconductor Corp.
  idProduct          0x0129 RTS5129 Card Reader Controller
  iProduct                2 USB2.0-CRW
  iSerial                 3 20100201396000000
  idVendor           0x1d6b Linux Foundation
  idProduct          0x0002 2.0 root hub
  iProduct                2 xHCI Host Controller
  iSerial                 1 0000:00:15.0

Plug in 1 usb devices and run the command again

sudo lsusb -v | grep 'idVendor\|idProduct\|iProduct\|iSerial'

See which device was added and take a note of idVendor,idProduct,iSerial
With idVendor and idProduct only take a note of the numbers after the x.
Do so with all your usb devices.

Create a UDEV Rule with the command.

sudo nano /etc/udev/rules.d/99-usb-serial.rules

Change the idVendor,idProduct,iSerial to your configuration and put a unique symlink name.

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="AK061I02", SYMLINK+="ttyUSB-RS485"

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A11HEJ4V", SYMLINK+="ttyUSB-RFXcom"

Run the command to add EXTRA_JAVA_OPTS

sudo nano /etc/default/openhab2

With openHAB3 use

sudo nano /etc/default/openhab

Add te next rule and change the config with your unique symlink name.

## Additional options for the JAVA_OPTS environment variable.
## These will be appended to the execution of the openHAB Java runtime in front of all other options.
## A couple of independent examples:

##   EXTRA_JAVA_OPTS="-Djna.library.path=/lib/arm-linux-gnueabihf/ -Duser.timezone=Europe/Berlin"


Add openhab user to the right groups with the following commands

sudo adduser openhab dialout
sudo adduser openhab tty

Reboot and look if the symlinks are created with te following command.

ls /dev/tty*

In the output your unique symlink name should be visible.

[18:54:59] openhabian@openhabian-server:~$ ls /dev/tty*
/dev/tty    /dev/tty17  /dev/tty26  /dev/tty35  /dev/tty44  /dev/tty53  /dev/tty62      /dev/ttyS12  /dev/ttyS21  /dev/ttyS30   /dev/ttyUSB-RFXcom
/dev/tty0   /dev/tty18  /dev/tty27  /dev/tty36  /dev/tty45  /dev/tty54  /dev/tty63      /dev/ttyS13  /dev/ttyS22  /dev/ttyS31   /dev/ttyUSB-RS485
/dev/tty1   /dev/tty19  /dev/tty28  /dev/tty37  /dev/tty46  /dev/tty55  /dev/tty7       /dev/ttyS14  /dev/ttyS23  /dev/ttyS4
/dev/tty10  /dev/tty2   /dev/tty29  /dev/tty38  /dev/tty47  /dev/tty56  /dev/tty8       /dev/ttyS15  /dev/ttyS24  /dev/ttyS5
/dev/tty11  /dev/tty20  /dev/tty3   /dev/tty39  /dev/tty48  /dev/tty57  /dev/tty9       /dev/ttyS16  /dev/ttyS25  /dev/ttyS6
/dev/tty12  /dev/tty21  /dev/tty30  /dev/tty4   /dev/tty49  /dev/tty58  /dev/ttyprintk  /dev/ttyS17  /dev/ttyS26  /dev/ttyS7
/dev/tty13  /dev/tty22  /dev/tty31  /dev/tty40  /dev/tty5   /dev/tty59  /dev/ttyS0      /dev/ttyS18  /dev/ttyS27  /dev/ttyS8
/dev/tty14  /dev/tty23  /dev/tty32  /dev/tty41  /dev/tty50  /dev/tty6   /dev/ttyS1      /dev/ttyS19  /dev/ttyS28  /dev/ttyS9
/dev/tty15  /dev/tty24  /dev/tty33  /dev/tty42  /dev/tty51  /dev/tty60  /dev/ttyS10     /dev/ttyS2   /dev/ttyS29  /dev/ttyUSB0
/dev/tty16  /dev/tty25  /dev/tty34  /dev/tty43  /dev/tty52  /dev/tty61  /dev/ttyS11     /dev/ttyS20  /dev/ttyS3   /dev/ttyUSB1
[18:55:03] openhabian@openhabian-server:~$ 

Now change your usb devices existing configuration to your new unique symlink name and reboot.


Thanks for this. Working great for my RFXtrx, no more USB lottery on reboot :grinning:

Not sure what to do for my currentcost energy meter though, it has no iSerial value. Any ideas? thanks

  idVendor           0x067b Prolific Technology, Inc.
  idProduct          0x2303 PL2303 Serial Port
  iProduct                2 USB-Serial Controller
  iSerial                 0


Got it working removing the iSerial

SUBSYSTEM==“tty”, ATTRS{idVendor}==“067b”, ATTRS{idProduct}==“2303”, SYMLINK+=“ttyUSB-CC1”

Guess I may just have an issue if I plug in another Prolific PL2303.

In my installation of openhab3, I cannot find ‘/etc/default/openhab’. Is there somewhere else to set the EXTRA_JAVA_OPTS?

also lsusb does not return a serial number for my z-wave stick


What OS do you use ? How did you install OH3 ? Does your installation run in a docker environment ?
All this is required to give better support. As the next statements are based on guessing.
In case it is deb package based I expect the /etc/default/openhab to be there.
You can set the environment variable in any file that is sourced before the startup of OH3 that should be enough but in case it is sourced from a second source this may overwrite the previous value.

Thank you for your prompt response. I installed openhab3 manually on an old Mac mini running Debian 10. I want to know it works for me before I move it to my other machine currently running openhab2. I am having issues with getting my z-wave controller recognized and I am beginning to believe it is an issue with Mac mini/Debian install so I think I will start over on a raspberry pi and see how that goes.

Ran into the same errors with the Raspberry Pi - solved it another way than with symlinks. Thanks

Have a look here openHAB on Linux | openHAB it describes location of files for package based and manual installation.
So the file /etc//default/openhab/ is not preconfigured for manual installations.
You can add/create one.

Usually on manual installations those parameters get added to

1 Like