KNXD add-on: convert your KNX-USB interface into an IP interface that can be used by HA

I have a USB device, so it cannot be the /dev/ttyACM0. I’ll stop quessing what it was and concentrate on the facts… :smile:

Checked the devices from supervisor -> system:

..
- name: 1-1.4
    sysfs: >-
      /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4
    dev_path: /dev/bus/usb/001/005
    subsystem: usb
    by_id: null
    attributes:
      BUSNUM: '001'
      DEVNAME: /dev/bus/usb/001/005
      DEVNUM: '005'
      DEVPATH: >-
        /devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4
      DEVTYPE: usb_device
      DRIVER: usb
      ID_BUS: usb
      ID_FOR_SEAT: usb-platform-fd500000_pcie-pci-0000_01_00_0-usb-0_1_4
      ID_MODEL: KNX-USB_Interface__MDRC_
      ID_MODEL_ENC: KNX-USB\x20Interface\x20\x28MDRC\x29
      ID_MODEL_ID: '5120'
      ID_PATH: 'platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4'
      ID_PATH_TAG: platform-fd500000_pcie-pci-0000_01_00_0-usb-0_1_4
      ID_REVISION: '0103'
      ID_SERIAL: ABB_STOTZ-KONTAKT_GmbH_KNX-USB_Interface__MDRC_
      ID_USB_INTERFACES: ':030000:'
      ID_VENDOR: ABB_STOTZ-KONTAKT_GmbH
      ID_VENDOR_ENC: ABB\x20STOTZ-KONTAKT\x20GmbH
      ID_VENDOR_ID: 147b
      MAJOR: '189'
      MINOR: '4'
      PRODUCT: 147b/5120/103
      SUBSYSTEM: usb
      TAGS: ':seat:'
      TYPE: 0/0/0
      USEC_INITIALIZED: '1274587164'
..

According to that, the device should be /dev/bus/usb/001/005 I believe.

Still got this when starting the plugin:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 2-init-config: executing... 
[cont-init.d] 2-init-config: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi

No change with or without filters. The same error message came when I started knxd manually per command line. It only worked when I defined usb:2.2.1.0 instead of /dev/usb/002/…

so it can’t deal with the full device path? What happens if you adjust /etc/knxd.ini and replace the full device path in the interface-usb section with 2.2.1.0 ? Also, where does this number come from in your case?

could somebody with these stoi errors please try if the error vanishes when we use libusb-compat instead of libusb in the Dockerfile? (respectively also libusb-compat-dev in the dev dependencies). Just curious if this helps

I checked the knxd.ini file and it looked strange. There were entries for all types of interfaces in it. Should this be like that? The problem is, that even if I change the ini file it gets overwritten with the add-on config. I can’t set the device to 2:3:1:0 there. The number is the combination of bus and device id of the usb device. With this I can start knxd manually in the docker container… but it doesn’t help since it should be started with the add-on config

yes, that is intended. The interface to be loaded is defined in the [main] section, the others will be ignored. This structure allows me to more easily add interface specific options/settings like the timeout without a lot of special case handling in the generating script.

And yes, your config will be overwritten when you restart the add-on, but you don’t have to restart it. Once inside the add-on, fire up top to find the process id (pid) of the s6 service running knxd and then just kill it via kill XXX (where XXX is the pid number). The process will then automatically be restarted and you should see new log output in the add-ons log section in the HA UI

with a HW path like /dev/bus/usb/001/005 shouldn’t the device number then just be 1:5? Why does it have 4 segments in your case?

When I used udevadm monitor it showed me 4 segments.
I’m trying to understand how the usb port is attached.
Where can I see the actual path of the USB device?

bash-5.0# dmesg | grep usb
[ 8116.314536] hid-generic 0003:0E77:0104.0004: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0
[ 8793.572353] hid-generic 0003:0E77:0104.0005: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0
[ 8878.975576] hid-generic 0003:0E77:0104.0006: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0
[ 8954.106221] hid-generic 0003:0E77:0104.0007: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0
[ 9001.333187] hid-generic 0003:0E77:0104.0008: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0
[ 9060.227855] hid-generic 0003:0E77:0104.0009: hiddev96,hidraw1: USB HID v1.01 Device [Lingg & Janke KNX/EIB-USB Interface (DIN rail)] on usb-0000:01:1b.0-2/input0

in case of HID devices the actual path likely is /dev/bus/usb/... - I only have seen an alias for uart/tty devices so far (like the one I have, even though it’s also attached via USB). But you seem to know more about linux than I do, so don’t trust anything I say :wink:

edit: btw - maybe removing usb:true from config.json will help. Not sure though. It’s supposed to pass the raw USB bus into the container so that it can also react on hotpug events etc (from what it says in the HA docs), but maybe it causes issues. Old version didn’t have that, but there I also had to map the USB bus directly into the container via the devices setting, which with the new HW layer of the new supervisor should not be needed anymore according to their devs.

hello,
I’ve a snapshot but the knxd addon is corrupt. then i can’t restore this addon.
but thanks for your response.
excuse me if my english is bad but i’m a french user.

Hello, with 0.4.0, I no longer have the problem I encountered previously. But now I have this:

terminate called after throwing an instance of 'std::invalid_argument'
what(): stoi

Regardless of the device selected, I have this error.
But I don’t know how to make the changes you’re suggesting. I can’t connect to my pi with ssh (putty).
Isn’t it just possible to put back 0.3.6 with alpin 3.12?
Thank you

0.3.6 is not restricted to Alpine 3.12 but uses the “latest stable” version of the add-on base image, which now is based on 3.13. So version 0.3.6 won’t fix the issue. Version 0.4.0 however is now restricted to Alpine 3.12, but there seem to be additional issues now.

ok, so I just read the knxd documentation again and it doesn’t like getting a full device path for USB devices, which kinda explains the error message, as it’s expecting just an integer. So looks like I have to get rid of the device selector again so that users with USB devices can leave that option empty or find a way to “translate” the device path to the int params required by knxd

I just released version 0.4.1 which should address the remaining issue with USB devices.

1 Like

Cool - I will try it out and hopefully it works. Let you know

So I can confirm that your latest changes work and the add-on works again! Many thanks

Hi!
Would it be possible / easier to use USB from an Integration rather than an Addon?

I think it wouldn’t be a huge undertaking to add usb support directly to xknx. If someone is looking for a nice Python project :snake: :wink:
This would also allow non-supervised-users to use USB interfaces.

non-supervised users can run knxd directly on their OS of choice and be done, or, well, buy an IP interface :wink:
There is also a java based tool on the webs that can act as IP interface for USB devices, but who likes java.

1 Like

thanks for confirmation. Spent almost two days now on bug hunting - glad I can finally do some paid work again :wink:

Don’t wanna spoil your weekend, but I still have something here. Have updated to 0.4.1 version and chosen the right device based on the host/hardware information.

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 2-init-config: executing... 
/var/run/s6/etc/cont-init.d/2-init-config: line 39: /dev/bus/usb/: Is a directory
[21:34:48] INFO: Interface:      usb
[21:34:48] INFO: Device:         /dev/bus/usb/001/004
[21:34:48] INFO: Address:        0.0.1
[21:34:48] INFO: Client Address: 0.0.2:8
[21:34:48] INFO: Filters:        
[21:34:48] INFO: Log-Level:      warning
[cont-init.d] 2-init-config: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
E00000049: [16:interface-usb] No reply to setup
F00000105: [15:interface-usb] Link down, terminating

On actual KNX device the USB link led is on, so I would think it should be physically connected.

Ps. Thank you for your work with this addon so far!