OpenHAB CULfw for Somfy RTS Rollershutters

hi @black0r1337,

it should be reachable via the marketplace. However it is tagged as Alpha and thus you probably have to change the configuration of the marketplace settings: https://www.openhab.org/docs/configuration/eclipseiotmarket.html#configuration

And maybe I should come up with a plan to further develop and/or integrate it directly into OpenHAB. Because it is currently in the state “Works for me”. But if there are any questions don’t hesitate to ask.

Cheers
Daniel

Hi Daniel,

I was working on some other aspects with OpenHAB in the last months, but wanted to finish the Somfy issue now. However, it is not working. I have placed a question regarding JAVA already at stackoverflow, but didn’t receive any reply yet. I have also removed your name from the project in order to fulfil DSGV :slight_smile:
I was starting by installing oracla JAVA and have checked out the SomfyCUL test code from here:
Testcode for simple tests: https://github.com/weisserd/serial-cul-test
I have than compiled it with maven and this went well eventually (after some training). But now I get this error message:

mvn exec:java -Dexec.mainClass=de.saltest.home.SomfyCULTest


[INFO] --- exec-maven-plugin:1.6.0:java (default-cli) @ serialTest ---
Okt 07, 2018 3:25:41 PM de.saltest.home.SomfyCULTest main
INFORMATION: Opening port ttyUSB0
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
        at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
        at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
        at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
        at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:85)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:104)
        at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
        at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
        at de.saltest.home.SomfyCULTest.main(SomfyCULTest.java:24)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
        at java.lang.Thread.run(Thread.java:748)
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver

jrxtx is installed:

dpkg-query -L librxtx-java
/usr/lib/jni/librxtxRS485.so
/usr/lib/jni/librxtxRaw.so
/usr/lib/jni/librxtxI2C.so
/usr/lib/jni/librxtxParallel.so
/usr/lib/jni/librxtxSerial.so
/usr/share/java/RXTXcomm.jar

Do you have an idea what could be the problem here? I guess it is just a small issue, but I’m lost now…
Thanks again,

Ben

Hi Ben,

did you try to add the native path of the library as start parameter:

-Djava.library.path=/usr/lib/jni

And for starting the application I suggest not using mvn.

Cheers
Daniel

Hi Daniel,
yes I tried this already. Also I have copied the libraries directly to the same folders, etc. The error message is like this:

java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar ./target/serialTest-0.0.1-SNAPSHOT.jar

Okt 07, 2018 3:30:42 PM de.saltest.home.SomfyCULTest main
INFORMATION: Opening port ttyUSB0
Exception in thread "main" java.lang.NoClassDefFoundError: org/openmuc/jrxtx/SerialPortBuilder
        at de.saltest.home.SomfyCULTest.main(SomfyCULTest.java:24)
Caused by: java.lang.ClassNotFoundException: org.openmuc.jrxtx.SerialPortBuilder
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 1 more

Another thing, if I try to compile using javac I get also an error:

javac -classpath /usr/lib/jni -cp /usr/share/java/RXTXcomm.jar:. src/main/java/de/saltest/home/SomfyCULTest.java
src/main/java/de/saltest/home/SomfyCULTest.java:7: error: package org.openmuc.jrxtx does not exist
import org.openmuc.jrxtx.Parity;
                        ^

Any more ideas?
Thanks!
BR,
Ben

Hi Ben,

sure I do have more ideas :wink:

I would do the build with Maven and build a JAR with all dependencies included. (https://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/) So you shouldn’t run into compile and packaging problems. Manually compiling produces more issues/problems when trying to find the right dependencies/libs.

As a result when starting (with java ...) the error concerning class not found should hopefully not arise and there is no need for an additional entry in the classpath.

Cheers
Daniel

Hi Daniel,
still no success, I’m getting more or less the same error:

 java -jar ./target/serialTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Okt 09, 2018 11:36:34 PM de.danielweisser.home.SomfyCULTest main
INFORMATION: Opening port ttyUSB0
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
        at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
        at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
        at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
        at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:85)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:104)
        at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
        at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
        at de.danielweisser.home.SomfyCULTest.main(SomfyCULTest.java:24)
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Could not load lib from jar and from system.
gnu.io.LibLoadException: directory does not exist /libs
        at gnu.io.LibraryLoader.loadLib(LibraryLoader.java:65)
        at gnu.io.LibraryLoader.loadLibsFromJar(LibraryLoader.java:48)
        at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:29)
        at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:118)
        at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
        at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
        at de.danielweisser.home.SomfyCULTest.main(SomfyCULTest.java:24)
