Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. OpenHAB
  4. [Tutorial] openHAB with serial gateway

[Tutorial] openHAB with serial gateway

Scheduled Pinned Locked Moved OpenHAB
78 Posts 25 Posters 76.3k Views 16 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jan Gatzke

    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.

    G Offline
    G Offline
    gizmosensor
    wrote on last edited by gizmosensor
    #27

    @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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      almj
      wrote on last edited by
      #28

      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!

      1 Reply Last reply
      1
      • A Offline
        A Offline
        almj
        wrote on last edited by
        #29

        Thanks for help ;)
        Figured out it by myself

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jan Gatzke
          wrote on last edited by
          #30

          Would you mind to share the solution?

          1 Reply Last reply
          1
          • T TimO

            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.

            C Offline
            C Offline
            C.r.a.z.y.
            wrote on last edited by
            #31

            @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

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jan Gatzke
              wrote on last edited by
              #32

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

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TimO
                Hero Member
                wrote on last edited by
                #33

                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.

                C 2 Replies Last reply
                0
                • T TimO

                  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.

                  C Offline
                  C Offline
                  C.r.a.z.y.
                  wrote on last edited by
                  #34

                  @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..

                  1 Reply Last reply
                  0
                  • T TimO

                    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.

                    C Offline
                    C Offline
                    C.r.a.z.y.
                    wrote on last edited by
                    #35

                    @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)

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      ewgor
                      wrote on last edited by
                      #36

                      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!

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        gigaguy
                        wrote on last edited by
                        #37

                        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)
                                        }}
                        
                        1 Reply Last reply
                        0
                        • John ConnollyJ Offline
                          John ConnollyJ Offline
                          John Connolly
                          wrote on last edited by
                          #38

                          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.

                          1 Reply Last reply
                          0
                          • John ConnollyJ Offline
                            John ConnollyJ Offline
                            John Connolly
                            wrote on last edited by
                            #39

                            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. :)

                            1 Reply Last reply
                            0
                            • Dave DanD Offline
                              Dave DanD Offline
                              Dave Dan
                              wrote on last edited by Dave Dan
                              #40

                              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.

                              1 Reply Last reply
                              0
                              • hekH Offline
                                hekH Offline
                                hek
                                Admin
                                wrote on last edited by
                                #41

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

                                Dave DanD 1 Reply Last reply
                                0
                                • hekH hek

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

                                  Dave DanD Offline
                                  Dave DanD Offline
                                  Dave Dan
                                  wrote on last edited by
                                  #42

                                  @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?

                                  1 Reply Last reply
                                  0
                                  • hekH Offline
                                    hekH Offline
                                    hek
                                    Admin
                                    wrote on last edited by
                                    #43

                                    Yes, they disappear when disabling DEBUG.

                                    1 Reply Last reply
                                    0
                                    • Dave DanD Offline
                                      Dave DanD Offline
                                      Dave Dan
                                      wrote on last edited by
                                      #44

                                      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!!!!

                                      1 Reply Last reply
                                      0
                                      • E Offline
                                        E Offline
                                        ewgor
                                        wrote on last edited by ewgor
                                        #45

                                        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!

                                        1 Reply Last reply
                                        0
                                        • E Offline
                                          E Offline
                                          ewgor
                                          wrote on last edited by
                                          #46

                                          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.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          6

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular