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. Serial Gateway connection to Openhab

Serial Gateway connection to Openhab

Scheduled Pinned Locked Moved OpenHAB
development ope
86 Posts 16 Posters 81.1k Views 10 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.
  • T TimO

    @C.r.a.z.y. : I don't think this problem is related to OpenHab.

    In my case the output looks like this:

    2015-03-09 11:50:45.780 [INFO ] [runtime.busevents             ] - Light_Corridor_First_Floor received command ON
    2015-03-09 11:50:45.782 [INFO ] [runtime.busevents             ] - Arduino received command 102;2;1;0;2;1
    
    ArduinoUpdate -> 102;2;1;0;2;1
    2015-03-09 11:50:45.990 [INFO ] [runtime.busevents             ] - Arduino state updated to 0;0;3;0;9;send: 0-0-102-102 s=2,c=1,t=2,pt=0,l=1,st=ok:1
    
    ArduinoUpdate -> 0;0;3;0;9;send: 0-0-102-102 s=2,c=1,t=2,pt=0,l=1,st=ok:1
    

    OpenHab does not interpret the response (fail/ok). It is something I need to work on.

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

    @TimO I think so maybe rpi usb problem...

    Is there a newer file for org.openhab.binding.serial_1.6.0.201411271703

    T 1 Reply Last reply
    0
    • C C.r.a.z.y.

      @TimO I think so maybe rpi usb problem...

      Is there a newer file for org.openhab.binding.serial_1.6.0.201411271703

      T Offline
      T Offline
      TimO
      Hero Member
      wrote on last edited by
      #30

      @C.r.a.z.y.: Yes, I'm using the current NIGHTLY from cloudbees: https://openhab.ci.cloudbees.com/job/openHAB/

      You need to change:

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

      To:

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

      The communication between the Gateway and the Controller/OpenHab seems to work fine, but the answer from the Gateway is the wrong one. So changing the binding won't solve this problem.

      What is the serial output of the receiving node?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        C.r.a.z.y.
        wrote on last edited by
        #31

        @tim @hek
        Hek adviced me to download current 1.4 v in a topic and i did. I was using 1.4 which downloaded 2 months ago.
        After that;
        My old node's sketch(or api) was not the same with my new serial controller sketch 1.4
        I reupload sketches to every node and gateway still I am not sure with this solution but today my nodes worked fine.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          l154
          wrote on last edited by
          #32

          Hi all,
          I wrote some rules for serial gateway to openhab, temp, hum, switch, dimmer and some internal commands are working without a problem. I don't have too much time to develop this for other devices.
          I'm not a java programmer so if I made some mistakes feel free to comment.
          The goal is to write a rules that will be easily expanded to other devices.
          I create a has map table where I define mappings ID to item name and inversely.
          test.rules file:

          import org.openhab.core.library.types.*
          import org.openhab.core.persistence.*
          import org.openhab.model.script.actions.*
          import java.util.*
          import org.eclipse.xtext.xbase.lib.*
          import org.openhab.core.items.*
          
          var String ArduinoUpdate = ""
          var String sketchName = ""
          var int V_TEMP = 0
          var int V_HUM = 1
          var int V_LIGHT = 2
          var int V_DIMMER = 3
          var int V_PRESSURE = 4
          var int V_FORECAST = 5
          var int V_RAIN = 6
          var int V_RAINRATE = 7
          var int V_WIND = 8
          var int V_GUST = 9
          var int V_DIRECTION = 10
          var int V_UV = 11
          var int V_WEIGHT = 12
          var int V_DISTANCE = 13
          var int V_IMPEDANCE = 14
          var int V_ARMED = 15
          var int V_TRIPPED = 16
          var int V_WATT = 17
          var int V_KWH = 18
          var int V_SCENE_ON = 19
          var int V_SCENE_OFF = 20
          var int V_HEATER = 21
          var int V_HEATER_SW = 22
          var int V_LIGHT_LEVEL = 23
          var int V_VAR1 = 24
          var int V_VAR2 = 25
          var int V_VAR3 = 26
          var int V_VAR4 = 27
          var int V_VAR5 = 28
          var int V_UP = 29
          var int V_DOWN = 30
          var int V_STOP = 31
          var int V_IR_SEND = 32
          var int V_IR_RECEIVE = 33
          var int V_FLOW = 34
          var int V_VOLUME = 35
          var int V_LOCK_STATUS = 36
          var int V_DUST_LEVEL = 37
          var int V_VOLTAGE = 38
          var int V_CURRENT = 39
          var int msgPresentation = 0
          var int msgSet = 1
          var int msgReq = 2
          var int msgInternal = 3
          var int msgStream = 4
          var int alarmArmor = 1
          // Internal Commands
          
          var int I_BATTERY_LEVEL = 0
          var int I_TIME = 1
          var int I_VERSION = 2
          var int I_ID_REQUEST = 3
          var int I_ID_RESPONSE = 4
          var int I_INCLUSION_MODE = 5
          var int I_CONFIG = 6
          var int I_FIND_PARENT = 7
          var int I_FIND_PARENT_RESPONSE = 8
          var int I_LOG_MESSAGE = 9
          var int I_CHILDREN = 10
          var int I_SKETCH_NAME = 11
          var int I_SKETCH_VERSION = 12
          var int I_REBOOT = 13
          var int I_GATEWAY_READY = 14
          // Mappings
          var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
          	"21;1;" -> "tempSalon01", 
          	"tempSalon01" -> "21;1;",
          	"21;0;" -> "humSalon01", 
          	"humSalon01" -> "21;0;",
          	"22;0;" -> "plugStrip01s12", 
          	"plugStrip01s12" -> "22;0;",
          	"22;1;" -> "plugStrip01s34", 
          	"plugStrip01s34" -> "22;1;",
          	"20;0;" -> "lightSalonCeiling00", 
          	"lightSalonCeiling00" -> "20;0;",
          	"20;1;" -> "lightSalonCeiling01", 
          	"lightSalonCeiling01" -> "20;1;",
          	"20;2;" -> "lightSalonCeiling02", 
          	"lightSalonCeiling02" -> "20;2;",
          	"20;3;" -> "lightSalonCeiling03", 
          	"lightSalonCeiling03" -> "20;3;",
          	"20;4;" -> "lightSalonCeiling04", 
          	"lightSalonCeiling04" -> "20;4;",
          	"10;4;" -> "lightBar04", 
          	"lightBar04" -> "10;4;",
          	"10;0;" -> "lightKitchenCabinet00", 
          	"lightKitchenCabinet00" -> "10;0;",
          	"10;1;" -> "lightKitchenCabinet01", 
          	"lightKitchenCabinet01" -> "10;1;",
          	"10;2;" -> "lightKitchenCabinet02", 
          	"lightKitchenCabinet02" -> "10;2;",
          	"10;3;" -> "lightKitchenCabinet03", 
          	"lightKitchenCabinet03" -> "10;3;",
          	"20;255;" -> "sensorLRCDimmer", 
          	"21;255;" -> "sensorLRHumTemp", 
          	"22;255;" -> "sensorLRStripPlug01", 
          	"10;255;" -> "sensorKCLight"
          
          )
          // dimmer function
          val org.eclipse.xtext.xbase.lib.Functions$Function5 dimmerOperation = [
          	org.openhab.core.library.items.DimmerItem relayItem, 
          	org.openhab.core.library.items.StringItem arduinoItem, 
          	String arduinoDevMap,
          	String receivedCommand,
          	Integer subType|
          	var Number percent = 0
          	if(relayItem.state instanceof DecimalType) percent = relayItem.state as DecimalType
          	if(receivedCommand==INCREASE) percent = percent + 5
          	if(receivedCommand==DECREASE) percent = percent - 5
          	if(receivedCommand==ON) percent = 100       
          	if(receivedCommand==OFF) percent = 0        
          	if(percent<0)   percent = 0
          	if(percent>100) percent = 100
          	
          	println ("Function: dimmerOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + percent )
          	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + percent + "\n")
          ]
          //switch function
          val org.eclipse.xtext.xbase.lib.Functions$Function4 switchOperation = [
          	org.openhab.core.library.items.SwitchItem relayItem, 
          	org.openhab.core.library.items.StringItem arduinoItem, 
          	String arduinoDevMap,
          	Integer subType|
          	var Integer state = 0
                  if (relayItem.state == OFF) {
          		state = 0 
          	}
          	else {
          		state = 1
          	}
          	println ("Function: switchOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + state )
          	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + state + "\n")
          ]
          
          //receiving msg from mysensors gateway
          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 == 1 ){
          				if (subType == V_TEMP){
          					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          					println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
          					}
          				if (subType == V_HUM){
          					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          					println ("HUM item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
          					}
          				if (subType == V_DIMMER){
          					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
          					println ("Dimmer item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Dimmer: " + msg )
          						}
          				if (subType == V_LIGHT){
          					var String state
          					var Integer statusInt = new Integer(message.get(5))
          					if(statusInt == 1) { 
          						state = "ON"
          						} 
          					else { 
          						state = "OFF" 
          						}
          					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
          					println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
          					}
          				}
          			// 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=""
          					}
          				}
          			}	
          		}
          end
          
          
          
          rule "lightBar04 Switch Rule"
          	when
          		Item lightBar04 changed
          	then
          		switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)			
          end	
          
          rule "lightKitchenCabinet00 Switch Rule"
          	when
          		Item lightKitchenCabinet00 changed
          	then
          		switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)			
          end	
          
          rule "lightKitchenCabinet01 Switch Rule"
          	when
          		Item lightKitchenCabinet01 changed
          	then
          		switchOperation.apply(lightKitchenCabinet01, Arduino, sensorToItemsMap.get("lightKitchenCabinet01"), V_LIGHT)			
          end	
          
          rule "lightKitchenCabinet02 Switch Rule"
          	when
          		Item lightKitchenCabinet02 changed
          	then
          		switchOperation.apply(lightKitchenCabinet02, Arduino, sensorToItemsMap.get("lightKitchenCabinet02"), V_LIGHT)			
          end	
          
          rule "lightKitchenCabinet03 Switch Rule"
          	when
          		Item lightKitchenCabinet03 changed
          	then
          		switchOperation.apply(lightKitchenCabinet03, Arduino, sensorToItemsMap.get("lightKitchenCabinet03"), V_LIGHT)			
          end	
          
          rule "lightSalonCeiling00 Switch Rule"
          	when
          		Item lightSalonCeiling00 received command
          	then
          		if(lightSalonCeiling00.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
          		dimmerOperation.apply(lightSalonCeiling00, Arduino, sensorToItemsMap.get("lightSalonCeiling00"), receivedCommand, V_DIMMER)			
          		} 
          	end	
          rule "lightSalonCeiling01 Switch Rule"
          	when
          		Item lightSalonCeiling01 received command
          	then
          		if(lightSalonCeiling01.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
          		dimmerOperation.apply(lightSalonCeiling01, Arduino, sensorToItemsMap.get("lightSalonCeiling01"), receivedCommand, V_DIMMER)			
          		} 
          	end	
          rule "lightSalonCeiling02 Switch Rule"
          	when
          		Item lightSalonCeiling02 received command
          	then
          		if(lightSalonCeiling02.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
          		dimmerOperation.apply(lightSalonCeiling02, Arduino, sensorToItemsMap.get("lightSalonCeiling02"), receivedCommand, V_DIMMER)			
          		} 
          	end	
          rule "lightSalonCeiling03 Switch Rule"
          	when
          		Item lightSalonCeiling03 received command
          	then
          		if(lightSalonCeiling03.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
          		dimmerOperation.apply(lightSalonCeiling03, Arduino, sensorToItemsMap.get("lightSalonCeiling03"), receivedCommand, V_DIMMER)			
          		} 
          	end	
          rule "lightSalonCeiling04 Switch Rule"
          	when
          		Item lightSalonCeiling04 received command
          	then
          		if(lightSalonCeiling04.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
          		dimmerOperation.apply(lightSalonCeiling04, Arduino, sensorToItemsMap.get("lightSalonCeiling04"), receivedCommand, V_DIMMER)			
          		} 
          	end	
          
          rule "plugStrip01s12 Switch Rule"
          	when
          		Item plugStrip01s12 changed
          	then
          		switchOperation.apply(plugStrip01s12, Arduino, sensorToItemsMap.get("plugStrip01s12"), V_LIGHT)			
          end	
          
          
          rule "plugStrip01s34 Switch Rule"
          	when
          		Item plugStrip01s34 changed
          	then
          		switchOperation.apply(plugStrip01s34, Arduino, sensorToItemsMap.get("plugStrip01s34"), V_LIGHT)			
          end	
          

          my test.item

          String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
          Group All
          Group flat "Flat" <house>
          Group livingRoom "Living Room"  <sofa>  (All,flat)
          Group kitchen      "Kitchen" <kitchen>  (All,flat)
          Group corridor      "Corridor" <corridor>  (All,flat)
          Group bathroom      "Bathroom" <bath>  (All,flat)
          Group gmRoom  "Grandma Room" <smile>  (All,flat)
          Group weather   (All)
          Group status    (All)
          Group mysensors    (All)
          
          Group:Switch:OR(ON, OFF) kLights "Lights" <light> (All, kitchen)
          Group:Switch:OR(ON, OFF) kcLights "Cabinet Lights [(%d)]" <light> (All, kLights)
          Group:Switch:OR(ON, OFF) skcLights "Single Cabinet Lights [(%d)]" <light> (All)
          
          Group:Switch:OR(ON, OFF) lrLights "Lights" <light> (livingRoom)
          Group:Switch:OR(ON, OFF) lrcLights "Ceiling Lights [(%d)]" <light> (lrLights)
          
          Group:Switch:OR(ON, OFF) lrSockets "Sockets" <socket> (livingRoom)
          Group:Switch:OR(ON, OFF) lrPlugStrip "Sockets [(%d)]" <socket> (lrSockets)
          
          Group:Number:AVG humAndTemp "Avg. Room Humidity[%.1f %%] and Temperature [%.1f °C]" <temperature>
          Group:Number:AVG temperature "Avg. Room Temperature [%.1f °C]" <temperature> (status)
          Group:Number:AVG humidity "Avg. Room Humidity [%.1f %%]" <temperature> (status)
          
          
          Group:Switch:OR(ON, OFF) lights "All Lights [(%d)]" <light> (All)
          
          Number tempChartPeriod          "Chart Period"
          Number tempSalon01 "Temperature [%s °C]" <temperature> (temperature,humAndTemp)
          Number humSalon01 "Humidity [%s %%]" <temperature> (humidity,humAndTemp)
          Switch lightKitchenCabinet00	"Light 1" (lights, kcLights)
          Switch lightKitchenCabinet01	"Light 2" (lights, kcLights)
          Switch lightKitchenCabinet02	"Light 3" (lights, kcLights)
          Switch lightKitchenCabinet03	"Light 4" (lights, kcLights)
          
          Switch lightBar04		"Bar Lights" (lights, kLights, lrLights)
          
          Dimmer lightSalonCeiling00	"Light 1 [%s %%]" (lights, lrcLights)
          Dimmer lightSalonCeiling01	"Light 2 [%s %%]" (lights, lrcLights)
          Dimmer lightSalonCeiling02	"Light 3 [%s %%]" (lights, lrcLights)
          Dimmer lightSalonCeiling03	"Light 4 [%s %%]" (lights, lrcLights)
          Dimmer lightSalonCeiling04	"Light All [%s %%]" (lights,lrLights,allLights)
          Switch plugStrip01s12		"Sockets 1-2" <socket> (lrPlugStrip)
          Switch plugStrip01s34		"Sockets 3-4" <socket> (lrPlugStrip)
          
          String sensorLRCDimmer "Living Room Ceiling Light Sensor [%s]" (mysensors)
          String sensorLRStripPlug01 "Living Room Strip Plug 01 Sensor [%s]" (mysensors)
          String sensorLRHumTemp "Living Room Hum&Temp&Motion&Light  Sensor [%s]" (mysensors)
          String sensorKCLight "Kitchen&Bar Light Sensor [%s]" (mysensors)
          

          my test.sitemap

          sitemap demo label="Main Menu"
          {
          
          	Frame label="Home" {
          		Group label="Kitchen" icon="kitchen" {
          			Frame label="Kitchen" {
          				Group item=kLights label="Lights" {
          				Switch item=lightBar04 label="Bar Lights"
          				Switch item=kcLights label="Cabinet Lights"
          				Group item=kcLights 
          				}
          			}
          		}
          
          		Group item=livingRoom {
          			Frame label="Living Room" {
          				Group item=lrLights 
          				Group label="Sensors" icon="temperature" {
          					Text item=tempSalon01 valuecolor=[tempSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
          					Text item=humSalon01 valuecolor=[humSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
          					Switch item=tempChartPeriod label="Chart Period" mappings=[0="12 Hours", 1="Day", 2="Week", 3="Month"]
          					Chart item=humAndTemp period=12h refresh=5000 visibility=[tempChartPeriod==0,tempChartPeriod=="Uninitialized"]
          					Chart item=humAndTemp period=D refresh=1800 visibility=[tempChartPeriod==1]
          					Chart item=humAndTemp period=W refresh=3600 visibility=[tempChartPeriod==2]
          					Chart item=humAndTemp period=M refresh=7200 visibility=[tempChartPeriod==3]
          				}
          				Group item=lrPlugStrip
          			}
          		}
          		Group item=corridor 
          		Group item=bathroom icon="bath"
          		Group item=grandmotherRoom icon="smiley"
          	}
          
          	Frame label="Lights All"{
          		Switch item=lights mappings=[OFF="All Off"]
          		Group item=lights
          		Group item=mysensors
          	}
          
          E 1 Reply Last reply
          2
          • T Offline
            T Offline
            TimO
            Hero Member
            wrote on last edited by
            #33

            Cool! I will certainly adapt that! Thanks!

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

              This looks great. Far better than my rules. I like the approach with the hash table very much.

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jemish
                wrote on last edited by
                #35

                Can I get the Arduino uno code for this openhab serial binding?
                I want a like to see that how it will work.

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

                  @jemish : Just use this one: http://www.mysensors.org/build/serial_gateway

                  It is the standard serial gateway. Nothing special.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jemish
                    wrote on last edited by jemish
                    #37

                    At this link: http://www.mysensors.org/build/serial_gateway I got the arduino sketch,
                    but I want to know, this sketch is for main arduino that is connected to the raspberry pi via serial communication and other side it is connected to the nRF24L01.

                    If it is true than, I want to know which code is required at node side where I can ON or OFF LED and LIGHTS or DIMMER.

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      jemish
                      wrote on last edited by
                      #38

                      Hey.....please can anyone reply me?......please......

                      J 1 Reply Last reply
                      0
                      • J jemish

                        Hey.....please can anyone reply me?......please......

                        J Offline
                        J Offline
                        Jan Gatzke
                        wrote on last edited by
                        #39

                        @jemish This is to basic to earn an answer. I suggest you start reading at http://www.mysensors.org .

                        1 Reply Last reply
                        1
                        • J Offline
                          J Offline
                          jemish
                          wrote on last edited by
                          #40

                          hi,
                          I have a question, that how can I get feedback from our switchboard that is at our wall.

                          If I am on the light by pressing the switch at switchboard.

                          If in case I get the 5v from switchboard and give it to the Arduino, than how can I update state of switch in openhab.

                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            jemish
                            wrote on last edited by
                            #41

                            Hay, can any one try that.........feedback from switchboard

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

                              I would try to use something like this on the sensor connected to the switchboard:

                              http://www.mysensors.org/build/binary

                              This will send V_TRIPPED per default.

                              In the rules files you have to bring everything togehter:

                              if V_TRIPPED from sensor_id_xyz received
                              then update status of light switch

                              If you know what I mean. :-D

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                almj
                                wrote on last edited by
                                #43
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • L l154

                                  Hi all,
                                  I wrote some rules for serial gateway to openhab, temp, hum, switch, dimmer and some internal commands are working without a problem. I don't have too much time to develop this for other devices.
                                  I'm not a java programmer so if I made some mistakes feel free to comment.
                                  The goal is to write a rules that will be easily expanded to other devices.
                                  I create a has map table where I define mappings ID to item name and inversely.
                                  test.rules file:

                                  import org.openhab.core.library.types.*
                                  import org.openhab.core.persistence.*
                                  import org.openhab.model.script.actions.*
                                  import java.util.*
                                  import org.eclipse.xtext.xbase.lib.*
                                  import org.openhab.core.items.*
                                  
                                  var String ArduinoUpdate = ""
                                  var String sketchName = ""
                                  var int V_TEMP = 0
                                  var int V_HUM = 1
                                  var int V_LIGHT = 2
                                  var int V_DIMMER = 3
                                  var int V_PRESSURE = 4
                                  var int V_FORECAST = 5
                                  var int V_RAIN = 6
                                  var int V_RAINRATE = 7
                                  var int V_WIND = 8
                                  var int V_GUST = 9
                                  var int V_DIRECTION = 10
                                  var int V_UV = 11
                                  var int V_WEIGHT = 12
                                  var int V_DISTANCE = 13
                                  var int V_IMPEDANCE = 14
                                  var int V_ARMED = 15
                                  var int V_TRIPPED = 16
                                  var int V_WATT = 17
                                  var int V_KWH = 18
                                  var int V_SCENE_ON = 19
                                  var int V_SCENE_OFF = 20
                                  var int V_HEATER = 21
                                  var int V_HEATER_SW = 22
                                  var int V_LIGHT_LEVEL = 23
                                  var int V_VAR1 = 24
                                  var int V_VAR2 = 25
                                  var int V_VAR3 = 26
                                  var int V_VAR4 = 27
                                  var int V_VAR5 = 28
                                  var int V_UP = 29
                                  var int V_DOWN = 30
                                  var int V_STOP = 31
                                  var int V_IR_SEND = 32
                                  var int V_IR_RECEIVE = 33
                                  var int V_FLOW = 34
                                  var int V_VOLUME = 35
                                  var int V_LOCK_STATUS = 36
                                  var int V_DUST_LEVEL = 37
                                  var int V_VOLTAGE = 38
                                  var int V_CURRENT = 39
                                  var int msgPresentation = 0
                                  var int msgSet = 1
                                  var int msgReq = 2
                                  var int msgInternal = 3
                                  var int msgStream = 4
                                  var int alarmArmor = 1
                                  // Internal Commands
                                  
                                  var int I_BATTERY_LEVEL = 0
                                  var int I_TIME = 1
                                  var int I_VERSION = 2
                                  var int I_ID_REQUEST = 3
                                  var int I_ID_RESPONSE = 4
                                  var int I_INCLUSION_MODE = 5
                                  var int I_CONFIG = 6
                                  var int I_FIND_PARENT = 7
                                  var int I_FIND_PARENT_RESPONSE = 8
                                  var int I_LOG_MESSAGE = 9
                                  var int I_CHILDREN = 10
                                  var int I_SKETCH_NAME = 11
                                  var int I_SKETCH_VERSION = 12
                                  var int I_REBOOT = 13
                                  var int I_GATEWAY_READY = 14
                                  // Mappings
                                  var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
                                  	"21;1;" -> "tempSalon01", 
                                  	"tempSalon01" -> "21;1;",
                                  	"21;0;" -> "humSalon01", 
                                  	"humSalon01" -> "21;0;",
                                  	"22;0;" -> "plugStrip01s12", 
                                  	"plugStrip01s12" -> "22;0;",
                                  	"22;1;" -> "plugStrip01s34", 
                                  	"plugStrip01s34" -> "22;1;",
                                  	"20;0;" -> "lightSalonCeiling00", 
                                  	"lightSalonCeiling00" -> "20;0;",
                                  	"20;1;" -> "lightSalonCeiling01", 
                                  	"lightSalonCeiling01" -> "20;1;",
                                  	"20;2;" -> "lightSalonCeiling02", 
                                  	"lightSalonCeiling02" -> "20;2;",
                                  	"20;3;" -> "lightSalonCeiling03", 
                                  	"lightSalonCeiling03" -> "20;3;",
                                  	"20;4;" -> "lightSalonCeiling04", 
                                  	"lightSalonCeiling04" -> "20;4;",
                                  	"10;4;" -> "lightBar04", 
                                  	"lightBar04" -> "10;4;",
                                  	"10;0;" -> "lightKitchenCabinet00", 
                                  	"lightKitchenCabinet00" -> "10;0;",
                                  	"10;1;" -> "lightKitchenCabinet01", 
                                  	"lightKitchenCabinet01" -> "10;1;",
                                  	"10;2;" -> "lightKitchenCabinet02", 
                                  	"lightKitchenCabinet02" -> "10;2;",
                                  	"10;3;" -> "lightKitchenCabinet03", 
                                  	"lightKitchenCabinet03" -> "10;3;",
                                  	"20;255;" -> "sensorLRCDimmer", 
                                  	"21;255;" -> "sensorLRHumTemp", 
                                  	"22;255;" -> "sensorLRStripPlug01", 
                                  	"10;255;" -> "sensorKCLight"
                                  
                                  )
                                  // dimmer function
                                  val org.eclipse.xtext.xbase.lib.Functions$Function5 dimmerOperation = [
                                  	org.openhab.core.library.items.DimmerItem relayItem, 
                                  	org.openhab.core.library.items.StringItem arduinoItem, 
                                  	String arduinoDevMap,
                                  	String receivedCommand,
                                  	Integer subType|
                                  	var Number percent = 0
                                  	if(relayItem.state instanceof DecimalType) percent = relayItem.state as DecimalType
                                  	if(receivedCommand==INCREASE) percent = percent + 5
                                  	if(receivedCommand==DECREASE) percent = percent - 5
                                  	if(receivedCommand==ON) percent = 100       
                                  	if(receivedCommand==OFF) percent = 0        
                                  	if(percent<0)   percent = 0
                                  	if(percent>100) percent = 100
                                  	
                                  	println ("Function: dimmerOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + percent )
                                  	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + percent + "\n")
                                  ]
                                  //switch function
                                  val org.eclipse.xtext.xbase.lib.Functions$Function4 switchOperation = [
                                  	org.openhab.core.library.items.SwitchItem relayItem, 
                                  	org.openhab.core.library.items.StringItem arduinoItem, 
                                  	String arduinoDevMap,
                                  	Integer subType|
                                  	var Integer state = 0
                                          if (relayItem.state == OFF) {
                                  		state = 0 
                                  	}
                                  	else {
                                  		state = 1
                                  	}
                                  	println ("Function: switchOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + state )
                                  	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + state + "\n")
                                  ]
                                  
                                  //receiving msg from mysensors gateway
                                  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 == 1 ){
                                  				if (subType == V_TEMP){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
                                  					}
                                  				if (subType == V_HUM){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("HUM item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
                                  					}
                                  				if (subType == V_DIMMER){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("Dimmer item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Dimmer: " + msg )
                                  						}
                                  				if (subType == V_LIGHT){
                                  					var String state
                                  					var Integer statusInt = new Integer(message.get(5))
                                  					if(statusInt == 1) { 
                                  						state = "ON"
                                  						} 
                                  					else { 
                                  						state = "OFF" 
                                  						}
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
                                  					println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
                                  					}
                                  				}
                                  			// 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=""
                                  					}
                                  				}
                                  			}	
                                  		}
                                  end
                                  
                                  
                                  
                                  rule "lightBar04 Switch Rule"
                                  	when
                                  		Item lightBar04 changed
                                  	then
                                  		switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet00 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet00 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet01 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet01 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet01, Arduino, sensorToItemsMap.get("lightKitchenCabinet01"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet02 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet02 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet02, Arduino, sensorToItemsMap.get("lightKitchenCabinet02"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet03 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet03 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet03, Arduino, sensorToItemsMap.get("lightKitchenCabinet03"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightSalonCeiling00 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling00 received command
                                  	then
                                  		if(lightSalonCeiling00.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling00, Arduino, sensorToItemsMap.get("lightSalonCeiling00"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling01 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling01 received command
                                  	then
                                  		if(lightSalonCeiling01.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling01, Arduino, sensorToItemsMap.get("lightSalonCeiling01"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling02 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling02 received command
                                  	then
                                  		if(lightSalonCeiling02.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling02, Arduino, sensorToItemsMap.get("lightSalonCeiling02"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling03 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling03 received command
                                  	then
                                  		if(lightSalonCeiling03.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling03, Arduino, sensorToItemsMap.get("lightSalonCeiling03"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling04 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling04 received command
                                  	then
                                  		if(lightSalonCeiling04.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling04, Arduino, sensorToItemsMap.get("lightSalonCeiling04"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  
                                  rule "plugStrip01s12 Switch Rule"
                                  	when
                                  		Item plugStrip01s12 changed
                                  	then
                                  		switchOperation.apply(plugStrip01s12, Arduino, sensorToItemsMap.get("plugStrip01s12"), V_LIGHT)			
                                  end	
                                  
                                  
                                  rule "plugStrip01s34 Switch Rule"
                                  	when
                                  		Item plugStrip01s34 changed
                                  	then
                                  		switchOperation.apply(plugStrip01s34, Arduino, sensorToItemsMap.get("plugStrip01s34"), V_LIGHT)			
                                  end	
                                  

                                  my test.item

                                  String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
                                  Group All
                                  Group flat "Flat" <house>
                                  Group livingRoom "Living Room"  <sofa>  (All,flat)
                                  Group kitchen      "Kitchen" <kitchen>  (All,flat)
                                  Group corridor      "Corridor" <corridor>  (All,flat)
                                  Group bathroom      "Bathroom" <bath>  (All,flat)
                                  Group gmRoom  "Grandma Room" <smile>  (All,flat)
                                  Group weather   (All)
                                  Group status    (All)
                                  Group mysensors    (All)
                                  
                                  Group:Switch:OR(ON, OFF) kLights "Lights" <light> (All, kitchen)
                                  Group:Switch:OR(ON, OFF) kcLights "Cabinet Lights [(%d)]" <light> (All, kLights)
                                  Group:Switch:OR(ON, OFF) skcLights "Single Cabinet Lights [(%d)]" <light> (All)
                                  
                                  Group:Switch:OR(ON, OFF) lrLights "Lights" <light> (livingRoom)
                                  Group:Switch:OR(ON, OFF) lrcLights "Ceiling Lights [(%d)]" <light> (lrLights)
                                  
                                  Group:Switch:OR(ON, OFF) lrSockets "Sockets" <socket> (livingRoom)
                                  Group:Switch:OR(ON, OFF) lrPlugStrip "Sockets [(%d)]" <socket> (lrSockets)
                                  
                                  Group:Number:AVG humAndTemp "Avg. Room Humidity[%.1f %%] and Temperature [%.1f °C]" <temperature>
                                  Group:Number:AVG temperature "Avg. Room Temperature [%.1f °C]" <temperature> (status)
                                  Group:Number:AVG humidity "Avg. Room Humidity [%.1f %%]" <temperature> (status)
                                  
                                  
                                  Group:Switch:OR(ON, OFF) lights "All Lights [(%d)]" <light> (All)
                                  
                                  Number tempChartPeriod          "Chart Period"
                                  Number tempSalon01 "Temperature [%s °C]" <temperature> (temperature,humAndTemp)
                                  Number humSalon01 "Humidity [%s %%]" <temperature> (humidity,humAndTemp)
                                  Switch lightKitchenCabinet00	"Light 1" (lights, kcLights)
                                  Switch lightKitchenCabinet01	"Light 2" (lights, kcLights)
                                  Switch lightKitchenCabinet02	"Light 3" (lights, kcLights)
                                  Switch lightKitchenCabinet03	"Light 4" (lights, kcLights)
                                  
                                  Switch lightBar04		"Bar Lights" (lights, kLights, lrLights)
                                  
                                  Dimmer lightSalonCeiling00	"Light 1 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling01	"Light 2 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling02	"Light 3 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling03	"Light 4 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling04	"Light All [%s %%]" (lights,lrLights,allLights)
                                  Switch plugStrip01s12		"Sockets 1-2" <socket> (lrPlugStrip)
                                  Switch plugStrip01s34		"Sockets 3-4" <socket> (lrPlugStrip)
                                  
                                  String sensorLRCDimmer "Living Room Ceiling Light Sensor [%s]" (mysensors)
                                  String sensorLRStripPlug01 "Living Room Strip Plug 01 Sensor [%s]" (mysensors)
                                  String sensorLRHumTemp "Living Room Hum&Temp&Motion&Light  Sensor [%s]" (mysensors)
                                  String sensorKCLight "Kitchen&Bar Light Sensor [%s]" (mysensors)
                                  

                                  my test.sitemap

                                  sitemap demo label="Main Menu"
                                  {
                                  
                                  	Frame label="Home" {
                                  		Group label="Kitchen" icon="kitchen" {
                                  			Frame label="Kitchen" {
                                  				Group item=kLights label="Lights" {
                                  				Switch item=lightBar04 label="Bar Lights"
                                  				Switch item=kcLights label="Cabinet Lights"
                                  				Group item=kcLights 
                                  				}
                                  			}
                                  		}
                                  
                                  		Group item=livingRoom {
                                  			Frame label="Living Room" {
                                  				Group item=lrLights 
                                  				Group label="Sensors" icon="temperature" {
                                  					Text item=tempSalon01 valuecolor=[tempSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
                                  					Text item=humSalon01 valuecolor=[humSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
                                  					Switch item=tempChartPeriod label="Chart Period" mappings=[0="12 Hours", 1="Day", 2="Week", 3="Month"]
                                  					Chart item=humAndTemp period=12h refresh=5000 visibility=[tempChartPeriod==0,tempChartPeriod=="Uninitialized"]
                                  					Chart item=humAndTemp period=D refresh=1800 visibility=[tempChartPeriod==1]
                                  					Chart item=humAndTemp period=W refresh=3600 visibility=[tempChartPeriod==2]
                                  					Chart item=humAndTemp period=M refresh=7200 visibility=[tempChartPeriod==3]
                                  				}
                                  				Group item=lrPlugStrip
                                  			}
                                  		}
                                  		Group item=corridor 
                                  		Group item=bathroom icon="bath"
                                  		Group item=grandmotherRoom icon="smiley"
                                  	}
                                  
                                  	Frame label="Lights All"{
                                  		Switch item=lights mappings=[OFF="All Off"]
                                  		Group item=lights
                                  		Group item=mysensors
                                  	}
                                  
                                  E Offline
                                  E Offline
                                  ewgor
                                  wrote on last edited by
                                  #44

                                  @l154 said:

                                  Hi all,
                                  I wrote some rules for serial gateway to openhab, temp, hum, switch, dimmer and some internal commands are working without a problem. I don't have too much time to develop this for other devices.
                                  I'm not a java programmer so if I made some mistakes feel free to comment.
                                  The goal is to write a rules that will be easily expanded to other devices.
                                  I create a has map table where I define mappings ID to item name and inversely.
                                  test.rules file:

                                  import org.openhab.core.library.types.*
                                  import org.openhab.core.persistence.*
                                  import org.openhab.model.script.actions.*
                                  import java.util.*
                                  import org.eclipse.xtext.xbase.lib.*
                                  import org.openhab.core.items.*
                                  
                                  var String ArduinoUpdate = ""
                                  var String sketchName = ""
                                  var int V_TEMP = 0
                                  var int V_HUM = 1
                                  var int V_LIGHT = 2
                                  var int V_DIMMER = 3
                                  var int V_PRESSURE = 4
                                  var int V_FORECAST = 5
                                  var int V_RAIN = 6
                                  var int V_RAINRATE = 7
                                  var int V_WIND = 8
                                  var int V_GUST = 9
                                  var int V_DIRECTION = 10
                                  var int V_UV = 11
                                  var int V_WEIGHT = 12
                                  var int V_DISTANCE = 13
                                  var int V_IMPEDANCE = 14
                                  var int V_ARMED = 15
                                  var int V_TRIPPED = 16
                                  var int V_WATT = 17
                                  var int V_KWH = 18
                                  var int V_SCENE_ON = 19
                                  var int V_SCENE_OFF = 20
                                  var int V_HEATER = 21
                                  var int V_HEATER_SW = 22
                                  var int V_LIGHT_LEVEL = 23
                                  var int V_VAR1 = 24
                                  var int V_VAR2 = 25
                                  var int V_VAR3 = 26
                                  var int V_VAR4 = 27
                                  var int V_VAR5 = 28
                                  var int V_UP = 29
                                  var int V_DOWN = 30
                                  var int V_STOP = 31
                                  var int V_IR_SEND = 32
                                  var int V_IR_RECEIVE = 33
                                  var int V_FLOW = 34
                                  var int V_VOLUME = 35
                                  var int V_LOCK_STATUS = 36
                                  var int V_DUST_LEVEL = 37
                                  var int V_VOLTAGE = 38
                                  var int V_CURRENT = 39
                                  var int msgPresentation = 0
                                  var int msgSet = 1
                                  var int msgReq = 2
                                  var int msgInternal = 3
                                  var int msgStream = 4
                                  var int alarmArmor = 1
                                  // Internal Commands
                                  
                                  var int I_BATTERY_LEVEL = 0
                                  var int I_TIME = 1
                                  var int I_VERSION = 2
                                  var int I_ID_REQUEST = 3
                                  var int I_ID_RESPONSE = 4
                                  var int I_INCLUSION_MODE = 5
                                  var int I_CONFIG = 6
                                  var int I_FIND_PARENT = 7
                                  var int I_FIND_PARENT_RESPONSE = 8
                                  var int I_LOG_MESSAGE = 9
                                  var int I_CHILDREN = 10
                                  var int I_SKETCH_NAME = 11
                                  var int I_SKETCH_VERSION = 12
                                  var int I_REBOOT = 13
                                  var int I_GATEWAY_READY = 14
                                  // Mappings
                                  var HashMap<String, String> sensorToItemsMap = newLinkedHashMap(
                                  	"21;1;" -> "tempSalon01", 
                                  	"tempSalon01" -> "21;1;",
                                  	"21;0;" -> "humSalon01", 
                                  	"humSalon01" -> "21;0;",
                                  	"22;0;" -> "plugStrip01s12", 
                                  	"plugStrip01s12" -> "22;0;",
                                  	"22;1;" -> "plugStrip01s34", 
                                  	"plugStrip01s34" -> "22;1;",
                                  	"20;0;" -> "lightSalonCeiling00", 
                                  	"lightSalonCeiling00" -> "20;0;",
                                  	"20;1;" -> "lightSalonCeiling01", 
                                  	"lightSalonCeiling01" -> "20;1;",
                                  	"20;2;" -> "lightSalonCeiling02", 
                                  	"lightSalonCeiling02" -> "20;2;",
                                  	"20;3;" -> "lightSalonCeiling03", 
                                  	"lightSalonCeiling03" -> "20;3;",
                                  	"20;4;" -> "lightSalonCeiling04", 
                                  	"lightSalonCeiling04" -> "20;4;",
                                  	"10;4;" -> "lightBar04", 
                                  	"lightBar04" -> "10;4;",
                                  	"10;0;" -> "lightKitchenCabinet00", 
                                  	"lightKitchenCabinet00" -> "10;0;",
                                  	"10;1;" -> "lightKitchenCabinet01", 
                                  	"lightKitchenCabinet01" -> "10;1;",
                                  	"10;2;" -> "lightKitchenCabinet02", 
                                  	"lightKitchenCabinet02" -> "10;2;",
                                  	"10;3;" -> "lightKitchenCabinet03", 
                                  	"lightKitchenCabinet03" -> "10;3;",
                                  	"20;255;" -> "sensorLRCDimmer", 
                                  	"21;255;" -> "sensorLRHumTemp", 
                                  	"22;255;" -> "sensorLRStripPlug01", 
                                  	"10;255;" -> "sensorKCLight"
                                  
                                  )
                                  // dimmer function
                                  val org.eclipse.xtext.xbase.lib.Functions$Function5 dimmerOperation = [
                                  	org.openhab.core.library.items.DimmerItem relayItem, 
                                  	org.openhab.core.library.items.StringItem arduinoItem, 
                                  	String arduinoDevMap,
                                  	String receivedCommand,
                                  	Integer subType|
                                  	var Number percent = 0
                                  	if(relayItem.state instanceof DecimalType) percent = relayItem.state as DecimalType
                                  	if(receivedCommand==INCREASE) percent = percent + 5
                                  	if(receivedCommand==DECREASE) percent = percent - 5
                                  	if(receivedCommand==ON) percent = 100       
                                  	if(receivedCommand==OFF) percent = 0        
                                  	if(percent<0)   percent = 0
                                  	if(percent>100) percent = 100
                                  	
                                  	println ("Function: dimmerOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + percent )
                                  	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + percent + "\n")
                                  ]
                                  //switch function
                                  val org.eclipse.xtext.xbase.lib.Functions$Function4 switchOperation = [
                                  	org.openhab.core.library.items.SwitchItem relayItem, 
                                  	org.openhab.core.library.items.StringItem arduinoItem, 
                                  	String arduinoDevMap,
                                  	Integer subType|
                                  	var Integer state = 0
                                          if (relayItem.state == OFF) {
                                  		state = 0 
                                  	}
                                  	else {
                                  		state = 1
                                  	}
                                  	println ("Function: switchOperation >> "+arduinoDevMap + "1;1;" + subType + ";" + state )
                                  	arduinoItem.sendCommand(arduinoDevMap + "1;0;" + subType + ";" + state + "\n")
                                  ]
                                  
                                  //receiving msg from mysensors gateway
                                  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 == 1 ){
                                  				if (subType == V_TEMP){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("Temp item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " temp: " + msg )
                                  					}
                                  				if (subType == V_HUM){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("HUM item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " hum: " + msg )
                                  					}
                                  				if (subType == V_DIMMER){
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), msg)
                                  					println ("Dimmer item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Dimmer: " + msg )
                                  						}
                                  				if (subType == V_LIGHT){
                                  					var String state
                                  					var Integer statusInt = new Integer(message.get(5))
                                  					if(statusInt == 1) { 
                                  						state = "ON"
                                  						} 
                                  					else { 
                                  						state = "OFF" 
                                  						}
                                  					postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), state)
                                  					println ("Light Item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " Light: " + state )
                                  					}
                                  				}
                                  			// 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=""
                                  					}
                                  				}
                                  			}	
                                  		}
                                  end
                                  
                                  
                                  
                                  rule "lightBar04 Switch Rule"
                                  	when
                                  		Item lightBar04 changed
                                  	then
                                  		switchOperation.apply(lightBar04, Arduino, sensorToItemsMap.get("lightBar04"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet00 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet00 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet00, Arduino, sensorToItemsMap.get("lightKitchenCabinet00"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet01 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet01 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet01, Arduino, sensorToItemsMap.get("lightKitchenCabinet01"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet02 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet02 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet02, Arduino, sensorToItemsMap.get("lightKitchenCabinet02"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightKitchenCabinet03 Switch Rule"
                                  	when
                                  		Item lightKitchenCabinet03 changed
                                  	then
                                  		switchOperation.apply(lightKitchenCabinet03, Arduino, sensorToItemsMap.get("lightKitchenCabinet03"), V_LIGHT)			
                                  end	
                                  
                                  rule "lightSalonCeiling00 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling00 received command
                                  	then
                                  		if(lightSalonCeiling00.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling00, Arduino, sensorToItemsMap.get("lightSalonCeiling00"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling01 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling01 received command
                                  	then
                                  		if(lightSalonCeiling01.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling01, Arduino, sensorToItemsMap.get("lightSalonCeiling01"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling02 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling02 received command
                                  	then
                                  		if(lightSalonCeiling02.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling02, Arduino, sensorToItemsMap.get("lightSalonCeiling02"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling03 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling03 received command
                                  	then
                                  		if(lightSalonCeiling03.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling03, Arduino, sensorToItemsMap.get("lightSalonCeiling03"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  rule "lightSalonCeiling04 Switch Rule"
                                  	when
                                  		Item lightSalonCeiling04 received command
                                  	then
                                  		if(lightSalonCeiling04.state instanceof DecimalType || receivedCommand==INCREASE || receivedCommand==DECREASE){
                                  		dimmerOperation.apply(lightSalonCeiling04, Arduino, sensorToItemsMap.get("lightSalonCeiling04"), receivedCommand, V_DIMMER)			
                                  		} 
                                  	end	
                                  
                                  rule "plugStrip01s12 Switch Rule"
                                  	when
                                  		Item plugStrip01s12 changed
                                  	then
                                  		switchOperation.apply(plugStrip01s12, Arduino, sensorToItemsMap.get("plugStrip01s12"), V_LIGHT)			
                                  end	
                                  
                                  
                                  rule "plugStrip01s34 Switch Rule"
                                  	when
                                  		Item plugStrip01s34 changed
                                  	then
                                  		switchOperation.apply(plugStrip01s34, Arduino, sensorToItemsMap.get("plugStrip01s34"), V_LIGHT)			
                                  end	
                                  

                                  my test.item

                                  String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }
                                  Group All
                                  Group flat "Flat" <house>
                                  Group livingRoom "Living Room"  <sofa>  (All,flat)
                                  Group kitchen      "Kitchen" <kitchen>  (All,flat)
                                  Group corridor      "Corridor" <corridor>  (All,flat)
                                  Group bathroom      "Bathroom" <bath>  (All,flat)
                                  Group gmRoom  "Grandma Room" <smile>  (All,flat)
                                  Group weather   (All)
                                  Group status    (All)
                                  Group mysensors    (All)
                                  
                                  Group:Switch:OR(ON, OFF) kLights "Lights" <light> (All, kitchen)
                                  Group:Switch:OR(ON, OFF) kcLights "Cabinet Lights [(%d)]" <light> (All, kLights)
                                  Group:Switch:OR(ON, OFF) skcLights "Single Cabinet Lights [(%d)]" <light> (All)
                                  
                                  Group:Switch:OR(ON, OFF) lrLights "Lights" <light> (livingRoom)
                                  Group:Switch:OR(ON, OFF) lrcLights "Ceiling Lights [(%d)]" <light> (lrLights)
                                  
                                  Group:Switch:OR(ON, OFF) lrSockets "Sockets" <socket> (livingRoom)
                                  Group:Switch:OR(ON, OFF) lrPlugStrip "Sockets [(%d)]" <socket> (lrSockets)
                                  
                                  Group:Number:AVG humAndTemp "Avg. Room Humidity[%.1f %%] and Temperature [%.1f °C]" <temperature>
                                  Group:Number:AVG temperature "Avg. Room Temperature [%.1f °C]" <temperature> (status)
                                  Group:Number:AVG humidity "Avg. Room Humidity [%.1f %%]" <temperature> (status)
                                  
                                  
                                  Group:Switch:OR(ON, OFF) lights "All Lights [(%d)]" <light> (All)
                                  
                                  Number tempChartPeriod          "Chart Period"
                                  Number tempSalon01 "Temperature [%s °C]" <temperature> (temperature,humAndTemp)
                                  Number humSalon01 "Humidity [%s %%]" <temperature> (humidity,humAndTemp)
                                  Switch lightKitchenCabinet00	"Light 1" (lights, kcLights)
                                  Switch lightKitchenCabinet01	"Light 2" (lights, kcLights)
                                  Switch lightKitchenCabinet02	"Light 3" (lights, kcLights)
                                  Switch lightKitchenCabinet03	"Light 4" (lights, kcLights)
                                  
                                  Switch lightBar04		"Bar Lights" (lights, kLights, lrLights)
                                  
                                  Dimmer lightSalonCeiling00	"Light 1 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling01	"Light 2 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling02	"Light 3 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling03	"Light 4 [%s %%]" (lights, lrcLights)
                                  Dimmer lightSalonCeiling04	"Light All [%s %%]" (lights,lrLights,allLights)
                                  Switch plugStrip01s12		"Sockets 1-2" <socket> (lrPlugStrip)
                                  Switch plugStrip01s34		"Sockets 3-4" <socket> (lrPlugStrip)
                                  
                                  String sensorLRCDimmer "Living Room Ceiling Light Sensor [%s]" (mysensors)
                                  String sensorLRStripPlug01 "Living Room Strip Plug 01 Sensor [%s]" (mysensors)
                                  String sensorLRHumTemp "Living Room Hum&Temp&Motion&Light  Sensor [%s]" (mysensors)
                                  String sensorKCLight "Kitchen&Bar Light Sensor [%s]" (mysensors)
                                  

                                  my test.sitemap

                                  sitemap demo label="Main Menu"
                                  {
                                  
                                  	Frame label="Home" {
                                  		Group label="Kitchen" icon="kitchen" {
                                  			Frame label="Kitchen" {
                                  				Group item=kLights label="Lights" {
                                  				Switch item=lightBar04 label="Bar Lights"
                                  				Switch item=kcLights label="Cabinet Lights"
                                  				Group item=kcLights 
                                  				}
                                  			}
                                  		}
                                  
                                  		Group item=livingRoom {
                                  			Frame label="Living Room" {
                                  				Group item=lrLights 
                                  				Group label="Sensors" icon="temperature" {
                                  					Text item=tempSalon01 valuecolor=[tempSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
                                  					Text item=humSalon01 valuecolor=[humSalon01=="Uninitialized"="lightgray",tempSalon01>90="lightgray",>25="orange",>15="green",>5="orange",<=5="blue"]
                                  					Switch item=tempChartPeriod label="Chart Period" mappings=[0="12 Hours", 1="Day", 2="Week", 3="Month"]
                                  					Chart item=humAndTemp period=12h refresh=5000 visibility=[tempChartPeriod==0,tempChartPeriod=="Uninitialized"]
                                  					Chart item=humAndTemp period=D refresh=1800 visibility=[tempChartPeriod==1]
                                  					Chart item=humAndTemp period=W refresh=3600 visibility=[tempChartPeriod==2]
                                  					Chart item=humAndTemp period=M refresh=7200 visibility=[tempChartPeriod==3]
                                  				}
                                  				Group item=lrPlugStrip
                                  			}
                                  		}
                                  		Group item=corridor 
                                  		Group item=bathroom icon="bath"
                                  		Group item=grandmotherRoom icon="smiley"
                                  	}
                                  
                                  	Frame label="Lights All"{
                                  		Switch item=lights mappings=[OFF="All Off"]
                                  		Group item=lights
                                  		Group item=mysensors
                                  	}
                                  

                                  hi all,

                                  does anyone have an arduino code for l154 nice work here above?
                                  i need an example only for arduino (dont have a rpi) on which i can connect a few relays and a few sensors like dht11 and a light sensor.
                                  Someone please a little help here with a arduino code or some links on where we can find something to work with this openhab configuration?
                                  thanks in advance.

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

                                    one more question:
                                    to make the connection with openhab should i change this "String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }" to "String Arduino "Arduino" { serial="COM4" }" couse my arduino is connecting on com4?
                                    thanks!

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

                                      @ewgor said:

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

                                      Use something like:

                                      String Arduino "Arduino" { serial="COM4@115200" }
                                      
                                      E 1 Reply Last reply
                                      0
                                      • T TimO

                                        @ewgor said:

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

                                        Use something like:

                                        String Arduino "Arduino" { serial="COM4@115200" }
                                        
                                        E Offline
                                        E Offline
                                        ewgor
                                        wrote on last edited by
                                        #47

                                        @TimO said:

                                        @ewgor said:

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

                                        Use something like:

                                        String Arduino "Arduino" { serial="COM4@115200" }
                                        

                                        thank you for answer TimO, i assume this 115200 is the baud rate, isn't it? on testing different arduino codes, i had to modify it to 9600 because otherwise it wouldn't work...
                                        can you please share with us any arduino code for a few relays and some sensors? or to suggest us some links where we can find something useful?
                                        i need an example only for an arduino (mega) connected directly through usb to my laptop.
                                        thanks again, i will try this "String Arduino "Arduino" { serial="COM4@115200" }" when i'll have an arduino code as an example.

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

                                          Yes, you're right, 115000 is the baudrate.

                                          Have you seen my tutorial?

                                          http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway
                                          tutorial-openhab-with-serial-gateway

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


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 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