Exception in thread "main" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
        at java.lang.Runtime.loadLibrary0(Runtime.java:870)
        at java.lang.System.loadLibrary(System.java:1122)
        at gnu.io.LibraryLoader.loadRxtxNative(LibraryLoader.java:32)
        at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:118)
        at org.openmuc.jrxtx.JRxTxPort.openSerialPort(JRxTxPort.java:50)
        at org.openmuc.jrxtx.SerialPortBuilder.build(SerialPortBuilder.java:166)
        at de.danielweisser.home.SomfyCULTest.main(SomfyCULTest.java:24)

However, it seems that the necessary libraries are packed into the jar:

jar tf target/serialTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar
META-INF/
META-INF/MANIFEST.MF
gnu/
gnu/io/
gnu/io/CommDriver.class
gnu/io/CommPort.class
gnu/io/CommPortEnum.class
gnu/io/CommPortEnumerator.class
gnu/io/CommPortException.class
gnu/io/CommPortIdentifier.class
gnu/io/CommPortOwnershipListener.class
gnu/io/Configure$1.class
gnu/io/Configure$2.class
gnu/io/Configure$3.class
gnu/io/Configure$4.class
gnu/io/Configure.class
gnu/io/I2C$I2CInputStream.class
gnu/io/I2C$I2COutputStream.class
gnu/io/I2C$MonitorThread.class
gnu/io/I2C.class
gnu/io/I2CPort.class
gnu/io/I2CPortEvent.class
gnu/io/I2CPortEventListener.class
gnu/io/LPRPort$MonitorThread.class
gnu/io/LPRPort$ParallelInputStream.class
gnu/io/LPRPort$ParallelOutputStream.class
gnu/io/LPRPort.class
gnu/io/LibLoadException.class
gnu/io/LibraryLoader.class
gnu/io/NoSuchPortException.class
gnu/io/ParallelPort.class
gnu/io/ParallelPortEvent.class
gnu/io/ParallelPortEventListener.class
gnu/io/PortInUseException.class
gnu/io/RS485$MonitorThread.class
gnu/io/RS485$RS485InputStream.class
gnu/io/RS485$RS485OutputStream.class
gnu/io/RS485.class
gnu/io/RS485Port.class
gnu/io/RS485PortEvent.class
gnu/io/RS485PortEventListener.class
gnu/io/RXTXCommDriver.class
gnu/io/RXTXPort$MonitorThread.class
gnu/io/RXTXPort$SerialInputStream.class
gnu/io/RXTXPort$SerialOutputStream.class
gnu/io/RXTXPort.class
gnu/io/RXTXVersion.class
gnu/io/Raw$MonitorThread.class
gnu/io/Raw$RawInputStream.class
gnu/io/Raw$RawOutputStream.class
gnu/io/Raw.class
gnu/io/RawPort.class
gnu/io/RawPortEvent.class
gnu/io/RawPortEventListener.class
gnu/io/SerialPort.class
gnu/io/SerialPortEvent.class
gnu/io/SerialPortEventListener.class
gnu/io/UnSupportedLoggerException.class
gnu/io/UnsupportedCommOperationException.class
gnu/io/Zystem.class
gnu/io/package-info.class
org/
org/openmuc/
org/openmuc/jrxtx/
org/openmuc/jrxtx/DataBits.class
org/openmuc/jrxtx/FlowControl.class
org/openmuc/jrxtx/JRxTxPort$1.class
org/openmuc/jrxtx/JRxTxPort$SerialInputStream.class
org/openmuc/jrxtx/JRxTxPort$SerialOutputStream.class
org/openmuc/jrxtx/JRxTxPort.class
org/openmuc/jrxtx/Parity.class
org/openmuc/jrxtx/PortNotFoundException.class
org/openmuc/jrxtx/SerialPort.class
org/openmuc/jrxtx/SerialPortBuilder.class
org/openmuc/jrxtx/SerialPortException.class
org/openmuc/jrxtx/SerialPortTimeoutException.class
org/openmuc/jrxtx/StopBits.class
de/
de/danielweisser/
de/danielweisser/home/
META-INF/maven/
META-INF/maven/de.danielweisser/
META-INF/maven/de.danielweisser/serialTest/
de/danielweisser/home/SomfyCULTest.class
META-INF/maven/de.danielweisser/serialTest/pom.xml
META-INF/maven/de.danielweisser/serialTest/pom.properties

