Well … that’s good … finally there’s a reason to document the whole stuff because someone is interested.
**Optional: Device symlink **
First of all my openhab runs on a Debian Linux system. You have to make sure, that the USB key is recognized by the system (e.g. dmesg) or lsusb.
Because the device name of the USB key must be hardcoded in the openhab application I make sure, that a generic symlink is created for the /dev/ttyUSB device, which is used by openhab. Example:
$ ls /dev/ttyUSB -la
crw-rw-rw- 1 root dialout 188, 0 Jan 10 06:26 /dev/ttyUSB0
lrwxrwxrwx 1 root root 7 Dec 8 15:55 /dev/ttyUSB_selve -> ttyUSB0
So in my case I tell openhab to use the device /dev/ttyUSB_selve. For most Debian systems this can be acomplished using an udev rule. I created a new file:
/etc/udev/rules.d/10-USBSelve_TTY.rules
SUBSYSTEM==“tty”, ATTRS{idVendor}==“0403”, ATTRS{idProduct}==“6015”, ATTRS{serial}==“DM00B3ZB”, ATTRS{product}==“FT230X Basic UART”, SYMLINK+=“ttyUSB_selve”, GROUP=“dialout”, MODE=“0666”
You have to edit the idVendor, idProduct, product and serial attribute. The values can be obtained by the dmesg output when plugging in the key. An alternative is:
udevadm info --name=/dev/ttyUSB --attribute-walk
**Basic config (Linux): **
In the file “/etc/default/openhab2” I had to add the serial port to the JAVA_OPTS variable by adding the line (section JAVA OPTIONS for good documentation)
EXTRA_JAVA_OPTS=“-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB_selve”
==> Openhab needs to be restarted now
Items file (/etc/openhab2/items/selve.items)
Example for one rollershutter:
Rollershutter rollershutter_selve_living_state { serial="/dev/ttyUSB_selve@115200,UP(<methodCall><methodName>selve.GW.iveo.commandManual</methodName><array><base64>AQAAAAAAAAA=</base64><int>1</int></array></methodCall>),DOWN(<methodCall><methodName>selve.GW.iveo.commandManual</methodName><array><base64>AQAAAAAAAAA=</base64><int>2</int></array></methodCall>),STOP(<methodCall><methodName>selve.GW.iveo.commandManual</methodName><array><base64>AQAAAAAAAAA=</base64><int>0</int></array></methodCall>)"}
Basically the base64 string (example above AQAAAAAAAAA=) controls which rollershutter to use. This is documented in the Selve XML API documentation.
In very short:
Per rollershutter you assign a channel in the USB RF gateway. More or less this is the same as when you program a selve remote control. I won’t go into details here, because this is not an openhab specific issue. This is all selve black magic. Read the selve documentation for this
One little hint: What helps is the XML API Windows Tool from selve to debug the whole stuff. (SELVE | Your partner for everything to do with roller shutters & sun protection)
Back to the Base64 string:
The channel ID mask is 8 Byte long. Each bit of represents one channel ID. If the bit in the mask is set to “1” to corresponding channel is used for the operation.
Now the brainf*** begins. First of all you need to determine the right bit for the corresponding channel. As documented in the XML API of selve here are some examples for the mask:
Byte 0.0 IveoID 0
Byte 0.7 IveoID 7
Byte 1.0 IveoID 8
Byte 7.7 IveoID 63
Now… how to get the base64 string for one (or a set of IDs)? Examples:
Channel 1 (Mask address Byte block index 0 / first bit [least significant])
Hex: 01 00 00 00 00 00 00 00
Bin: 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Base64: AQAAAAAAAAA=
Channel 2 (Mask address Byte block index 0 / second bit [least significant])
Hex: 02 00 00 00 00 00 00 00
Bin: 00000010 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Base64: AgAAAAAAAAA=
Channel 3 (Mask address Byte block index 0 / third bit [least significant])
Hex: 04 00 00 00 00 00 00 00
Bin: 00000100 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Base64: BAAAAAAAAAA=
[…]
Channel 11 (Mask address Byte block index 1 / third bit [least significant])
Hex: 00 04 00 00 00 00 00 00
Bin: 00000000 00000100 00000000 00000000 00000000 00000000 00000000 00000000
Base64: AAQAAAAAAAA=
Of course you can control multiple channels at the same time.
Example Channel 1 and 2
Hex: 03 00 00 00 00 00 00 00
Bin: 00000011 00000000 00000000 00000000 00000000 00000000 00000000 00000000
Base64: AwAAAAAAAAA=
Hex to Base64 conversion: Base64 to hex: Encode and decode bytes online - cryptii
Again - please read and understand the XML API and the USB key itself! 