From Domoticz
Jump to: navigation, search

This page strongly overlaps with Assign fixed device name to USB port

If you have multiple USB devices connected, sometimes after a reboot the device order is changed (ttyUSB0 is ttyUSB1, or the other way around). The consequence of this is that Domoticz will have the incorrect devices selected in its setup.

The good news is, that there is a solution for this:

Find IDs of the USB devices

Make sure all the usb devices are plugged in.

Run the following command:

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

and write down the:

*iSerial (if this is zero, you can ignore it)

Or use this command

And search the list


The RFXtrx433 is reported as:

 idVendor           0x0403 Future Technology Devices International, Ltd
 idProduct          0x6001 FT232 USB-Serial (UART) IC
 iProduct                2 RFXtrx433
 iSerial                 3 07VYAR1X

Aeon ZWave USB stick is reported as:

 idVendor           0x10c4 Cygnal Integrated Products, Inc.
 idProduct          0xea60 CP210x UART Bridge / myAVR mySmartUSB light

You need the part behind the '0x'. So you don't have to write down '0x0403' but '0403'. When we deal with hexadecimal numbers, they are written with a 0x in front of them so we don't confuse them with base 10 numbers.

Creating rules file

Create a rules file, with the following example content:

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


Put the following content in the file:

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="123YAOOW", SYMLINK+="ttyUSB-RFX433-A"

SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="123YX78C", SYMLINK+="ttyUSB-RFX433-B"

(Note these values are from my system; put in the values you've written down between the quotes (e.g. replace '0403' with the idVendor of your USB device).

Some devices don't show a serial, you can remove that part in the file, so it looks like this:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="ttyUSB-RFX433"

Names should be ttyUSB-UNIQUENAME so you can easily identify them within Domoticz.

AeoTec Z-Stick

Gen2: SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="ttyUSB-ZStick-2G"

Gen5: SUBSYSTEM=="tty", ATTRS{idVendor}=="0658", ATTRS{idProduct}=="0200", SYMLINK+="ttyUSB-ZStick-5G"

Opentherm Gateway

SUBSYSTEM=="tty", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303",SYMLINK+="ttyUSB-OTG"

P1 smartmeter

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

When you see no device

 sudo mknod /dev/ttyUSB0 c 188 0
 sudo mknod /dev/ttyUSB1 c 188 1

And do the steps again.

Reboot your Raspberry Pi and check results

Restart (sudo reboot) with
sudo shutdown -r now
After the reboot you should have two new serial ports (ttyUSB21 and ttyUSB22), and they will always be assigned to the devices you have configured in the rules file.

To use the new ports, in Domoticz go to the Setup -> Hardware webpage, highlight the RFXtrx433, and in the Serial Port dropdown list select the new Port 'ttyUSB21'.
Then save.

Alternatively, you can reload the udev rules without rebooting by running the following command:
sudo udevadm control --reload
Then disconnect and reconnect the USB device, to see if it works.

Alternative filtering via Devpath

When there is a situation with two or more devices with the same vendor ID and productID and there is no serial number, then you can use the options below to add some other way of filtering. In this case we'll use the dev path, which is the IDs the devices have gotten in the USB hierarchy. The downside of using the devpath is that the devices will always have to stay plugged into the same physical port.

Like above, find the idVendor and idProduct codes by typing lsusb -v. Next, find the devices place in USB hierarchy. You can see this hierarchy by typing:

lsusb -t

This gives an example output of:

Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
  |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/5p, 480M
      |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx, 480M
      |__ Port 2: Dev 4, If 0, Class=Vendor Specific Class, Driver=ch341, 12M
      |__ Port 5: Dev 6, If 0, Class=Vendor Specific Class, Driver=ch341, 12M

The devpath is the port hierachy. So in this specific example, using two cheap Chinese Arduino clones without proper serial numbers on a Raspberry Pi 3, we might add this to the USB Serial Rules file:

SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{devpath}=="1.2", SYMLINK+="ttyUSB-arduino1"
SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{devpath}=="1.5", SYMLINK+="ttyUSB-arduino2"

Alternative filtering via other attributes

Another option to distinguish the devices, is to look for other dissimilarities with the udevadm tool:

udevadm info -a -n /dev/ttyUSBX ..where you should replace the X with a number. You can find that number by typing ls /dev and looking for entries starting with ttyUSB.

Udevadm info starts with the device specified by the devpath and then walks up the chain of parent devices. It prints for every device found, all possible attributes in the udev rules key format. A rule to match, can be composed by the attributes of the device and the attributes from one single parent device.

Now compare the output of both devices and find some non-simulare attributes. Then add a rule based on that to the 99-usb-serial.rules file