Am I right? Or do I miss something?
Cheers,
Ben

Sorry, I was a little fast. If I use the library path option and the full JAR it seems to work:

java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar -jar ./target/serialTest-0.0.1-SNAPSHOT-jar-with-dependencies.jar
Okt 09, 2018 11:43:40 PM de.danielweisser.home.SomfyCULTest main
INFORMATION: Opening port ttyUSB0
Okt 09, 2018 11:43:40 PM de.danielweisser.home.SomfyCULTest main
INFORMATION: Closed port

I’m going to test more now and keep you posted how it works.
Thanks so far.
Best,
Ben

Hi Ben,

good to hear that you’re making progress.

Cheers
Daniel

Hi Daniel,
I think I have an idea what could be the issue with the binding. I have tried the java test code and it works. However, it does only work at 38400 baud. With 9600 it is not reacting at all. I was looking at the source code and was realizing that the transfer speed to the CUL is hardcoded at 9600 baud, The question now is how I can compile the binding by myself (changing the sources) or would it be possible to make the transfer speed a pararmeter? What do do you think what be the best approach?

In the meantime I did try to compile the binding myself. I’ve chosen the maven approach, but had some difficulties to compile your forked branch with the somfycul binding. so I did checked out the original master branch of openhab-addons and deleted .m2 first in my raspi home folder and compiled just an arbitrary single binding using:

mvn clean install

however, the same approach did not work with somfycul and resultet in the following error message:

[ERROR] Internal error: java.lang.RuntimeException: Invalid repository URL: http://download.eclipse.org/smarthome/updates-release/${esh.releaseVersion}: Illeg                                                                                                al character in path at index 55: http://download.eclipse.org/smarthome/updates-release/${esh.releaseVersion} -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: Invalid repository URL: http://download.eclipse.org/smarthome/updates-rel                                                                                                ease/${esh.releaseVersion}
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:121)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

I assume you’re using eclipse to do the compilation? Do you have an idea, why compilation fails with maven on the raspberry?

Thanks and BR,
Ben

Hi Ben,

the best approach would be to take the Somfy binding and enhance it (add config parameters, improve documentation, add tests) and bring it to a state where the integration into the main OpenHAB distribution is possible.

For my setup I take the code, compile it via my Linux (Ubuntu-based) machine via Maven and then put it to the raspi (by shell and by the Eclipse marketplace for tests).

The error in your command seems to be that the variable ${esh.releaseVersion} is not properly resolved.

Cheers
Daniel

Finally, I was successful. The shadow blinds are working now in openHAB. This is what I did directly on my RPi:

  • checking out the original openhab-addons sources from github
  • changing into the binding folder
  • execute the skeleton script to create an empty binding (with the very same name and author as the somfycul binding)
  • compare the sources of the original somfycul binding with the empty one and copy the relevant parts to the skeleton files
  • change the baud rate in the sources to 38400
  • compile the single binding with:
mvn clean install
  • copy the successfully compiled jar file from target folder to addons folder in openHAB
  • optional: clear the cache (for me it was not working without clearing, but afterwards it worked instantly)

thats it :slight_smile:

Now im looking for a possibility to make sure that all three of my USB sticks are always getting the same tty* after reboot. Usually it works, but not always.

Thanks for the support and for developing the binding sources!

Cheers,
Ben

1 Like

Hi Ben,

the solution for your tty* problem can be found at https://wiki.siduction.de/index.php?title=Symlink_zur_eindeutigen_Erkennung_mittels_udev-Regel

Cheers
Daniel

Hi Daniel,
thanks, this worked! However, I had to add the new ports in /etc/default/openhab2 otherwise 2 of 3 were not recognized.

Cheers,
Ben

