[Tutorial] openHAB with serial gateway


  • Hero Member

    The support for a baudrate of 115.200, which is used by the MySensor serial gateway, is available since 1.7.0 in the OpenHab serial binding.

    You're able to remove the old version with "apt-get remove ...", no need to replace the files. Just use the installation in /opt.



  • Thanks @TimO. I got everything running in /opt (@9600, but I can change that later), and am receiving humidity/temp stats from my one sensor module running on a nano with DHT22 connected. I need to go through and do some major cleanup now, and also figure out how to convert to from F to C for the temp. It seems like the stock code has provisions for that, however I haven't quite figured out how to enable the change yet.

    Thanks for the help - I look forward to implementing more of these sensors.



  • I am having trouble getting Arduino Nano detected by Raspberry Pi via USB.

    I could see this in the monitor when I selected the correct baudrate:

     0;0;3;0;14;Gateway startup complete.
    
    [151199.509040] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
    [151199.612259] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
    [151199.612296] usb 1-1.2: New USB device strings: Mfr=0, Product=2,
    SerialNumber=0
    [151199.612314] usb 1-1.2: Product: USB2.0-Serial
    [153464.158413] usb 1-1.2: USB disconnect, device number 5
    [153715.311307] usb 1-1.3: new full-speed USB device number 6 using dwc_otg
    [153715.414679] usb 1-1.3: New USB device found, idVendor=1a86, idProduct=7523
    [153715.414717] usb 1-1.3: New USB device strings: Mfr=0, Product=2,
    SerialNumber=0
    [153715.414733] usb 1-1.3: Product: USB2.0-Serial
    

    Initially while flashing serial gateway sketch to nano from Mac I had some trouble to get the right drivers. After following this post it worked fine. Is this to do with chinese knock offs?
    http://kiguino.moos.io/2014/12/31/how-to-use-arduino-nano-mini-pro-with-CH340G-on-mac-osx-yosemite.html

    Also I installed Arduino sketch on Raspberry pi with apt-get install arduino: When I launch Arduino and go to Tools>Port is disabled.

    Is there anything I need to do on RPi so it can detect Arduino Nano knock pff?


  • Hero Member

    I followed the link to the page you mentioned and from there to the chinese page.
    There is a zip-file for linux too, maybe you need to install the driver on the RPi too?

    http://www.wch.cn/download/CH341SER_LINUX_ZIP.html

    Just a guess. 🙂



  • Thanks @TimO .

    I have been trying to make and load that driver but cannot get hands on 3.12.28+ kernel source. It wont compile without it.

    I am wondering how come no body has come accross this issue, I bought my Arduino Nano from one of the links on mysensors store.

    http://www.aliexpress.com/item/1-pcs-for-Nano-V3-0-ATmega328P-Module-Board-Free-Mini-USB-Cable-for-Arduino-Compatible/1397847851.html?aff_platform=aaf&sk=3jYZr3nAE%3A&aff_trace_key=23901740799811215&cpt=1431974332161



  • I don't understand why everybody is using an USB connection for the serial gateway when openHAB is running on a raspberry pi. The pi has a rock stable uart with 3.3V logic. There is no need to convert the arduinos uart to USB. Just connect RX to TX and TX to RX. Connect ground to ground and VCC of the arduino to the 3.3V pin of the pi and you are done. The official openHAB wiki contains instructions on how to use the onboard uart of the pi: https://github.com/openhab/openhab/wiki/Serial-Binding



  • @Jan-Gatzke Thanks for the pointer. I will try that.

    I think the reason is lack of understanding. After reading sea of information I am able to pull together the basic architecture of how this would work.



  • @guzzler I stumbled over the same issue. The FTDI chip on my Nano is correctly recognized as USB device when I attach it to the Raspi. However, when I reboot the Raspi, the device is not there. I need to unplug and replug it.

    That's not normal behaviour of an USB device. And it's quite hindering deploying the Nano as gateway via USB-serial. Maybe it has something to do with automatically performed reset on the Arduino Nano board??

    (The hint about attaching directly to serial is great. Noted for later.)



  • @poeml more precisely, the Nano's FTDI chip connects to the booting Raspberry, but instead of registering a single device there are 4 (!) log lines claiming registering 4 devices (very funny), and none of the devices are bound.

    May 23 23:16:21 bramble kernel: [    3.738087] usb 1-1.5: new full-speed USB device number 5 using dwc_otg
    May 23 23:16:21 bramble kernel: [    4.283520] usb 1-1.5: new full-speed USB device number 6 using dwc_otg
    May 23 23:16:21 bramble kernel: [    4.768136] usb 1-1.5: new full-speed USB device number 7 using dwc_otg
    May 23 23:16:21 bramble kernel: [    5.268161] usb 1-1.5: new full-speed USB device number 8 using dwc_otg
    
    

    I don't find a way to trigger re-registering the device, or power-cycle the USB port, via software. I can only power-cycle the whole USB bridge, which means that the LED goes out (the Ethernet chip is switched off as well...) and LED goes on again, but with the same faulty registering as when booting.

     # cat reset-usb
    #!/bin/bash
    echo 0 > /sys/bus/usb/devices/1-1/authorized
    sleep 1
    echo 1 > /sys/bus/usb/devices/1-1/authorized
    

    Unplugging and replugging always works.

    For the record: Raspberry Pi version 2 with the 4 USB ports, just updated to Debian 8.0 (Jessie). I didn't check with Debian Wheezy if it worked then. The Nano was linked from MySensors store I believe and works great otherwise. I have two of them and both have the same problem (or the Raspi's USB stack has the problem, who knows).



  • Great tutorial! Thank you for putting this together.

    My controller is on RPi, and I'm using a Nano for mySerial gateway with the USB plugged into the RPi. When I specify the port as follows I get the following message

    String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

    org.openhab.model.item.binding.BindingConfigParseException: Could not open serial port /dev/ttyUSB0@115200: Serial port '/dev/ttyUSB0@115200' could not be found. Available ports are:
    /dev/ttyUSB0

    MySensors.h has the following
    #define BAUD_RATE 115200

    I tried taking out @115200, I see openhab.log showing it trying to read garbage and the rules failing. So, I', thinking the garbage is because openhab is not reading it with the right baud rate. However, openhab on the RPi doesn't like /dev/ttyUSB0@115200

    Any ideas anyone?



  • Your Version of openHAB is to old. You need openHAB 1.7 to set the baud rate with @xxxxx. Update openHAB or recompile the gateway sketch with 9600 baud in config.h.


  • Hero Member

    @poeml Just a thought - try connecting the nano to the rpi via a USB hub.



  • @Jan-Gatzke That seemed to work. I'm getting readable data now. Thanks!

    I also set the nodeId to 15 (The above example assumed it was set to 101), as follows in the sensor

    gw.begin(NULL, 15);

    I adjusted the mapping accordingly in the mapping, as specified in the tutorial using 15 instead of 101. The following is now being output from event.log

    2015-05-31 22:18:33 - livingTemp01 state updated to 22



  • Dear all,

    I've stuck. Please help me to understand.
    Currently I have a serial gateway and openHAB 1.7. I've managed to get controller working and send commands to openhab installed on Windows.

    Now I need to understand how to convert commands from the gateway.

    I have a rule

    rule "Arduino sends to Openhab"
        when
            Item Arduino received update
        then
            var String lineBuffer =  Arduino.state.toString.split("\n")
            for (String line : lineBuffer) {
                var String[] message = line.split(";")
                var Integer nodeId = new Integer(message.get(0))
                var Integer childId = new Integer(message.get(1))
                var Integer msgType = new Integer(message.get(2))
                var Integer ack = new Integer(message.get(3))
                var Integer subType = new Integer(message.get(4))
                var String msg = message.get(5)
    			
                if(msgType == 3 ){
                    if (subType == 9){
    					sendCommand(Arduino_Motion1, ON)
    					pushover("Motion Detected", -1)
    		} } }			
    end
    

    items:

    String Arduino "Serial" {serial="COM4@115200"}
    Switch Arduino_Motion1 	"Motion" <siren>
    

    and a sitemap

    sitemap home label="Home"
    {
    
    Frame label="Serial" {
    Switch item=Arduino_Motion1 label="Motion Sensor"
    } } 
    

    So in debug I have following:

    2015-06-01 12:51:29.154 [INFO ] [runtime.busevents             ] - Arduino state updated to 0;0;3;0;9;read: 1-1-0 s=1,c=1,t=16,pt=0,l=1:1
    1;1;1;0;16;1
    
    2015-06-01 12:51:29.156 [INFO ] [runtime.busevents             ] - Arduino_Motion1 received command ON
    

    So I've found an example of temp sensor but not the motion...
    Pushover sends me notifications when motion sensor send 0 to the gateway every minute or so. (0;0;3;0;9;read: 1-1-0 s=1,c=1,t=16,pt=0,l=1:0). I don't understand how can I separate last 0 from 1.
    I know I'm on a last step, please help 🙂

    Thank you!



  • Thanks for help 😉
    Figured out it by myself



  • Would you mind to share the solution?



  • @TimO Hi do you work with Openhab 2.0? I tried to install it and couldnt create a binding, its very hard for me. I need auto Discovery of mysensors with 2.0



  • A 2.0 binding would be great. How far did you get?


  • Hero Member

    Last time I've tested Openhab 2.0 there were some (well known) serious bugs and it still is only an alpha version. An MySensors binding for Openhab would be really cool and I will give it a try, but not for the 1.X Version, because of the lack of autodiscovery mechanisms in Openhab itself and because I think it is a little bit too early for Openhab 2.0.



  • @TimO ok 2.0 alpha...

    An idea for 1.x; Ready-Discovery ?
    We write 250 mysensors items like ID=1-30 for switches, 31-50 for contacts, 51-70 for motion etc... if item is available then sitemap will show them.

    Is there anyway to create rules on frontend? Maybe IFTTT + MySensors goes well..



  • @TimO

    Hi

    Please check this http://forum.mysensors.org/topic/1543/universal-gateway-for-315-433mhz-devices/2

    Is there anyway to use directly 433 with openhab --- serial gateway will be 433 receiver and transmitter (without mysensors lib and devices)



  • hi,
    just wanted to ask if anybody developed l154 work here http://forum.mysensors.org/topic/655/serial-gateway-connection-to-openhab/31? any arduino code for the node point with a few relays and a few sensors?
    thanks!



  • How to I add I_BATTERY_LEVEL to the openhab rules? Being internal I wasnt sure if hashmap would do it.

    Something like this? Where Item is NodeX_Batt

            // Internal Command
            if(msgType == 3){
                if(subType == I_BATTERY_LEVEL){
                        postUpdate("Node" + nodeId + "_Batt, msg)
                        println("Node" + nodeId + "_Batt:" + msg)
                    }}


  • This is a BRILLIANT tutorial. Up and running with a single temp/humidity node in minutes. Thanks so much.

    I built a second node (identical simple DHT22 temp/humidity) and set the Node-id to 110. I'm just wondering how to add the second node into OpenHAB? I have confirmed that openhab is receiving the signals from the second node correctly, but not quite sure about the OpenHAB rules, sitemap and items configs for a second node - that is identical in every way save for the Node ID and different item names. I've simply duplicated all of the code in the relevant config files, changed the item names and added four extra lines to the mapping to map the second 110 node. When I do this I get no data from either of the nodes. If I comment out my changes, I get the values from my first node just fine.

    Can anyone with multiple nodes post a link to their configs so I can see what I might be doing wrong? Cheers.



  • Scratch that...I figured it out. In the rules file, I needed to add a extra comma after the first chunk of mapping. As it stood, I presume it failed to process the whole rule, as there was a syntax error (missing comma) which mean't the 'list' of mappings were incomplete. Added a comma and all was right once again. 🙂



  • Hi guys,

    I'm running in an interesting issue here, posting to see where I'm missing a step.

    I have a Serial Gateway, connected to openHAB and working without issue. I see messages from the arduino Monitor and I can see the messages in openHAB without issue.

    I'm running openHAB on Raspberry PI. arduino connected to PI by USB (on serial port /dev/ttyUSB0) declared as below:

    String itmSensor_gateway_rawmessage 			{ serial="/dev/ttyUSB0@115200" }
    

    The problem that I'm facing is related to the parse process ( I think ).

    Message sent from my node:

    send: 124-124-0-0 s=0,c=1,t=1,pt=7,l=5,sg=0,st=ok:32.0
    

    with this code:
    This is the section of the arduino sketch that I'm using to send the Humidity status:

    float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
          Serial.print("H: ");
          Serial.println(humidity);
          numAttemptsHum = 0;
      }  else {
        Serial.print("Attempt ");
        Serial.print(numAttemptsHum);
        Serial.print("/");
        Serial.print(MAX_NUM_ATTEMPTS_HUM);
        Serial.print(" - Same Humidity level presented");
        Serial.print(" (Previous:");
        Serial.print(lastHum);
        Serial.print(" vs Current: ");
        Serial.print(humidity);
        Serial.println(") - not sending");
        numAttemptsHum ++;
        if ( numAttemptsHum > MAX_NUM_ATTEMPTS_HUM ) {
          lastHum = 0;
          numAttemptsHum = 0;
        }
      }
    

    (it's based on the Humidity & Temp example with minor changes to avoid traffic witout reducing the sampling frequency but with consistent updates based on a specific threshold.).

    Message received in openHAB:

    13:27:54.142 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 124-124-0 s=0,c=1,t=1,pt=7,l=5,sg=0:31.0
    ' on serial port /dev/ttyUSB0
    

    So at this point I see that all messages are type 3 ( not 1 as in the above example ).

    That message updates my openHAB item, as per this example I have a rule that descompose the original message ( no modifications done yet to the one posted here ).

    So, when I finally get to the core msg ( the one that in this example is directly assigned to the openHAB item ) the value is:

    124-124-0 s=0,c=1,t=1,pt=7,l=5,sg=0:31.0
    

    instead of the 31.0 that I was expecting.

    Any ideas?

    (happy to provide more sections of code if needed, didn't want to put everyting here to avoid garbage)

    Thanks in advance for any help.


  • Admin

    @Dave-Dan
    0;0;3 means a debug message.. you can throw these away. Shouldn't be processed by your controller.



  • @hek
    hey hek, thanks for the quick reply.

    so that means that if i disable DEBUG in the arduino skech I'll remove that part of the message?


  • Admin

    Yes, they disappear when disabling DEBUG.



  • Ok cool.
    That means that I'm doing something else wrong bc I still see that part after disabling DEBUG.

    I'm curious on why having the same sketch + openHAB rule from thia thread I xan make it work ...

    Will review carefully because sounds weird for me.

    Thanks!!!!



  • Hi TimO,
    I want to make a permanent USB setting for my Radberry and I follow your tutorial here.
    In my etc/udev/rules.d I have two documents: 40-scratch.rules and 99-input.rules and I don't know where to make the needed modifications as you show in this tutorial.
    The file you point to make the modifications has another name and I can't figure where to add the vendor, product and serial no for my arduino. Shall I make a new file called 99-usb-serial.rules and to write in it the ATTRS{idVendor} and the rest of them according to my dmesg as you say here above or to do that in one of the two files I have?
    Thanks!



  • Hi! Can somebody please help here? I got stuck with my openhab server on my raspberry!
    By now I was starting the server by:

    Sudo /opt/openhab/start.sh
    

    But I wanted more, to make it auto start on reboot so in case of power failure to auto start when the power is back. Therefore I followed some tutorials found on the www and I got it done, now the server starts alone but I cannot do anything from web page or from my phone. I also can't see the temp and humidity on the web or phone!
    The question is how to stop this server? I tried different commands found on the internet but non of them can stop this invincible server I have lunched 🙂
    I tried to stop it, remove, delete... Nothing works!
    Is there any way to remove everything from my raspberry pi and to start it all over again with all the installation as for windows ? Format the partition, install the noobs again and so on?
    Thanks.


  • Hero Member

    1. udev: Just create the new file if it is not there yet. It should be processed automatically.

    2. The best way to start a service in Linux is using an etc-script. You will find an example here: https://github.com/openhab/openhab/wiki/Samples-Tricks#how-to-configure-openhab-to-start-automatically-on-linux
      The script will start OpenHab at boot and you're able to start/stop/restart with

      /etc/init.d/openhab start
      or
      service openhab start


  • I'm having issues getting the ttyUSB99 fix to work.
    I'm running openhab 1.7.1 and it was installed using apt-get.
    My dmseg output looks like this

    [10167.765598] usb 1-1.2: USB disconnect, device number 4
    [10167.766311] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
    [10167.766407] ch341 1-1.2:1.0: device disconnected
    [10171.843803] usb 1-1.2: new full-speed USB device number 5 using dwc_otg
    [10171.946998] usb 1-1.2: New USB device found, idVendor=1a86, idProduct=7523
    [10171.947025] usb 1-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
    [10171.947042] usb 1-1.2: Product: USB2.0-Serial
    [10171.948288] ch341 1-1.2:1.0: ch341-uart converter detected
    [10171.952514] usb 1-1.2: ch341-uart converter now attached to ttyUSB0
    

    As you can see there is no SerialNumber here, but I found it using

    pi@raspberrypi ~ $ udevadm info -a -n /dev/ttyUSB0 | grep '{serial}' | head -n1
        ATTRS{serial}=="3f980000.usb
    

    So I created a rules file looking like this:

    pi@raspberrypi ~ $ cat /etc/udev/rules.d/99-usb-serial.rules
    SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99"
    

    I have disconnected and reconnected my gateway.
    But starting openhab now just results in the following error:

    2015-09-20 09:24:48.867 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type 'serial' of item ?Arduino? could not be parsed correctly.
    org.openhab.model.item.binding.BindingConfigParseException: Could not open serial port /dev/ttyUSB99: Serial port '/dev/ttyUSB99' could not be found. Available ports are:
    /dev/ttyUSB0
    

    What can I do to resolve this?



  • Eventually solved it by just omitting SerialNumber, i.e.

    SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ATTRS{serial}=="3f980000.usb", SYMLINK+="ttyUSB99
    

    I guess that could cause problems if I would attached more similar devices to my RPI, but I don't know if there is any point in having more than one gateway? (unless you have > 255 sensors I guess)



  • Hi,

    I am new with mysensors and i am trying to make it work with openhab.
    I have a soil sensor and with same copy paste from the forum i manage to sent the value on the openhab, now i am trying to translate the battery level on the opnehab side but i dont know how to do it. can someone help me please?? this is what i get on the openhab 0;0;3;0;9;read: 254-254-0 s=255,c=3,t=0,pt=1,l=1,sg=0:68
    254;255;3;0;0;68 this is the battery value.
    But i am lost on the rule how to decode the message.

    Thanks
    Nikos



  • I also would like to share my working default.rules + examples with you. Hope it can help someone.

    https://gist.github.com/gersilex/13f39b3419427b35636a


  • Hero Member

    Hi @nikos1671 !

    You need to add an item to the hash map with nodeID 254 and childId 255.
    In the rules section search for

    // Internal Command
            		    if(msgType == 3){
            		        if(subType == I_SKETCH_NAME){
            		                println("Sketch name: " + msg )
            		                sketchName=msg
            		            }
            		        if(subType == I_SKETCH_VERSION){
            		                println("Sketch version: " + msg )
            		                postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), sketchName+" " +msg )
            		                sketchName=""
            		            }
            		        }
            	 	   }
    
    

    As the battery status is an internal message, you need to modify this section. Add an if statement for I_BATTERY_LEVEL.

    For more information about the messages: http://www.mysensors.org/download/serial_api_15



  • @TimO thank you



  • What i am doing wrong??
    i am using the last rules from silex and i can parse the data from my sensebender temp and hum on openhab but i cannot make it with battery. here is my setup

    // Mappings
    var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(

    "3;1;"                 -> "Temp",
    "Temp"					-> "3;1;",
    "3;2;"                 -> "Hum",
    "Hum"					-> "3;2;",
    "3;255;"                 -> "Batt",
    "Batt"			   		-> "3;255;",
    

    the rule

    if(msgType == M_INTERNAL){ // Internal Command
    print("(INTERNAL)\t")
    if(subType == I_SKETCH_NAME){
    println("Sketch name: " + msg )
    }
    if(subType == I_SKETCH_VERSION){
    println("Sketch version: " + msg )
    }
    if(subType == I_BATTERY_LEVEL){
    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    println ("Batt item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Batt: " + msg )
    }

                    }
    

    my.items
    String Arduino "Arduino" { serial="COM3@115200" }

    Number Temp "Temperatur [%.1f °C]" <temperature>
    Number Hum "Feuchtigkeit [%.1f %%]" <temperature>
    Number Batt "bataria [%.1f %%]" <energy>

    and this is the logs of openhab
    20:02:58.954 [DEBUG] [b.serial.internal.SerialDevice:194 ] - Received message '0;0;3;0;9;read: 3-3-0 s=255,c=4,t=0,pt=6,l=10,sg=0:FFFFFFFFFFFFFFFF03
    3;255;4;0;0;FFFFFFFFFFFFFFFF0300
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=11,pt=0,l=17,sg=0:Sensebender Micro
    3;255;3;0;11;Sensebender Micro
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.3
    3;255;3;0;12;1.3
    0;0;3;0;9;read: 3-3-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
    3;1;0;0;6;
    0;0;3;0;9;read: 3-3-0 s=2,c=0,t=7,pt=0,l=0,sg=0:
    3;2;0;0;7;
    0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.6
    3;1;1;0;0;23.6
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:53
    3;2;1;0;1;53
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=0,pt=1,l=1,sg=0:113
    3;255;3;0;0;113
    ' on serial port COM3
    20:02:58.960 [DEBUG] [o.b.f.i.h.FritzahaWebInterface:336 ] - Sending update to item Power_FritzDECTv
    20:02:58.977 [DEBUG] [m.r.internal.engine.RuleEngine:305 ] - Executing rule 'Decode incoming MySensors data'
    20:02:59.101 [ERROR] [o.o.c.s.ScriptExecutionThread :50 ] - Error during the execution of rule 'Decode incoming MySensors data': 5

    Can someone help me please??



  • Hi @nikos1671,

    everytime I had that error was mainly because I forgot / add extra comma in the LinkedHastMap definition or something like that.

    Can you please share the full openHAB rule?



  • Hi @Dave-Dan ,

    i think i found the problem. i have 2 sensebender micro one with the original shiped firmaware 1.1 (node1) and one with the new one 1.3 (node3) as you can see in the logs of openhab the node1 its parsing the data on the openhab very good but the node3 throwing an error( Error during the execution of rule 'Decode incoming MySensors data': 5)

    here is the rule that i use

    // CONTRIBUTE: Feel free to fork, enhance, pull reqest
    //
    // SiLeX <gersilex@gmail.com>
    //
    //
    // IMPORTS //////////////////////////////////////////////////////////////////////////////////////////////////////////
    import org.openhab.core.library.types.*
    import org.openhab.core.persistence.*
    import org.openhab.model.script.actions.*
    import java.util.HashMap
    import org.eclipse.xtext.xbase.lib.*
    import org.openhab.core.items.*
    
    // VARS /////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // MySensors 1.5 ////////////////////////////////////////////////////////////////////////////////////////////////////
    // MessageTypes  //
    
    val int M_PRESENTATION    = 0  // Sent by a node when they present attached sensors. This is usually done in setup() at startup.
    val int M_SET             = 1  // This message is sent from or to a sensor when a sensor value should be updated
    val int M_REQ             = 2  // Requests a variable value (usually from an actuator destined for controller).
    val int M_INTERNAL        = 3  // This is a special internal message. See table below for the details
    val int M_STREAM          = 4  // Used for OTA firmware updates
    
    // SubTypes for MessageType M_PRESENTATION //
    // (Not used for now, as automatic configuration is not possible in OpenHAB 1.)
    // val int S_DOOR                     = 0   // Door and window sensors
    // val int S_MOTION                   = 1   // Motion sensors
    // val int S_SMOKE                    = 2   // Smoke sensor
    // val int S_LIGHT                    = 3   // Light Actuator (on/off)
    // val int S_BINARY                   = 3   // Binary device (on/off), Alias for S_LIGHT
    // val int S_DIMMER                   = 4   // Dimmable device of some kind
    // val int S_COVER                    = 5   // Window covers or shades
    // val int S_TEMP                     = 6   // Temperature sensor
    // val int S_HUM                      = 7   // Humidity sensor
    // val int S_BARO                     = 8   // Barometer sensor (Pressure)
    // val int S_WIND                     = 9   // Wind sensor
    // val int S_RAIN                     = 10  // Rain sensor
    // val int S_UV                       = 11  // UV sensor
    // val int S_WEIGHT                   = 12  // Weight sensor for scales etc.
    // val int S_POWER                    = 13  // Power measuring device, like power meters
    // val int S_HEATER                   = 14  // Heater device
    // val int S_DISTANCE                 = 15  // Distance sensor
    // val int S_LIGHT_LEVEL              = 16  // Light sensor
    // val int S_ARDUINO_NODE             = 17  // Arduino node device
    // val int S_ARDUINO_REPEATER_NODE    = 18  // Arduino repeating node device
    // val int S_LOCK                     = 19  // Lock device
    // val int S_IR                       = 20  // Ir sender/receiver device
    // val int S_WATER                    = 21  // Water meter
    // val int S_AIR_QUALITY              = 22  // Air quality sensor e.g. MQ-2
    // val int S_CUSTOM                   = 23  // Use this for custom sensors where no other fits.
    // val int S_DUST                     = 24  // Dust level sensor
    // val int S_SCENE_CONTROLLER         = 25  // Scene controller device
    // val int S_RGB_LIGHT                = 26  // RGB light
    // val int S_RGBW_LIGHT               = 27  // RGBW light (with separate white component)
    // val int S_COLOR_SENSOR             = 28  // Color sensor
    // val int S_HVAC                     = 29  // Thermostat/HVAC device
    // val int S_MULTIMETER               = 30  // Multimeter device
    // val int S_SPRINKLER                = 31  // Sprinkler device
    // val int S_WATER_LEAK               = 32  // Water leak sensor
    // val int S_SOUND                    = 33  // Sound sensor
    // val int S_VIBRATION                = 34  // Vibration sensor
    // val int S_MOISTURE                 = 35  // Moisture sensor
    
    // SubTypes for MessageType M_SET //
    val int V_TEMP                  = 0   // Temperature
    val int V_HUM                   = 1   // Humidity
    val int V_STATUS                = 2   // Binary status. 0=off 1=on
    val int V_LIGHT                 = 2   // Deprecated. Alias for V_STATUS. Light status. 0=off 1=on
    val int V_PERCENTAGE            = 3   // Percentage value. 0-100 (%)
    val int V_DIMMER                = 3   // Deprecated. Alias for V_PERCENTAGE. Dimmer value. 0-100 (%)
    val int V_PRESSURE              = 4   // Atmospheric Pressure
    val int V_FORECAST              = 5   // Whether forecast. One of "stable", "sunny", "cloudy", "unstable", "thunderstorm" or "unknown"
    val int V_RAIN                  = 6   // Amount of rain
    val int V_RAINRATE              = 7   // Rate of rain
    val int V_WIND                  = 8   // Windspeed
    val int V_GUST                  = 9   // Gust
    val int V_DIRECTION             = 10  // Wind direction
    val int V_UV                    = 11  // UV light level
    val int V_WEIGHT                = 12  // Weight (for scales etc)
    val int V_DISTANCE              = 13  // Distance
    val int V_IMPEDANCE             = 14  // Impedance value
    val int V_ARMED                 = 15  // Armed status of a security sensor. 1=Armed, 0=Bypassed
    val int V_TRIPPED               = 16  // Tripped status of a security sensor. 1=Tripped, 0=Untripped
    val int V_WATT                  = 17  // Watt value for power meters
    val int V_KWH                   = 18  // Accumulated number of KWH for a power meter
    val int V_SCENE_ON              = 19  // Turn on a scene
    val int V_SCENE_OFF             = 20  // Turn of a scene
    val int V_HVAC_FLOW_STATE       = 21  // Mode of header. One of "Off", "HeatOn", "CoolOn", or "AutoChangeOver"
    val int V_HVAC_SPEED            = 22  // HVAC/Heater fan speed ("Min", "Normal", "Max", "Auto")
    val int V_LIGHT_LEVEL           = 23  // Uncalibrated light level. 0-100%. Use V_LEVEL for light level in lux.
    val int V_VAR1                  = 24  // Custom value
    val int V_VAR2                  = 25  // Custom value
    val int V_VAR3                  = 26  // Custom value
    val int V_VAR4                  = 27  // Custom value
    val int V_VAR5                  = 28  // Custom value
    val int V_UP                    = 29  // Window covering. Up.
    val int V_DOWN                  = 30  // Window covering. Down.
    val int V_STOP                  = 31  // Window covering. Stop.
    val int V_IR_SEND               = 32  // Send out an IR-command
    val int V_IR_RECEIVE            = 33  // This message contains a received IR-command
    val int V_FLOW                  = 34  // Flow of water (in meter)
    val int V_VOLUME                = 35  // Water volume
    val int V_LOCK_STATUS           = 36  // Set or get lock status. 1=Locked, 0=Unlocked
    val int V_LEVEL                 = 37  // Used for sending level-value
    val int V_VOLTAGE               = 38  // Voltage level
    val int V_CURRENT               = 39  // Current level
    val int V_RGB                   = 40  // RGB value transmitted as ASCII hex string (I.e "ff0000" for red)
    val int V_RGBW                  = 41  // RGBW value transmitted as ASCII hex string (I.e "ff0000ff" for red + full white)
    val int V_ID                    = 42  // Optional unique sensor id (e.g. OneWire DS1820b ids)
    val int V_UNIT_PREFIX           = 43  // Allows sensors to send in a string representing the unit prefix to be displayed in GUI. This is not parsed by controller! E.g. cm, m, km, inch.
    val int V_HVAC_SETPOINT_COOL    = 44  // HVAC cold setpoint
    val int V_HVAC_SETPOINT_HEAT    = 45  // HVAC/Heater setpoint
    val int V_HVAC_FLOW_MODE        = 46  // Flow mode for HVAC ("Auto", "ContinuousOn", "PeriodicOn")
    
    // SubTypes for MessageType M_INTERNAL //
    val int I_BATTERY_LEVEL           = 0   // Use this to report the battery level (in percent 0-100).
    val int I_TIME                    = 1   // Sensors can request the current time from the Controller using this message. The time will be reported as the seconds since 1970
    val int I_VERSION                 = 2   // Used to request gateway version from controller.
    val int I_ID_REQUEST              = 3   // Use this to request a unique node id from the controller.
    val int I_ID_RESPONSE             = 4   // Id response back to sensor. Payload contains sensor id.
    val int I_INCLUSION_MODE          = 5   // Start/stop inclusion mode of the Controller (1=start, 0=stop).
    val int I_CONFIG                  = 6   // Config request from node. Reply with (M)etric or (I)mperal back to sensor.
    val int I_FIND_PARENT             = 7   // When a sensor starts up, it broadcast a search request to all neighbor nodes. They reply with a I_FIND_PARENT_RESPONSE.
    val int I_FIND_PARENT_RESPONSE    = 8   // Reply message type to I_FIND_PARENT request.
    val int I_LOG_MESSAGE             = 9   // Sent by the gateway to the Controller to trace-log a message
    val int I_CHILDREN                = 10  // A message that can be used to transfer child sensors (from EEPROM routing table) of a repeating node.
    val int I_SKETCH_NAME             = 11  // Optional sketch name that can be used to identify sensor in the Controller GUI
    val int I_SKETCH_VERSION          = 12  // Optional sketch version that can be reported to keep track of the version of sensor in the Controller GUI.
    val int I_REBOOT                  = 13  // Used by OTA firmware updates. Request for node to reboot.
    val int I_GATEWAY_READY           = 14  // Send by gateway to controller when startup is complete.
    val int I_REQUEST_SIGNING         = 15  // Used between sensors when initialting signing.
    val int I_GET_NONCE               = 16  // Used between sensors when requesting nonce.
    val int I_GET_NONCE_RESPONSE      = 17  // Used between sensors for nonce response.
    
    // MySensors 1.5 Configuration
    ///////////////////////////////
    // Use the HashMap "sensorToItemsMap" to create a relation between the nodeID
    // within MySensors and the item name in OpenHAB.
    //
    // Please note that you must map in both directions, so we can resolve both.
    
    // Mappings
    var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
    
        "3;1;"                 -> "Temp",
        "Temp"					-> "3;1;",
    	"3;2;"                 -> "Hum",
        "Hum"					-> "3;2;",
    	"3;255;"                 -> "Batt",
        "Batt"			   		-> "3;255;",
        "1;1;"                 -> "Temp1",
        "Temp1"					-> "1;1;",
    	"1;2;"                 -> "Hum1",
        "Hum1"					-> "1;2;",
    	"1;255;"                -> "Battery1",
        "Battery1"				-> "1;255;",
    
    )
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////
    
    val org.eclipse.xtext.xbase.lib.Functions$Function4 mysensors = [
        String IDs,
        int subType,
        String data,
        org.openhab.core.library.items.StringItem gw
        |
        if(!(data instanceof String)) println("\nERROR: data must be String but has " + data.getClass() + "\n")
        var String new_data
        if(data == "ON"){
            new_data = new String("1")
        }
        else if (data == "OFF"){
            new_data = new String("0")
        }
        else
        {
            new_data = new String(data)
        }
        var String output = IDs + "1;0;" + subType + ";" + new_data + "\n"
        gw.sendCommand(output)
    ]
    
    // Notes for this rule
    // This is all you need to have MySensors set your items.
    // It's better to hardcode the nodeID on your MySensors sensors,
    // because openHAB will not assign them nodeIDs.
    
    rule "Decode incoming MySensors data"
        when
            Item Arduino changed
        then
            var String lineBuffer =  Arduino.state.toString.split("\n")
            for (String line : lineBuffer) {
                var String[] message = line.split(";")
                var Integer nodeId = new Integer(message.get(0))
                var Integer childId = new Integer(message.get(1))
                var Integer msgType = new Integer(message.get(2))
                var Integer ack = new Integer(message.get(3))
                var Integer subType = new Integer(message.get(4))
                var String msg = message.get(5)
                var String openhab_item = sensorToItemsMap.get( nodeId + ";" + childId + ";" )
                if (nodeId != 0){ // internal messages have nodeId 0, but are not used for now
                    if (openhab_item == null){
                        println("No item matches nodeId=" + nodeId + ", childId=" + childId + ". Data received: " + msg)
                    }
                    else { // openhab_item != null
                        print("openhab_item=" + openhab_item + "\t")
                        print("msgType=" + msgType + " ")
                        var String newState = msg
                        if (msgType == M_SET){ // Set Command from or to node
                            println("(SET)\t subType=" + subType + " ")
    
                            if (subType      == V_STATUS ){ if ( new Integer(msg) == 1 ) newState =      "ON" else newState = "OFF" }
                            if (subType      ==  V_ARMED ){ if ( new Integer(msg) == 1 ) newState =      "ON" else newState = "OFF" }
                            else if (subType == V_TRIPPED){ if ( new Integer(msg) == 1 ) newState = "OPEN" else newState = "CLOSED" }
    
                            else println("No special handler for subType=" + subType + " found. Simply using data as String.")
    
                        postUpdate(openhab_item, newState)
                        }
                        if(msgType == M_INTERNAL){ // Internal Command
                            print("(INTERNAL)\t")
                            if(subType == I_SKETCH_NAME){
                                println("Sketch name: " + msg )
                            }
                            if(subType == I_SKETCH_VERSION){
                                println("Sketch version: " + msg )
                            }
    						if(subType == I_BATTERY_LEVEL){
    							postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    							println ("Battery1 item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Battery1: " + msg )
                            }
    						if(subType == I_BATTERY_LEVEL){
    							postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
    							println ("Batt item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Batt: " + msg )
                            }
                        }
                    } // openhab_item != null
                }
            }
        }
    end
    

    and here is the logs of openhhab

    10:37:09.294 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;gateway started, id=0, parent=0, distance=0
    0;0;3;0;14;Gateway startup complete.
    ' on serial port COM13
    10:37:10.764 [DEBUG] [o.o.i.s.i.DiscoveryServiceImpl:66   ] - Registering new service _openhab-server-ssl._tcp.local. at port 8443
    10:37:12.060 [INFO ] [c.internal.ModelRepositoryImpl:80   ] - Loading model 'demo.rules'
    10:37:13.305 [DEBUG] [.i.LoggingPersistenceActivator:31   ] - Logging persistence bundle has been started.
    10:37:13.316 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:37:13.347 [DEBUG] [.p.internal.PersistenceManager:147  ] - Initializing logging persistence service.
    10:37:13.369 [DEBUG] [.zwave.internal.ZWaveActivator:36   ] - Z-Wave binding started. Version 1.7.1
    10:37:13.424 [DEBUG] [.z.internal.ZWaveActiveBinding:175  ] - ConverterHandler not initialised. Polling disabled.
    10:37:13.424 [INFO ] [.z.internal.ZWaveActiveBinding:317  ] - ZWave 'updated' with null config
    10:37:14.156 [DEBUG] [riptExtensionClassNameProvider:63   ] - Script actions have changed: PingActionService, AudioActionService, HTTPActionService, TransformationActionService, ExecActionService, 
    10:37:34.145 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=255,c=0,t=17,pt=0,l=5,sg=0:1.4.1
    1;255;0;0;17;1.4.1
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    1;255;3;0;6;0
    ' on serial port COM13
    10:37:34.145 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:37:36.179 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=255,c=3,t=11,pt=0,l=17,sg=0:Sensebender Micro
    1;255;3;0;11;Sensebender Micro
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.1
    1;255;3;0;12;1.1
    0;0;3;0;9;read: 1-1-0 s=1,c=0,t=6,pt=0,l=5,sg=0:1.4.1
    1;1;0;0;6;1.4.1
    0;0;3;0;9;read: 1-1-0 s=2,c=0,t=7,pt=0,l=5,sg=0:1.4.1
    1;2;0;0;7;1.4.1
    0;0;3;0;9;read: 1-1-0 s=255,c=3,t=0,pt=1,l=1,sg=0:80
    1;255;3;0;0;80
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.2
    1;1;1;0;0;22.2
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:47
    1;2;1;0;1;47
    ' on serial port COM13
    10:37:36.179 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:37:47.968 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=255,c=0,t=17,pt=0,l=3,sg=0:1.5
    3;255;0;0;17;1.5
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=6,pt=1,l=1,sg=0:0
    3;255;3;0;6;0
    ' on serial port COM13
    10:37:47.968 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:37:50.078 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=255,c=4,t=0,pt=6,l=10,sg=0:FFFFFFFFFFFFFFFF03
    3;255;4;0;0;FFFFFFFFFFFFFFFF0300
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=11,pt=0,l=17,sg=0:Sensebender Micro
    3;255;3;0;11;Sensebender Micro
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=12,pt=0,l=3,sg=0:1.3
    3;255;3;0;12;1.3
    0;0;3;0;9;read: 3-3-0 s=1,c=0,t=6,pt=0,l=0,sg=0:
    3;1;0;0;6;
    0;0;3;0;9;read: 3-3-0 s=2,c=0,t=7,pt=0,l=0,sg=0:
    3;2;0;0;7;
    0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.2
    3;1;1;0;0;22.2
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:48
    3;2;1;0;1;48
    0;0;3;0;9;read: 3-3-0 s=255,c=3,t=0,pt=1,l=1,sg=0:75
    3;255;3;0;0;75
    ' on serial port COM13
    10:37:50.078 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:37:50.158 [ERROR] [o.o.c.s.ScriptExecutionThread :50   ] - Error during the execution of rule 'Decode incoming MySensors data': 5
    10:38:42.965 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=255,c=3,t=0,pt=1,l=1,sg=0:82
    1;255;3;0;0;82
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.1
    1;1;1;0;0;22.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:38:42.965 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:39:49.716 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.1
    1;1;1;0;0;22.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:40:40.851 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:40:56.432 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.2
    1;1;1;0;0;22.2
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:48
    1;2;1;0;1;48
    ' on serial port COM13
    10:40:56.432 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:41:04.095 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:24.2
    3;1;1;0;0;24.2
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:76
    3;2;1;0;1;76
    ' on serial port COM13
    10:41:04.095 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:42:03.228 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.2
    1;1;1;0;0;22.2
    ' on serial port COM13
    10:42:03.230 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:42:03.437 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:47
    1;2;1;0;1;47
    ' on serial port COM13
    10:42:03.437 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:42:08.798 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.5
    3;1;1;0;0;23.5
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:50
    3;2;1;0;1;50
    ' on serial port COM13
    10:42:08.798 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:43:10.504 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.1
    1;1;1;0;0;22.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:43:10.504 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:43:13.496 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.2
    3;1;1;0;0;23.2
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:48
    3;2;1;0;1;48
    ' on serial port COM13
    10:43:13.496 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:44:17.497 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.0
    1;1;1;0;0;22.0
    ' on serial port COM13
    10:44:17.500 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:44:18.176 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.8
    3;1;1;0;0;22.8
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    3;2;1;0;1;46
    ' on serial port COM13
    10:44:18.176 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:45:24.715 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.0
    1;1;1;0;0;22.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:45:24.717 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:46:31.704 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.9
    1;1;1;0;0;21.9
    ' on serial port COM13
    10:46:31.706 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:47:32.139 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 3-3-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.3
    3;1;1;0;0;22.3
    0;0;3;0;9;read: 3-3-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    3;2;1;0;1;46
    ' on serial port COM13
    10:47:32.141 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:47:38.937 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.9
    1;1;1;0;0;21.9
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:47:38.939 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:48:46.058 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:48:46.060 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:49:53.042 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.9
    1;1;1;0;0;21.9
    ' on serial port COM13
    10:49:53.044 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:51:00.209 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=255,c=3,t=0,pt=1,l=1,sg=0:82
    1;255;3;0;0;82
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:22.0
    1;1;1;0;0;22.0
    ' on serial port COM13
    10:51:00.211 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:51:00.424 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:51:00.426 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:52:07.248 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=255,c=3,t=0,pt=1,l=1,sg=0:82
    1;255;3;0;0;82
    ' on serial port COM13
    10:52:07.249 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    10:52:07.640 [DEBUG] [b.serial.internal.SerialDevice:194  ] - Received message '0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.9
    1;1;1;0;0;21.9
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=1,pt=2,l=2,sg=0:46
    1;2;1;0;1;46
    ' on serial port COM13
    10:52:07.640 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'Decode incoming MySensors data'
    
    

    The rule react fast and fill all the data (temp,hum,bat) on the openhab site for the node with the old firmware but with the new frimware i connect the batteries on the sensor and i must wait some minutes until the temp and hum appear on th site but the battery percent not,only after hours
    Thanks
    Nikos



  • hey @nikos1671,

    good to hear you have it under control.

    Also, please take a look to the 'sensorToItemsMap' definition. If I remember correctly, the last item in the last item, otherwise the compiler is waiting for another item.

    This is something that happened to me every time I include any new item (you know, copy & paste ... bad thing :P).

    The fact that you have to wait hours to get the battery status is odd. When I restart one of my nodes ( one with battery level) I have the information inmediately available, well ... as soon as the node sends the information, and fully refreshed in openhab site.

    it's true I've had different update speeds but basically because I did my first tests with ah Raspberry Pi 1 and now I have all the system working in a Pi 2 ... so goes faster (very much).



  • Hey guys, on my Raspberry Pi 2 the first rule execution takes about 15 seconds. If you have changed the rules file, the xtent logic has to be re-compiled to java code again. But after the first rule execution it takes only about 10-50ms for execution.

    Also, @nikos1671 I would turn off the DEBUG mode on your gateway. Receiving data works and this is what you would debug. You see incoming data without debug, too so you can securely get rid of it 😁



  • Hi ,

    I think the problem is this msg 3;255;4;0;0;FFFFFFFFFFFFFFFF0300 is this something with the OTA firmware? i think the rule dont recognise this msg and give an error (Error during the execution of rule 'Decode incoming MySensors data': 5). Can the author of the rule please confirm if this it the problem of the error??



  • @nikos1671 In case of unhandled messages (when there is no openhab item assigned to this nodeID;childID;-combination in your sensorToItemsMap), they will just be ignored (and print the data field).
    This happens here in the code: https://gist.github.com/gersilex/13f39b3419427b35636a#file-default-rules-L211

    This will look like this:

    3;255;4;0;0;FFFFFFFFFFFFFFFF0300
    No item matches nodeId=3, childId=255. Data received: FFFFFFFFFFFFFFFF0300
    

    However, this was never tested with debugging enabled on the Gateway. This is why I asked you to disable debugging and recompile/reupload the code to your gateway arduino without the DEBUG flag inside MyConfig.h.

    There is a know problem which is not catched currently:

    • Data can only be decoded, if the String has exactly 6 fields, seperated by a semicolon.

    Please go and try to disable the DEBUG on your gateway arduino.



  • Can someone help me? I want to integrate a motion sensor in OpenHAB but I don't know how to distinguish between the motion start and end. here's my openhab console log:

    bewegungsmelder_fehler.png



  • Can somebody help..?



  • Try removing DEBUG in the Serial GW and review messages.

    I receive a 0 or 1 depending if the motion is detected or the sensor is resetting to normal status.



  • @Dave-Dan i tried it, but the motion sensor is still sending only zero's.... even if it is not triggered.
    I got these motion sensors: http://www.amazon.de/Pyroelectrische-Infrarot-Bewegung-Sensor-Detektor/dp/B008AESDSY/



  • When I look at the serial monitor output for my motion sensor, it clearly gives me a "0" or "1" depending if movement is detected or not.

    But when I look at the serial monitor of my gateway, it only receives the same message no matter if motion started (motion sensor serial monitor: 1) or ended (motion sensor serial monitor: 0)

    12345.png


  • Hero Member

    @HenryWhite The node is requesting for an id and not sending any status. You'll need to define a static id in the sketch of your node:

    http://www.mysensors.org/download/sensor_api_15#the-full-api

    Look for "Starting up the library" and the "begin()" function.



  • @TimO thank you so much! it works now. Any idea why i had to assign a static id? i thought the gateway should tell the node a dynamic id automatically..


  • Hero Member

    @HenryWhite You're welcome. The id is assigned by the controller, in your case OpenHAB. There is a post in the forum about how to add a rule for id assignment, but I don't use it myself.



  • I have a real noob question, and I am way better with the electronics that I am the software. I can see my motion detector show up in my gateway, and in the events.log, so I know that I am getting to the Raspberry Pi I deployed opneHAB on.

    Here's some detail:
    So I have build the MySensors.org motion detector (and a separate temp/humidity sensor), loaded up the NRF24l01+ and PIR.
    I created a gateway out of a nano with NRF24l01+.
    I followed the tutorial on how to do the serial bindings.
    I see in the terminal window runtime.busevents that the motion detector is detecting movement, and later changing back to 0, along with the other sensor I have, which is the DHT11 for temp and humidity.

    2016-01-10 18:48:12 - Arduino state updated to 0;0;3;0;9;read: 4-4-0 s=1,c=1,t=0,pt=7,l=5:21.0
    4;1;1;0;0;21.0
    2016-01-10 18:48:12 - livingTemp01 state updated to 21.0
    2016-01-10 18:49:32 - Arduino state updated to 0;0;3;0;9;read: 10-10-0 s=1,c=1,t=16,pt=0,l=1:1
    10;1;1;0;16;1
    2016-01-10 18:49:35 - Arduino state updated to 0;0;3;0;9;read: 10-10-0 s=1,c=1,t=16,pt=0,l=1:0
    10;1;1;0;16;0

    My confusion is how this software all works to get just the information from the gateway to the screen.
    I know you have to declare an item in the demo.items file, and that item needs to be in the sitemap to display. but I do not understand how you get the status from the gateway? Can someone point me to some simple examples that include the mysensor.org PIR sensor? How does the item declaration get the knowledge of the change that the gateway is receiving from the sensor? I have read through several documents and tutorials, but I am missing this bit of information.



  • Ah, I finally see it, it was staring me in the face in the rules section. You identify via the msgType then assign in the rule. Doh!



  • @poeml following up myself, using an external, powered USB hub indeed fixed the problem. The USB adapter is now correctly usable after system bootup. (I use the official Raspberry Foundation hub, which promises to avoid issues with backpowering.)



  • It just took me 2 hours to realize that you should not use

    import java.util.*
    

    when you want to use timer operations like

    if (timer=! null) {
    ...
    }
    

    Without importing java.util.* , everything works as expected. Someone has an idea why this is the case? Can you reproduce my problem?



  • Thanks for this great post. Just what I need to get a handle on using openHAB with MySensors!



  • Can someone please assist me regarding this serial connection setup.
    I can see in my event log that I receive updates of the Arduino state as below:

    Arduino state updated to 99;1;1;0;0;23.7
    99;0;1;0;1;37.2
    
    

    And also in the openhab.log file I get the following types of messages:

    [DEBUG] [b.serial.internal.SerialDevice:225  ] - Received message '99;0;1;0;1;37.6
    ' on serial port /dev/ttyUSB99
    

    But the rule is for some reason not initiated I guess as the println and logInfo i I've added to the top of the rule is absent from the logs. I can see from the tutorial and your posts that you get log information like below but these I cant find in any log.

    [INFO ] [runtime.busevents             ]
    

    Possibly I'm missing something in my logback.xml settings or perhaps there is some other reason to this which also might explain why my rule is not started. Perhaps its because I'm using a newer binding for the serial connection? (org.openhab.binding.serial-1.8.3.jar)

    Any help would be much appreciated!

    Update 1: Perhaps I'll try the mysensors binding and if I'm more successful with that approach I'll skip this serial binding altogether.

    Update 2: Ok, I will be using the mysensors binding for the serial connection. I tried it last night and it just worked! And this serial binding approach also demands some quite extensive rule handling of the incoming messages which is not the case with mysensors binding. I think I read somewhere that the mysensors binding will also be available for Openhab 2.0 so hopefully I can continue using it also in the future.

    My recommendation for new users of the serial gateway (who also uses openhap as a controller) is to go for the mysensors binding!



  • This post is deleted!


  • @TimO is it possible to send commands to actuators with this method? I have a LED Dimmer Actuator and don't know what I have to do in OpenHAB to send commands to this actuator over the serial gateway..


  • Hero Member



  • @TimO

    Great! Thank you!


Log in to reply
 

Suggested Topics

  • 22
  • 2
  • 3
  • 4
  • 135
  • 1

64
Online

11.4k
Users

11.1k
Topics

112.7k
Posts