@bahrenholz - are you willing to share the JAR of your recompiled version? I’ve not got a development environment that’s recompiling it yet, and have the same problem with baud rate.

Hi, I did send it via email, but I’m not sure if it came through. GMail is denying transportation of such files anyways.

@bahrenholz
Hi, I would be also interested in the updated JAR with baud 38400. Is placing it in the addons folder enough or do I have to uninstall the addon from the marketplace first?

thanks,
Christoph

Hi,

I have uploaded it to dropbox. I hope this is ok for Daniel :slight_smile:

https://www.dropbox.com/s/sm6bn8m4v956656/org.openhab.binding.somfycul-2.4.0-SNAPSHOT.jar?dl=0

You should uninstall the marketplace binding and just copy it to the addons folder. Good luck and best.

My solution to the baud rate problem was to edit CULfw configuration before compiling, and downloading to the nanoCUL.
Edit board.h file in the Devices/nanoCUL directory:
Find #define UART_BAUD_RATE and edit it to 9600. Then compile and download:
make program

Now it perfectly works with the openHAB addon!

Trying to get this running… Openhab 2.5M5.

I have a CUL USB Stick, placed the jar in /usr/share/openhab2/addons (raspianpi).
In discovery, I added a culDeviceLabel and set port /dev/ttyUSB1 (saw it in logs). The things say that it is online. Is there any way I could check if it is really working?
image

I then tried to add a somfyDeviceLabel with channels.
image

Now I tried to learn it.

I pressed “prog” on working RTS remote (rollershutters are moving), then “programChannelLabel” in paper UI.
Nothing happens, no log entries.

Update: I followed OpenHAB CULfw for Somfy RTS Rollershutters (added things, added items, added items to sitemap).

Switch klappladenBueroProg    "Somfy Büro prog"  (somfyFF) {channel="somfycul:somfydevice:buero:program"}
Rollershutter klappladenBuero  "Somfy Büro"  (somfyFF) {channel="somfycul:somfydevice:buero:position"} 

I pressed “prog” on working RTS remote (rollershutters are moving), then the klappladenBueroProg.
I hear a double beep, which I think confirms that programming did work.

But when I try to send the position, nothing happens.
Here what I see in the log:

2019-11-21 19:46:29.647 [INFO ] [ing.somfycul.handler.SomfyCULHandler] - channelUID: somfycul:somfydevice:esslinks:position, command: UP

2019-11-21 19:46:29.655 [DEBUG] [ing.somfycul.handler.SomfyCULHandler] - rolling code before command null

2019-11-21 19:46:29.662 [INFO ] [.binding.somfycul.handler.CulHandler] - Send message YsA120nullnull for thing somfyDeviceLabel

2019-11-21 19:46:29.669 [DEBUG] [.binding.somfycul.handler.CulHandler] - Trying to write ‘YsA120nullnull’ to serial port /dev/ttyUSB1

2019-11-21 19:46:29.682 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method ‘ThingHandler.handleCommand()’ on ‘org.openhab.binding.somfycul.handler.SomfyCULHandler@bf20a0’: For input string: “null”

java.lang.NumberFormatException: For input string: “null”

at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_222]

at java.lang.Long.parseLong(Long.java:589) ~[?:1.8.0_222]

at java.lang.Long.valueOf(Long.java:776) ~[?:1.8.0_222]

at java.lang.Long.decode(Long.java:928) ~[?:1.8.0_222]

at org.openhab.binding.somfycul.handler.SomfyCULHandler.handleCommand(SomfyCULHandler.java:106) ~[?:?]

at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source) ~[?:?]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]

at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]

at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [bundleFile:?]

at com.sun.proxy.$Proxy415.handleCommand(Unknown Source) [?:?]

at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:74) [bundleFile:?]

at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:48) [bundleFile:?]

at sun.reflect.GeneratedMethodAccessor167.invoke(Unknown Source) ~[?:?]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_222]

at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_222]

at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]

at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_222]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_222]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_222]

at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]

Hi,
from my experience the responsiveness of the stick is very much depending on the fact if baud rate of stick and binding are corresponding. You should verify this either with a windows terminal tool (I did it that way and send commands succesfully to the rollershutter) or somehow else. Usually, if this is working your setup should too.
good luck!

1 Like