Index: /D_RFXCOMHarrison.json
===================================================================
--- /D_RFXCOMHarrison.json	(revision 20)
+++ /D_RFXCOMHarrison.json	(revision 30)
@@ -145,14 +145,4 @@
             "Function": "advanced_device"
         },
-        {
-                    "Label": {
-                        "lang_tag": "logs",
-                        "text": "Logs"
-                    },
-                    "Position": "4",
-                    "TabType": "javascript",
-                    "ScriptName": "shared.js",
-                    "Function": "device_logs"
-        },
 		{
                     "Label": {
@@ -186,4 +176,26 @@
         }
     } ,
+	 "eventList": {
+	        "event_1": {
+	            "label": "Curtain is closed",
+	            "serviceId": "urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1",
+	             "serviceStateTable": {
+	                  "CurtainStatus": {
+	                      "value": "1",
+	                      "comparisson": "="
+	                  }
+	              }
+	        },
+	        "event_2": {
+	            "label": "Curtain is opened",
+	            "serviceId": "urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1",
+	             "serviceStateTable": {
+	                  "CurtainStatus": {
+	                      "value": "0",
+	                      "comparisson": "="
+	                  }
+	              }
+	        }
+	    },
     "eventList2": [
         {
Index: /S_EZAnemoSensor.xml
===================================================================
--- /S_EZAnemoSensor.xml	(revision 20)
+++ /S_EZAnemoSensor.xml	(revision 30)
@@ -25,5 +25,5 @@
        <name>SpeedAv</name>
        <dataType>string</dataType>
-	   <shortCode>speedAv</shortCode>
+	   <shortCode>speedav</shortCode>
     </stateVariable>
 	
Index: /D_RainSensor1.json
===================================================================
--- /D_RainSensor1.json	(revision 20)
+++ /D_RainSensor1.json	(revision 30)
@@ -136,4 +136,4 @@
         }
     ],
-    "DeviceType": "urn:upnp-org:serviceId:RainSensor1"
+    "DeviceType": "urn:schemas-micasaverde-com:device:RainSensor:1"
 }
Index: /D_EZAnemoSensor.json
===================================================================
--- /D_EZAnemoSensor.json	(revision 20)
+++ /D_EZAnemoSensor.json	(revision 30)
@@ -97,5 +97,5 @@
                     "ControlType": "label",
                     "Label": {
-                        "lang_tag": "gust",
+                        "lang_tag": "speed",
                         "text": "Speed"
                     },
@@ -127,5 +127,5 @@
                     "ControlType": "label",
                     "Label": {
-                        "lang_tag": "gust_unit",
+                        "lang_tag": "speed_unit",
                         "text": "m/s"
                     },
@@ -198,5 +198,146 @@
       "Function": "advanced_device"
     },
+		{
+                  "Label": {
+                      "lang_tag": "notifications",
+                      "text": "Notifications"
+                  },
+                  "Position": "5",
+                  "TabType": "javascript",
+                  "ScriptName": "shared.js",
+                  "Function": "device_notifications"
+      }
   ],
-  "DeviceType": "urn:schemas-micasaverde-com:device:EZAnemoSensor:1"
+  "eventList": {
+      "event_1": {
+          "label": "Wind speed goes above",
+          "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+			"norepeat": "1",
+          "argumentList" : {
+              "argument_1" : {
+                  "dataType": "i4",
+                  "name": "Speed",
+                  "comparisson": ">",
+                  "prefix": "speed: ",
+                  "suffix": " m/s"
+              }
+          }
+      },
+     "event_2": {
+          "label": "Wind speed goes below",
+          "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+			"norepeat": "1",
+          "argumentList" : {
+              "argument_1" : {
+                  "dataType": "i4",
+                  "name": "Speed",
+                  "comparisson": "<",
+                  "prefix": "speed: ",
+                  "suffix": " m/s"
+              }
+          }
+      },
+      "event_3": {
+          "label": "Battery level goes below",
+          "serviceId": "urn:micasaverde-com:serviceId:HaDevice1",
+          "argumentList": {
+              "argument_1": {
+					"prefix":"Level",
+                  "dataType": "i4",
+                  "name": "BatteryLevel",
+                  "comparisson": "<",
+                  "suffix": "%" 
+              } 
+          } 
+      }
+   } ,
+   "eventList2": [
+       {
+           "id": 1,
+           "label": {
+               "lang_tag": "speed_goes_above",
+               "text": "Wind speed goes above"
+           },
+           "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+           "norepeat": "1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "dataType": "i4",
+                   "name": "Speed",
+                   "comparisson": ">",
+                   "prefix": {
+                       "lang_tag": "speed",
+                       "text": "Speed"
+                   },
+                   "suffix": {
+                       "lang_tag": "m/s",
+                       "text": "m/s"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_speed_goes_above",
+                       "text": "The wind speed goes above _DEVICE_NAME_ m/s _ARGUMENT_VALUE_"
+                   }
+               }
+           ]
+       },
+       {
+           "id": 2,
+           "label": {
+               "lang_tag": "speed_goes_below",
+               "text": "Wind speed goes below"
+           },
+           "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+           "norepeat": "1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "dataType": "i4",
+                   "name": "Speed",
+                   "comparisson": "<",
+                   "prefix": {
+                       "lang_tag": "speed",
+                       "text": "Speed av"
+                   },
+                   "suffix": {
+                       "lang_tag": "m/s",
+                       "text": "m/s"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_speed_goes_below",
+                       "text": "The wind speed goes below _DEVICE_NAME_ m/s _ARGUMENT_VALUE_"
+                   }
+               }
+           ]
+       },
+       {
+           "id": 3,
+           "label": {
+               "lang_tag": "battery_level_goes_below",
+               "text": "Battery level goes below"
+           },
+           "serviceId": "urn:micasaverde-com:serviceId:HaDevice1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "prefix": {
+                       "lang_tag": "Level",
+                       "text": "Niveau"
+                   },
+                   "dataType": "i4",
+                   "name": "BatteryLevel",
+                   "comparisson": "<",
+                   "suffix": {
+                       "lang_tag": "percent_sign",
+                       "text": "%"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_battery_level_goes_below",
+                       "text": "Battery level for _DEVICE_NAME_ goes below _ARGUMENT_VALUE_%"
+                   }
+               }
+           ]
+       }
+   ],
+  "DeviceType": "urn:schemas-upnp-org:device:EZAnemoSensor:1"
 }
Index: /MakeZips.bat
===================================================================
--- /MakeZips.bat	(revision 30)
+++ /MakeZips.bat	(revision 30)
@@ -0,0 +1,28 @@
+del *.zip
+
+mkdir rfxcomuk
+cd rfxcomuk
+del *.* /Y
+xcopy ..\* . /Y
+del *.zip
+del *.bat
+del *_fr.json
+zip ..\Rfxcom_uk.zip *.*
+cd ..
+
+mkdir rfxcomfr
+cd rfxcomfr
+del *.* /Y
+xcopy ..\* . /Y
+del *.zip
+del *.bat
+del D_BarometerSensor1.json
+ren D_BarometerSensor1_fr.json D_BarometerSensor1.json
+del D_EZAnemoSensor.json
+ren D_EZAnemoSensor_fr.json D_EZAnemoSensor.json
+zip ..\Rfxcom_fr.zip *.*
+cd ..
+
+
+
+
Index: /D_EZAnemoSensor_fr.json
===================================================================
--- /D_EZAnemoSensor_fr.json	(revision 20)
+++ /D_EZAnemoSensor_fr.json	(revision 30)
@@ -146,5 +146,5 @@
                     "ControlType": "label",
                     "Label": {
-                        "lang_tag": "average_spped",
+                        "lang_tag": "average_speed",
                         "text": "Vitesse moy"
                     },
@@ -198,5 +198,146 @@
       "Function": "advanced_device"
     },
+		{
+                  "Label": {
+                      "lang_tag": "notifications",
+                      "text": "Notifications"
+                  },
+                  "Position": "5",
+                  "TabType": "javascript",
+                  "ScriptName": "shared.js",
+                  "Function": "device_notifications"
+      }
   ],
-  "DeviceType": "urn:schemas-micasaverde-com:device:EZAnemoSensor:1"
+  "eventList": {
+      "event_1": {
+          "label": "Vitesse vent passe en dessus de",
+          "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+			"norepeat": "1",
+          "argumentList" : {
+              "argument_1" : {
+                  "dataType": "i4",
+                  "name": "Speed",
+                  "comparisson": ">",
+                  "prefix": "speed: ",
+                  "suffix": " m/s"
+              }
+          }
+      },
+     "event_2": {
+          "label": "Vitesse vent descend en dessous de",
+          "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+			"norepeat": "1",
+          "argumentList" : {
+              "argument_1" : {
+                  "dataType": "i4",
+                  "name": "Speed",
+                  "comparisson": "<",
+                  "prefix": "speed: ",
+                  "suffix": " m/s"
+              }
+          }
+      },
+      "event_3": {
+          "label": "Niveau de la batterie descend en dessous de",
+          "serviceId": "urn:micasaverde-com:serviceId:HaDevice1",
+          "argumentList": {
+              "argument_1": {
+					"prefix":"Level",
+                  "dataType": "i4",
+                  "name": "BatteryLevel",
+                  "comparisson": "<",
+                  "suffix": "%" 
+              } 
+          } 
+      }
+   } ,
+   "eventList2": [
+       {
+           "id": 1,
+           "label": {
+               "lang_tag": "speed_goes_above",
+               "text": "Vitesse vent passe en dessus de"
+           },
+           "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+           "norepeat": "1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "dataType": "i4",
+                   "name": "Speed",
+                   "comparisson": ">",
+                   "prefix": {
+                       "lang_tag": "speed",
+                       "text": "Speed"
+                   },
+                   "suffix": {
+                       "lang_tag": "m/s",
+                       "text": "m/s"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_speed_goes_above",
+                       "text": "La vitesse du vent pour _DEVICE_NAME_ passe en dessus de _ARGUMENT_VALUE_  m/s"
+                   }
+               }
+           ]
+       },
+       {
+           "id": 2,
+           "label": {
+               "lang_tag": "speed_goes_below",
+               "text": "Vitesse vent descend en dessous de"
+           },
+           "serviceId": "urn:upnp-org:serviceId:EZAnemoSensor1",
+           "norepeat": "1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "dataType": "i4",
+                   "name": "Speed",
+                   "comparisson": "<",
+                   "prefix": {
+                       "lang_tag": "speed",
+                       "text": "Speed av"
+                   },
+                   "suffix": {
+                       "lang_tag": "m/s",
+                       "text": "m/s"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_speed_goes_below",
+                       "text": "La vitesse du vent pour _DEVICE_NAME_ descend en dessous de _ARGUMENT_VALUE_ m/s"
+                   }
+               }
+           ]
+       },
+       {
+           "id": 3,
+           "label": {
+               "lang_tag": "battery_level_goes_below",
+               "text": "Niveau de la batterie descend en dessous de"
+           },
+           "serviceId": "urn:micasaverde-com:serviceId:HaDevice1",
+           "argumentList": [
+               {
+                   "id": 1,
+                   "prefix": {
+                       "lang_tag": "Level",
+                       "text": "Niveau"
+                   },
+                   "dataType": "i4",
+                   "name": "BatteryLevel",
+                   "comparisson": "<",
+                   "suffix": {
+                       "lang_tag": "percent_sign",
+                       "text": "%"
+                   },
+                   "HumanFriendlyText": {
+                       "lang_tag": "hft_battery_level_goes_below",
+                       "text": "Le niveau de la batterie pour _DEVICE_NAME_ descend en dessous de _ARGUMENT_VALUE_%"
+                   }
+               }
+           ]
+       }
+   ],
+  "DeviceType": "urn:schemas-upnp-org:device:EZAnemoSensor:1"
 }
Index: /I_RFXCOM.xml
===================================================================
--- /I_RFXCOM.xml	(revision 20)
+++ /I_RFXCOM.xml	(revision 30)
@@ -19,189 +19,189 @@
     ipPortRead = 0
     ipPortSend = 0
-	
-	RFXConstants = {
-		sensorTypeMotion = 1,
-		sensorTypeDoor = 2,
-		sensorTypeKeyFob = 4,
-		sensorTypeRemote = 8,
-		sensorTypeControler = 16,
-		sensorTypeWindowCovering = 32,
-		sensorTypeTemperature = 64,
-		sensorTypeHumidity = 128,
-		sensorTypeWindDirection = 256, 
-		sensorTypeWindSpeed = 512,
-		sensorTypeWindSpeedAv = 1024,
-		sensorTypeBarometer = 2048,
-		sensorTypeRain = 4096,
-		
-		sensorManufacturerX10 = "X10",
-		sensorManufacturerHomeEasy = "HOMEEASY",
-		sensorManufacturerVisonic = "VISONIC",
-		sensorManufacturerOregon = "OREGON",
-		sensorManufacturerHarrison = "HARRISON",
-			
-		cmdGroupOn = 1,
-		cmdGroupOff = 2,
-		cmdOn = 4,
-		cmdOff = 8,
-		cmdArmAway = 16,
-		cmdArmHome = 32,
-		cmdDisarm = 64,
-		cmdTamper = 128,
-		cmdJamming = 256,
-		cmdBatteryLow = 512,
-		cmdNormal = 1024,
-		cmdAlert = 2048
-	}
-	
+  
+  RFXConstants = {
+    sensorTypeMotion = 1,
+    sensorTypeDoor = 2,
+    sensorTypeKeyFob = 4,
+    sensorTypeRemote = 8,
+    sensorTypeControler = 16,
+    sensorTypeWindowCovering = 32,
+    sensorTypeTemperature = 64,
+    sensorTypeHumidity = 128,
+    sensorTypeWindDirection = 256, 
+    sensorTypeWindSpeed = 512,
+    sensorTypeWindSpeedAv = 1024,
+    sensorTypeBarometer = 2048,
+    sensorTypeRain = 4096,
+    
+    sensorManufacturerX10 = "X10",
+    sensorManufacturerHomeEasy = "HOMEEASY",
+    sensorManufacturerVisonic = "VISONIC",
+    sensorManufacturerOregon = "OREGON",
+    sensorManufacturerHarrison = "HARRISON",
+      
+    cmdGroupOn = 1,
+    cmdGroupOff = 2,
+    cmdOn = 4,
+    cmdOff = 8,
+    cmdArmAway = 16,
+    cmdArmHome = 32,
+    cmdDisarm = 64,
+    cmdTamper = 128,
+    cmdJamming = 256,
+    cmdBatteryLow = 512,
+    cmdNormal = 1024,
+    cmdAlert = 2048
+  }
+  
   function mainStartup(lul_device)
-		RFXDevicesLS = {}
-		RFXCountLS = 0
-		RFXDevicesDS = {}
-		RFXCountDS = 0
-		RFXDevicesMS = {}
-		RFXCountMS = 0
-		RFXDevicesKF = {}
-		RFXCountKF = 0
-		RFXCountTS2 = 0
-		RFXDevicesTS2 = {}
-		RFXCountHS2 = 0
-		RFXDevicesHS2 = {}
-		RFXCountBS2 = 0
-		RFXDevicesBS2 = {}
-		RFXCountRS2 = 0
-		RFXDevicesRS2 = {}
-		RFXCountAS2 = 0
-		RFXDevicesAS2 = {}
-		RFXCOM_HAR_Count = 0
-		RFXCOM_HAR_Devices = {}
-		
-		THIS_DEVICE = lul_device
-		luup.log("Starting RFXCOM device: " .. tostring(THIS_DEVICE))
-		local device = luup.devices[THIS_DEVICE]
-
-		-- Set our device IP number
-		if (device.ip == "") then
-			return false, "IP Address attribute must be configured", "rfxcom"
-		end
-		ipAddress = device.ip
-
-		-- Get defined read and write port. If not set, set the default port numbers 10001 and 10002
-		local portList = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "portRead", lul_device)
-		if ((portList or "") == "") then
-			portList = "10001"
-			luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "portRead", portList, lul_device)
-		elseif (portList:find("%d") == nil) then
-			return false, "The Port Read parameter must be of the form nnnn.  eg. 10001"
-		end
-		ipPortRead = portList
-	  
-		local portList = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "portWrite", lul_device)
-		if ((portList or "") == "") then
-			portList = "10002"
-			luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "portWrite", portList, lul_device)
-		elseif (portList:find("%d") == nil) then
-			return false, "The Port Write parameter must be of the form nnnn.  eg. 10002"
-		end     
-		ipPortSend = portList
-
-		-- Check if we should create the devices automaticly
-		local RFXAutoCreate = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", lul_device)
-		if ((RFXAutoCreate or "") == "") then
-			luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", "0", lul_device)
-		end
-		
-		-- Check all devices if they are childeren. If so, register in
-		-- the correct array based on the device type
-		for k, v in pairs(luup.devices) do
-			-- Look for devices with this device as parent
-			if (v.device_num_parent == lul_device) then
-				luup.log( "Found child device, lets save! id " .. tostring(v.id) .. " device " .. tostring(v.device_type))
-
-				-- Check on door sensors
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:DoorSensor:1") then
-					RFXCountDS = RFXCountDS + 1
-					RFXDevicesDS[RFXCountDS] = v.id
-				end
-				
-				-- Check on motion sensors
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:MotionSensor:1") then
-					RFXCountMS = RFXCountMS + 1
-					RFXDevicesMS[RFXCountMS] = v.id
-				end		
-
-				-- Check on keyfobs
-				if (tostring(v.device_type) == "urn:schemas-ActiveRFID:device:RFIDTransmitter:1") then
-					RFXCountKF = RFXCountKF + 1
-					RFXDevicesKF[RFXCountKF] = v.id
-				end		
-
-				-- Check on light switches 
-				if (tostring(v.device_type) == "urn:schemas-upnp-org:device:BinaryLight:1") then
-					RFXCountLS = RFXCountLS + 1
-					RFXDevicesLS[RFXCountLS] = v.id
-				end
-
-				-- Check on Harrison window coverings
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:WindowCovering:1") then
-					RFXCOM_HAR_Count = RFXCOM_HAR_Count + 1
-					RFXCOM_HAR_Devices[RFXCOM_HAR_Count] = v.id
-				end
-				
-				-- Check on temperature devices
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:TemperatureSensor:1") then
-					RFXCountTS2 = RFXCountTS2 + 1
-					RFXDevicesTS2[RFXCountTS2] = v.id
-					luup.log("Registered device " .. RFXDevicesTS2[RFXCountTS2] .. " as temperature sensor ".. RFXCountTS2)
-				end
-				
-				-- Check on humidity devices
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:HumiditySensor:1") then
-					RFXCountHS2 = RFXCountHS2 + 1
-					RFXDevicesHS2[RFXCountHS2] = v.id
-					luup.log("Registered device " .. RFXDevicesHS2[RFXCountHS2] .. " as humidity sensor ".. RFXCountHS2)
-				end
-				
-				-- Check on barometer devices
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:BarometerSensor:1") then
-					RFXCountBS2 = RFXCountBS2 + 1
-					RFXDevicesBS2[RFXCountBS2] = v.id
-					luup.log("Registered device " .. RFXDevicesBS2[RFXCountBS2] .. " as barometer sensor ".. RFXCountBS2)
-				end
-				
-				-- Check on barometer devices
-				if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:RainSensor:1") then
-					RFXCountRS2 = RFXCountRS2 + 1
-					RFXDevicesRS2[RFXCountRS2] = v.id
-					luup.log("Registered device " .. RFXDevicesRS2[RFXCountRS2] .. " as rain sensor ".. RFXCountRS2)
-				end
-				
-				-- Check on EZAnemoSensor devices
-				if (tostring(v.device_type) == "urn:schemas-upnp-org:device:EZAnemoSensor:1") then
-					RFXCountAS2 = RFXCountAS2 + 1
-					RFXDevicesAS2[RFXCountAS2] = v.id
-					luup.log("Registered device " .. RFXDevicesAS2[RFXCountAS2] .. " as Anemo sensor ".. RFXCountAS2)
-				end
-			end
-		end
-		luup.log("Tree with number child devices:")
-		luup.log("       door sensors: " .. RFXCountDS)
-		luup.log("     motion sensors: " .. RFXCountMS)
-		luup.log("     keyfob sensors: " .. RFXCountKF)
-		luup.log("     light switches: " .. RFXCountLS)
-		luup.log("    window covering: " .. RFXCOM_HAR_Count)
-		luup.log("temperature sensors: " .. RFXCountTS2)
-		luup.log("   humidity sensors: " .. RFXCountHS2)
-		luup.log("   pressure sensors: " .. RFXCountBS2)
-		luup.log("       rain sensors: " .. RFXCountBS2)
-		luup.log("      anemo sensors: " .. RFXCountAS2)
-			
-		luup.log("Open socket for read " .. ipAddress .. " port " .. ipPortRead )
-		luup.io.open(THIS_DEVICE, ipAddress, ipPortRead)
-		startupReady = 1
-
-		luup.log("Startup RFXCOM ready")
-
-		return true, "ok", "rfxcom"
+    RFXDevicesLS = {}
+    RFXCountLS = 0
+    RFXDevicesDS = {}
+    RFXCountDS = 0
+    RFXDevicesMS = {}
+    RFXCountMS = 0
+    RFXDevicesKF = {}
+    RFXCountKF = 0
+    RFXCountTS2 = 0
+    RFXDevicesTS2 = {}
+    RFXCountHS2 = 0
+    RFXDevicesHS2 = {}
+    RFXCountBS2 = 0
+    RFXDevicesBS2 = {}
+    RFXCountRS2 = 0
+    RFXDevicesRS2 = {}
+    RFXCountAS2 = 0
+    RFXDevicesAS2 = {}
+    RFXCOM_HAR_Count = 0
+    RFXCOM_HAR_Devices = {}
+    
+    THIS_DEVICE = lul_device
+    luup.log("Starting RFXCOM device: " .. tostring(THIS_DEVICE))
+    local device = luup.devices[THIS_DEVICE]
+
+    -- Set our device IP number
+    if (device.ip == "") then
+      return false, "IP Address attribute must be configured", "rfxcom"
+    end
+    ipAddress = device.ip
+
+    -- Get defined read and write port. If not set, set the default port numbers 10001 and 10002
+    local portList = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "portRead", lul_device)
+    if ((portList or "") == "") then
+      portList = "10001"
+      luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "portRead", portList, lul_device)
+    elseif (portList:find("%d") == nil) then
+      return false, "The Port Read parameter must be of the form nnnn.  eg. 10001"
+    end
+    ipPortRead = portList
+    
+    local portList = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "portWrite", lul_device)
+    if ((portList or "") == "") then
+      portList = "10002"
+      luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "portWrite", portList, lul_device)
+    elseif (portList:find("%d") == nil) then
+      return false, "The Port Write parameter must be of the form nnnn.  eg. 10002"
+    end     
+    ipPortSend = portList
+
+    -- Check if we should create the devices automaticly
+    local RFXAutoCreate = luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", lul_device)
+    if ((RFXAutoCreate or "") == "") then
+      luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", "0", lul_device)
+    end
+    
+    -- Check all devices if they are children. If so, register in
+    -- the correct array based on the device type
+    for k, v in pairs(luup.devices) do
+      -- Look for devices with this device as parent
+      if (v.device_num_parent == lul_device) then
+        luup.log( "Found child device, lets save! id " .. tostring(v.id) .. " device " .. tostring(v.device_type))
+
+        -- Check on door sensors
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:DoorSensor:1") then
+          RFXCountDS = RFXCountDS + 1
+          RFXDevicesDS[RFXCountDS] = v.id
+        end
+        
+        -- Check on motion sensors
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:MotionSensor:1") then
+          RFXCountMS = RFXCountMS + 1
+          RFXDevicesMS[RFXCountMS] = v.id
+        end   
+
+        -- Check on keyfobs
+        if (tostring(v.device_type) == "urn:schemas-ActiveRFID:device:RFIDTransmitter:1") then
+          RFXCountKF = RFXCountKF + 1
+          RFXDevicesKF[RFXCountKF] = v.id
+        end   
+
+        -- Check on light switches 
+        if (tostring(v.device_type) == "urn:schemas-upnp-org:device:BinaryLight:1") then
+          RFXCountLS = RFXCountLS + 1
+          RFXDevicesLS[RFXCountLS] = v.id
+        end
+
+        -- Check on Harrison window coverings
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:WindowCovering:1") then
+          RFXCOM_HAR_Count = RFXCOM_HAR_Count + 1
+          RFXCOM_HAR_Devices[RFXCOM_HAR_Count] = v.id
+        end
+        
+        -- Check on temperature devices
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:TemperatureSensor:1") then
+          RFXCountTS2 = RFXCountTS2 + 1
+          RFXDevicesTS2[RFXCountTS2] = v.id
+          luup.log("Registered device " .. RFXDevicesTS2[RFXCountTS2] .. " as temperature sensor ".. RFXCountTS2)
+        end
+        
+        -- Check on humidity devices
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:HumiditySensor:1") then
+          RFXCountHS2 = RFXCountHS2 + 1
+          RFXDevicesHS2[RFXCountHS2] = v.id
+          luup.log("Registered device " .. RFXDevicesHS2[RFXCountHS2] .. " as humidity sensor ".. RFXCountHS2)
+        end
+        
+        -- Check on barometer devices
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:BarometerSensor:1") then
+          RFXCountBS2 = RFXCountBS2 + 1
+          RFXDevicesBS2[RFXCountBS2] = v.id
+          luup.log("Registered device " .. RFXDevicesBS2[RFXCountBS2] .. " as barometer sensor ".. RFXCountBS2)
+        end
+        
+        -- Check on barometer devices
+        if (tostring(v.device_type) == "urn:schemas-micasaverde-com:device:RainSensor:1") then
+          RFXCountRS2 = RFXCountRS2 + 1
+          RFXDevicesRS2[RFXCountRS2] = v.id
+          luup.log("Registered device " .. RFXDevicesRS2[RFXCountRS2] .. " as rain sensor ".. RFXCountRS2)
+        end
+        
+        -- Check on EZAnemoSensor devices
+        if (tostring(v.device_type) == "urn:schemas-upnp-org:device:EZAnemoSensor:1") then
+          RFXCountAS2 = RFXCountAS2 + 1
+          RFXDevicesAS2[RFXCountAS2] = v.id
+          luup.log("Registered device " .. RFXDevicesAS2[RFXCountAS2] .. " as Anemo sensor ".. RFXCountAS2)
+        end
+      end
+    end
+    luup.log("Tree with number child devices:")
+    luup.log("       door sensors: " .. RFXCountDS)
+    luup.log("     motion sensors: " .. RFXCountMS)
+    luup.log("     keyfob sensors: " .. RFXCountKF)
+    luup.log("     light switches: " .. RFXCountLS)
+    luup.log("    window covering: " .. RFXCOM_HAR_Count)
+    luup.log("temperature sensors: " .. RFXCountTS2)
+    luup.log("   humidity sensors: " .. RFXCountHS2)
+    luup.log("   pressure sensors: " .. RFXCountBS2)
+    luup.log("       rain sensors: " .. RFXCountBS2)
+    luup.log("      anemo sensors: " .. RFXCountAS2)
+      
+    luup.log("Open socket for read " .. ipAddress .. " port " .. ipPortRead )
+    luup.io.open(THIS_DEVICE, ipAddress, ipPortRead)
+    startupReady = 1
+
+    luup.log("Startup RFXCOM ready")
+
+    return true, "ok", "rfxcom"
   end
      
@@ -247,246 +247,241 @@
     return lsResult
   end
-	
-	function SendHarrisonCmd( psHouse, psCmd)
+  
+  function SendHarrisonCmd( psHouse, psCmd)
     local liMODEHAR = 0x34
-	  local liMODERFXCOM = 0x33
-	  local client = nil
-	  local lsSend = ""
-	  local lsSendStat = ""
-	  local lsRecvStat = ""
-	  	  
+    local liMODERFXCOM = 0x33
+    local client = nil
+    local lsSend = ""
+    local lsSendStat = ""
+    local lsRecvStat = ""
+        
     luup.log("Connect to rfxtrans ip " .. ipAddress .. " port " .. ipPortSend)
     client = socket.connect(ipAddress, ipPortSend)
 
-	  if client ~= nil then
-			client:settimeout(2)
-
-			luup.log("Send cmd " .. psCmd .. " to " .. psHouse)
-
-			--to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
-			lsSend = string.char(0xf0) .. string.char(liMODEHAR) .. string.char(0xf0) .. string.char(liMODEHAR)
-			--luup.log("send cmd: " .. formattohex(lsSend))
-
-			lsSendStat = client:send(lsSend)
-			--luup.log("send cmd result: " .. formattohex(lsSendStat))
-
-			-- We will receive an ack with the last byte of the command sent. or a nack 0x5a
-			lsRecvStat=client:receive(1)
-			--luup.log("recv result: " .. formattohex(lsRecvStat))
-
-			--to send a command we need to specify: [House Code][Command]
-			-- House code is 2 bytes. Open up the remote. There are 8 dip switches with a 3 state.
-			-- note down the bits where state top = 2 bits: 11, middle = 10, down = 00.
-			-- write down the bits starting from switch 1 to 8.
-			-- I get the following code of bits:  00 00 11 11 00 10 10 10
-			-- This is binary and can be written in hex as follows:  0F2A and there you have the house code
-			-- The curtain has three command: open, close, stop: F380, CF80 and FC80
-			--
-			if ( psCmd == "OPEN" ) then
-				lsSend = psHouse .. "F380"
-				luup.log("send open command for Harrison house code: " .. psHouse)
-			elseif ( psCmd == "CLOSE") then
-				lsSend = psHouse .. "CF80"
-				luup.log("send close command for Harrison house code: " .. psHouse)
-			else
-				--stop
-				lsSend = psHouse .. "FC80"
-				luup.log("send stop command for Harrison house code: " .. psHouse)
-			end
-
-			lsSend = ToByteString( lsSend )
-
-			local lsSendStat = client:send(lsSend)
-			--luup.log("send cmd result: " .. formattohex(lsSendStat))
-
-			-- We will recieve an ack with the last byte. or a nack 0x5a
-			local lsRecvStat=client:receive(1)
-			--luup.log("recv result: " .. formattohex(lsRecvStat))
-
-			-- Close client connection
-			client:close()
-		else
-			return false
-		end
-		luup.log("finished: ")
+    if client ~= nil then
+      client:settimeout(2)
+
+      luup.log("Send cmd " .. psCmd .. " to " .. psHouse)
+
+      --to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
+      lsSend = string.char(0xf0) .. string.char(liMODEHAR) .. string.char(0xf0) .. string.char(liMODEHAR)
+      --luup.log("send cmd: " .. formattohex(lsSend))
+
+      lsSendStat = client:send(lsSend)
+      --luup.log("send cmd result: " .. formattohex(lsSendStat))
+
+      -- We will receive an ack with the last byte of the command sent. or a nack 0x5a
+      lsRecvStat=client:receive(1)
+      --luup.log("recv result: " .. formattohex(lsRecvStat))
+
+      --to send a command we need to specify: [House Code][Command]
+      -- House code is 2 bytes. Open up the remote. There are 8 dip switches with a 3 state.
+      -- note down the bits where state top = 2 bits: 11, middle = 10, down = 00.
+      -- write down the bits starting from switch 1 to 8.
+      -- I get the following code of bits:  00 00 11 11 00 10 10 10
+      -- This is binary and can be written in hex as follows:  0F2A and there you have the house code
+      -- The curtain has three command: open, close, stop: F380, CF80 and FC80
+      --
+      if ( psCmd == "OPEN" ) then
+        lsSend = psHouse .. "F380"
+        luup.log("send open command for Harrison house code: " .. psHouse)
+      elseif ( psCmd == "CLOSE") then
+        lsSend = psHouse .. "CF80"
+        luup.log("send close command for Harrison house code: " .. psHouse)
+      else
+        --stop
+        lsSend = psHouse .. "FC80"
+        luup.log("send stop command for Harrison house code: " .. psHouse)
+      end
+
+      lsSend = ToByteString( lsSend )
+
+      local lsSendStat = client:send(lsSend)
+      --luup.log("send cmd result: " .. formattohex(lsSendStat))
+
+      -- We will recieve an ack with the last byte. or a nack 0x5a
+      local lsRecvStat=client:receive(1)
+      --luup.log("recv result: " .. formattohex(lsRecvStat))
+
+      -- Close client connection
+      client:close()
+    else
+      return false
+    end
+    luup.log("finished: ")
   end
  
-	function SendCmd( psID, psCmd )
+  function SendCmd( psID, psCmd )
     local liMODERESET = 0x30
     local liMODEHAR = 0x34
-	  local liMODEVAR = 0x33
-	  local liMODEBRB48 = 0x37
-	  local liMODEKAKURF = 0x3d
-	  local client = nil
-	  local lsSend = ""
-	  local lsSendStat = ""
-	  local lsRecvStat = ""
-	  
-	  
+    local liMODEVAR = 0x33
+    local liMODEBRB48 = 0x37
+    local liMODEKAKURF = 0x3d
+    local client = nil
+    local lsSend = ""
+    local lsSendStat = ""
+    local lsRecvStat = ""
+    
+    
     luup.log("Connect to rfxtrans ip " .. ipAddress .. " port " .. ipPortSend)
     client = socket.connect(ipAddress, ipPortSend)
 
-	  if client ~= nil then
-			client:settimeout(2)
-
-			luup.log("Send cmd " .. psCmd .. " to " .. psID)
-
-			-- Because this is a homeeasy, kaku device, calc the
-			-- command to be send based on the ID of the device
-			
-			local lsDeviceType = string.sub( psID, 1, 3)
-			luup.log("Device type is " .. lsDeviceType .. " based on id " .. psID)
-			
-			if lsDeviceType == "HEA" then
-  			--to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
-  			lsSend = string.char(0xf0) .. string.char(liMODERESET) .. string.char(0xf0) .. string.char(liMODERESET)
+    if client ~= nil then
+      client:settimeout(2)
+
+      luup.log("Send cmd " .. psCmd .. " to " .. psID)
+
+      -- Because this is a homeeasy, kaku device, calc the
+      -- command to be send based on the ID of the device
+      
+      local lsDeviceType = string.sub( psID, 1, 3)
+      luup.log("Device type is " .. lsDeviceType .. " based on id " .. psID)
+      
+      if lsDeviceType == "HEA" then
+        --to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
+        lsSend = string.char(0xf0) .. string.char(liMODERESET) .. string.char(0xf0) .. string.char(liMODERESET)
         lsRecvStat = DoSend( client, lsSend)
-  			lsSend = string.char(0xf0) .. string.char(liMODEVAR) .. string.char(0xf0) .. string.char(liMODEVAR)
+        lsSend = string.char(0xf0) .. string.char(liMODEVAR) .. string.char(0xf0) .. string.char(liMODEVAR)
         lsRecvStat = DoSend( client, lsSend)
 
-				lsSend = RecodeHomeEasy34(psID, psCmd)
-			elseif lsDeviceType == "X10" then
-  			--to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
---  			lsSend = string.char(0xf0) .. string.char(liMODERESET) .. string.char(0xf0) .. string.char(liMODERESET)
+        lsSend = RecodeHomeEasy34(psID, psCmd)
+      elseif lsDeviceType == "X10" then
+--        to send a command we need to specify:  F0 CMD F0 CMD    where CMD has special meaning.
+--        lsSend = string.char(0xf0) .. string.char(liMODERESET) .. string.char(0xf0) .. string.char(liMODERESET)
 --        lsRecvStat = DoSend( client, lsSend)
-  			lsSend = string.char(0xf0) .. string.char(liMODEKAKURF) .. string.char(0xf0) .. string.char(liMODEKAKURF)
+        lsSend = string.char(0xf0) .. string.char(liMODEKAKURF) .. string.char(0xf0) .. string.char(liMODEKAKURF)
         lsRecvStat = DoSend( client, lsSend)
-				lsSend = RecodeX10(psID, psCmd)
-			else
-				lsSend = nil
-			end
-			
-			if lsSend ~= nil then
-				lsSend = ToByteString(lsSend)
-				luup.log("send command " .. psCmd .. " as " .. formattohex(lsSend))
+        lsSend = RecodeX10(psID, psCmd)
+      else
+        lsSend = nil
+      end
+      
+      if lsSend ~= nil then
+        lsSend = ToByteString(lsSend)
+        luup.log("send command " .. psCmd .. " as " .. formattohex(lsSend))
         
-				-- We will recieve an ack with the last byte. or a nack 0x5a
-				lsRecvStat = DoSend( client, lsSend)
-			end
-			
-			-- Close client connection
-			client:close()
-		else
-  		luup.log("connection failed.")
-			return false
-		end
-		luup.log("finished: ")
+        -- We will receive an ack with the last byte. or a nack 0x5a
+        lsRecvStat = DoSend( client, lsSend)
+      end
+      
+      -- Close client connection
+      client:close()
+    else
+      luup.log("connection failed.")
+      return false
+    end
+    luup.log("finished: ")
   end
 
   function DoSend( poClient, psMessage)
-  	if psMessage ~= nil then luup.log("send cmd: " .. formattohex(psMessage)) end
-
-  	local lsSendStat = poClient:send(psMessage)
-
-  	-- We will receive an ack with the last byte of the command sent. or a nack 0x5a
-  	local lsRecvStat = poClient:receive(1)
-  	if lsRecvStat ~= nil then luup.log("recv result: " .. formattohex(lsRecvStat)) end
-  	return lsRecvStat
-  end
-
-	function RecodeHomeEasy33(psID,psCmd)
-		local lbCmd = string.byte(psID, 5)
-		
-		if psCmd == RFXConstants.cmdOff then
-			lbCmd = bitw.bor(lbCmd,0x00)
-		elseif psCmd == RFXConstants.cmdOn then
-			lbCmd = bitw.bor(lbCmd,0x10)
-		elseif psCmd == RFXConstants.cmdGroupOff then
-			lbCmd = bitw.bor(lbCmd,0x20)
-		elseif psCmd == RFXConstants.cmdGroupOn then		
-			lbCmd = bitw.bor(lbCmd,0x30)
-		end
-		
-		return string.format("%02x%02x%02x%02x%02x%02x",string.byte(psID, 1),string.byte(psID, 2),string.byte(psID, 3),
-								string.byte(psID, 4),lbCmd, string.byte(psID, 6))
-	end
-	
-	function RecodeHomeEasy34(psID, psCmd)
-  	luup.log("Recode homeeasy" )
-	
-	  local lsIDBytes = ToByteString( string.sub(psID, 4, 14 ) )
-    local lsID = "21"
-    luup.log("Raw data " .. formattohex( lsIDBytes) )
-    
-    local liCommandCorrection = 0
+    if psMessage ~= nil then luup.log("send cmd: " .. formattohex(psMessage)) end
+
+    local lsSendStat = poClient:send(psMessage)
+
+    -- We will receive an ack with the last byte of the command sent. or a nack 0x5a
+    local lsRecvStat = poClient:receive(1)
+    if lsRecvStat ~= nil then luup.log("recv result: " .. formattohex(lsRecvStat)) end
+    return lsRecvStat
+  end
+
+  function RecodeHomeEasy33(psID, psCmd)
+    luup.log("Recode homeeasy33" )
+    return "21" .. RecodeHomeEasyBase( psID, psCmd)
+  end
+  
+  function RecodeHomeEasy34(psID, psCmd)
+    luup.log("Recode homeeasy34" )
+    return "22" .. RecodeHomeEasyBase( psID, psCmd)
+  end
+  
+  function RecodeHomeEasyBase(psID, psCmd)
+    local lsIDBytes = ToByteString( string.sub(psID, 4, 14 ) )
+
+    local lbCmd = 0
+    if psCmd == RFXConstants.cmdOff then
+      lbCmd = 0x00
+    elseif psCmd == RFXConstants.cmdOn then
+      lbCmd = 0x10
+    elseif psCmd == RFXConstants.cmdGroupOff then
+      lbCmd = 0x20
+    elseif psCmd == RFXConstants.cmdGroupOn then    
+      lbCmd = 0x30
+    end
+
     local lsEnd = "00"
-    if psCmd == RFXConstants.cmdOn then
-      liCommandCorrection = 0x10
-      lsEnd = "00"
-    end
-    --Raw data 00 0E 28 73 0A 0B  wordt 22 03 8A 1C DA
-		-- 00.0C.86.0A.B cmd 4 moet  worden 22 03 A1 C2 9B 80 
-		-- Make ID as received bytes minus command
+    local lsID = ""
     lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band( string.byte(lsIDBytes, 1), 0x03 ), 6) + bitw.rshift( bitw.band( string.byte(lsIDBytes, 2), 0xFC ), 2))
     lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band( string.byte(lsIDBytes, 2), 0x03 ), 6) + bitw.rshift( bitw.band( string.byte(lsIDBytes, 3), 0xFC ), 2))
     lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band( string.byte(lsIDBytes, 3), 0x03 ), 6) + bitw.rshift( bitw.band( string.byte(lsIDBytes, 4), 0xFC ), 2))
-    lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band( string.byte(lsIDBytes, 4), 0x03 ), 6) + liCommandCorrection + bitw.band( string.byte(lsIDBytes, 5), 0x0F))
-
-		return lsID .. lsEnd
-	end
-
-	function RecodeHomeEasy36(psID,psCmd)
-		return nil
-	end
-	
-	function RecodeX10( psID, psCmd)
-	
+    lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band( string.byte(lsIDBytes, 4), 0x03 ), 6) + lbCmd + bitw.band( string.byte(lsIDBytes, 5), 0x0F))
+
+    return lsID .. lsEnd
+  end
+  
+
+  function RecodeHomeEasy36(psID,psCmd)
+    luup.log("Recode homeeasy36 not implemented" )
+    return nil
+  end
+  
+  function RecodeX10( psID, psCmd)
+  
     luup.log("RecodeX10")
-	
-	  local laX10HOUSE = { 0x60, 0x70, 0x40, 0x50, 0x80, 0x90, 0xa0, 0xb0, 0xe0, 0xf0, 0xc0, 0xd0, 0x00, 0x10, 0x20, 0x30 }
-	  local laX10UNIT  = { 0x00, 0x10, 0x08, 0x18, 0x40, 0x50, 0x48, 0x58, 0x00, 0x10, 0x08, 0x18, 0x40, 0x50, 0x48, 0x58 }
-	  
-	  local lsHouseCode = string.sub(psID, 4, 4)
-	  local liHouseCode = 1 + string.byte(lsHouseCode) - string.byte("A")
-	  local liHouseByte = laX10HOUSE[ liHouseCode ]
-	  
-	  local lsUnitCode = ""
-	  local liUnitCode = 0
-	  local liUnitByte = 0
-	  local liCommandCorrection = 0
-
-	  if ( string.len( psID ) > 5 ) then
-	    lsUnitCode = string.sub(psID, 5, 6)
-	    liUnitCode = tonumber(lsUnitCode) 
-  	  liUnitByte = laX10UNIT[ liUnitCode ]
-
-  		if ((psCmd == RFXConstants.cmdOff) or (psCmd == RFXConstants.CmdGroupOff)) then
-  			liCommandCorrection = 32
-  			luup.log("cmdoff corr")
-  		end
-  	else
-  	  -- group command!  80 = off, 90 = on
-  	  liUnitByte = 0x80
-  	  liCommandCorrection = 0
-  		if ((psCmd == RFXConstants.cmdOn) or (psCmd == RFXConstants.CmdGroupOn)) then
-  		  liCommandCorrection = 16
-      end
-			luup.log("group cmd " .. liCommandCorrection )
-	  end
-	  
-		local liHouseCorrection = 0
-		if (liUnitCode >= 9) then
-			liHouseCorrection = 4
-		end
-	  liHouseByte = liHouseCorrection + liHouseByte
-		liUnitByte = liCommandCorrection + liUnitByte
-
-	  local lsResultstrA = string.format("%02X", bitw.band(bitw.bnot(liHouseByte),0x7fffffff))
-	  local lsResultstrB = string.format("%02X", bitw.band(bitw.bnot(liUnitByte),0x7fffffff))
-	  local lsResultstr = string.format("%02X%02X%s%02X%s", 0x20, liHouseByte, string.sub(lsResultstrA,7,8), liUnitByte, string.sub(lsResultstrB,7,8))
-  	return lsResultstr
-	end
-
-	------------------------------------------------------------------------------------			
-	-- decode X10 commands
-	------------------------------------------------------------------------------------			
-	function decodeX10(psCommand)
-	  local lsCommand = string.sub( psCommand, 2)
+  
+    local laX10HOUSE = { 0x60, 0x70, 0x40, 0x50, 0x80, 0x90, 0xa0, 0xb0, 0xe0, 0xf0, 0xc0, 0xd0, 0x00, 0x10, 0x20, 0x30 }
+    local laX10UNIT  = { 0x00, 0x10, 0x08, 0x18, 0x40, 0x50, 0x48, 0x58, 0x00, 0x10, 0x08, 0x18, 0x40, 0x50, 0x48, 0x58 }
+    
+    local lsHouseCode = string.sub(psID, 4, 4)
+    local liHouseCode = 1 + string.byte(lsHouseCode) - string.byte("A")
+    local liHouseByte = laX10HOUSE[ liHouseCode ]
+    
+    local lsUnitCode = ""
+    local liUnitCode = 0
+    local liUnitByte = 0
+    local liCommandCorrection = 0
+
+    if ( string.len( psID ) > 5 ) then
+      lsUnitCode = string.sub(psID, 5, 6)
+      liUnitCode = tonumber(lsUnitCode) 
+      liUnitByte = laX10UNIT[ liUnitCode ]
+
+      if ((psCmd == RFXConstants.cmdOff) or (psCmd == RFXConstants.CmdGroupOff)) then
+        liCommandCorrection = 32
+        luup.log("cmdoff corr")
+      end
+    else
+      -- group command!  80 = off, 90 = on
+      liUnitByte = 0x80
+      liCommandCorrection = 0
+      if ((psCmd == RFXConstants.cmdOn) or (psCmd == RFXConstants.CmdGroupOn)) then
+        liCommandCorrection = 16
+      end
+      luup.log("group cmd " .. liCommandCorrection )
+    end
+    
+    local liHouseCorrection = 0
+    if (liUnitCode >= 9) then
+      liHouseCorrection = 4
+    end
+    liHouseByte = liHouseCorrection + liHouseByte
+    liUnitByte = liCommandCorrection + liUnitByte
+
+    local lsResultstrA = string.format("%02X", bitw.band(bitw.bnot(liHouseByte),0x7fffffff))
+    local lsResultstrB = string.format("%02X", bitw.band(bitw.bnot(liUnitByte),0x7fffffff))
+    local lsResultstr = string.format("%02X%02X%s%02X%s", 0x20, liHouseByte, string.sub(lsResultstrA,7,8), liUnitByte, string.sub(lsResultstrB,7,8))
+    return lsResultstr
+  end
+
+  ------------------------------------------------------------------------------------      
+  -- decode X10 commands
+  ------------------------------------------------------------------------------------      
+  function decodeX10(psCommand)
+    local lsCommand = string.sub( psCommand, 2)
     local liCommandLength = string.len(lsCommand)
     local lsRFXMSG = ""
-		local lsSensorManufacturer = RFXConstants.sensorManufacturerX10
-		local lnSensorType = RFXConstants.sensorTypeControler
-		local lsID = ""
-		local lsCmd = ""
+    local lsSensorManufacturer = RFXConstants.sensorManufacturerX10
+    local lnSensorType = RFXConstants.sensorTypeControler
+    local lsID = ""
+    local lsCmd = ""
 
     luup.log("trying x10")
@@ -520,5 +515,7 @@
             liRecBytes = liRecBytes + bitw.rshift( bitw.band( string.byte(lsCommand, 3) , 0x8), 2)
             liRecBytes = liRecBytes + bitw.rshift( bitw.band( string.byte(lsCommand, 3) , 0x40), 4)
-            liRecBytes = liRecBytes + bitw.lshift( bitw.band( string.byte(lsCommand, 1) , 0x4), 1)
+            
+            -- hhg tip on forum. X10 Unit code 9 to 16 was recognized as 1 to 8. please read reply #87
+            liRecBytes = liRecBytes + bitw.lshift( bitw.band( string.byte(lsCommand, 3) , 0x4), 1)
             liRecBytes = liRecBytes + 1
 
@@ -541,18 +538,18 @@
     end
 
-		return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
-	end
-	
-	------------------------------------------------------------------------------------			
-	-- decode homeeasy / kaku commands
-	------------------------------------------------------------------------------------			
-	function decodeHomeEasy36(psCommand)
-		local lsSensorManufacturer = RFXConstants.sensorManufacturerHomeEasy
-		local lnSensorType = RFXConstants.sensorTypeControler
-		local lsID = ""
-		local lsCmd = ""
-		
-		-- 22 03 A1 C2 8B C0  ->  
-		-- Make ID as received bytes minus command
+    return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
+  end
+  
+  ------------------------------------------------------------------------------------      
+  -- decode homeeasy / kaku commands
+  ------------------------------------------------------------------------------------      
+  function decodeHomeEasy36(psCommand)
+    local lsSensorManufacturer = RFXConstants.sensorManufacturerHomeEasy
+    local lnSensorType = RFXConstants.sensorTypeControler
+    local lsID = ""
+    local lsCmd = ""
+    
+    -- 22 03 A1 C2 8B C0  ->  
+    -- Make ID as received bytes minus command
     lsID = lsID .. string.format("%02X", bitw.rshift( string.byte(psCommand, 2), 6))
     lsID = lsID .. string.format("%02X", bitw.lshift( bitw.band(string.byte(psCommand, 2), 0x3F), 2) + bitw.rshift(string.byte(psCommand, 3), 6))
@@ -561,149 +558,149 @@
     -- add button id to device.
     lsID = "HEA" .. lsID .. string.format("%01X", bitw.band( string.byte(psCommand, 5), 0x0F ) )
-							
-		-- Extract on/off/group on/group off command
-		local lnDataM = bitw.rshift( bitw.band( string.byte(psCommand, 5) , 0x30 ), 4 )
-		if (lnDataM == 0) then lsCmd = RFXConstants.cmdOff end
-		if (lnDataM == 1) then lsCmd = RFXConstants.cmdOn end
-		if (lnDataM == 2) then lsCmd = RFXConstants.cmdGroupOff end
-		if (lnDataM == 3) then lsCmd = RFXConstants.cmdGroupOn end
-		
-		-- Make message
-		lsRFXMSG = string.format ("[%s:%d ID: %s CMD: %d]", lsSensorManufacturer,lnSensorType, lsID, lsCmd)
- 		
-		return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
-	end
-
-	function decodeHomeEasy34(psCommand)
-		local lsSensorManufacturer = RFXConstants.sensorManufacturerHomeEasy
-		local lnSensorType = RFXConstants.sensorTypeControler
-		local lsID = ""
-		local lsCmd = ""
-				
-		lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy36(psCommand)
-		return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
-	end
-		
-	------------------------------------------------------------------------------------			
-	-- decode Visonic commands
-	------------------------------------------------------------------------------------			
-	function decodeVisonic( psCommand )
-		local lsRFXMSG = ""
-		local liCommandLength = string.len(psCommand)
-		local lnSensorType = 0
-		local lsSensorManufacturer = RFXConstants.sensorManufacturerVisonic
-		local lsCmd = ""
-		local lsID = ""
+              
+    -- Extract on/off/group on/group off command
+    local lnDataM = bitw.rshift( bitw.band( string.byte(psCommand, 5) , 0x30 ), 4 )
+    if (lnDataM == 0) then lsCmd = RFXConstants.cmdOff end
+    if (lnDataM == 1) then lsCmd = RFXConstants.cmdOn end
+    if (lnDataM == 2) then lsCmd = RFXConstants.cmdGroupOff end
+    if (lnDataM == 3) then lsCmd = RFXConstants.cmdGroupOn end
+    
+    -- Make message
+    lsRFXMSG = string.format ("[%s:%d ID: %s CMD: %d]", lsSensorManufacturer,lnSensorType, lsID, lsCmd)
+    
+    return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
+  end
+
+  function decodeHomeEasy34(psCommand)
+    local lsSensorManufacturer = RFXConstants.sensorManufacturerHomeEasy
+    local lnSensorType = RFXConstants.sensorTypeControler
+    local lsID = ""
+    local lsCmd = ""
+        
+    lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy36(psCommand)
+    return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
+  end
+    
+  ------------------------------------------------------------------------------------      
+  -- decode Visonic commands
+  ------------------------------------------------------------------------------------      
+  function decodeVisonic( psCommand )
+    local lsRFXMSG = ""
+    local liCommandLength = string.len(psCommand)
+    local lnSensorType = 0
+    local lsSensorManufacturer = RFXConstants.sensorManufacturerVisonic
+    local lsCmd = ""
+    local lsID = ""
 
     luup.log("trying Visonic")
-	luup.log("decodeV msg : " .. formattohex(psCommand))
+  luup.log("decodeV msg : " .. formattohex(psCommand))
     if ( liCommandLength >= 6 ) then
 
-  		-- First decode ID
-  		-- lsID = "VIS" .. string.format("%02X%02X%02X-%d",string.byte(psCommand, 2),string.byte(psCommand, 3),string.byte(psCommand, 6),string.byte(psCommand,2) * 256 + string.byte(psCommand,3)) 
-		lsID = "VIS" .. string.format("%02X", string.byte(psCommand, 2) )
-  		local liHsAddr = 0  
-  		--liHsAddr = createhsaddr(psCommand)
-		
-  		--if protocol = MODEB32 then
-  		--	lsRFXMSG = string.format(" addr: %02x%d",string.byte(psCommand, 2),liHsAddr)
-  		--else
-  		--	lsRFXMSG = string.format(" addr: %s ID: %d,lsDevice,liHsAddr)
-  		--end	
-		-- Next decode message data
-  		if string.byte(psCommand, 4) == 0x44 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdTamper
-  		elseif string.byte(psCommand, 4) == 0xC4 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdTamper
-  		elseif string.byte(psCommand, 4) == 0x4 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdAlert	
-  		elseif string.byte(psCommand, 4) == 0x5 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdBatteryLow
-  		elseif string.byte(psCommand, 4) == 0x84 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdNormal	
-  		elseif string.byte(psCommand, 4) == 0x85 then
-  			lnSensorType = RFXConstants.sensorTypeDoor
-  			lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdBatteryLow
-  		elseif string.byte(psCommand, 4) == 0x4C then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdTamper
-  		elseif string.byte(psCommand, 4) == 0xCC then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdTamper
-  		elseif string.byte(psCommand, 4) == 0x0C then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdAlert
-  		elseif string.byte(psCommand, 4) == 0x0D then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdBatteryLow
-  		elseif string.byte(psCommand, 4) == 0x8C then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdNormal
-  		elseif string.byte(psCommand, 4) == 0x8D then
-  			lnSensorType = RFXConstants.sensorTypeMotion
-  			lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdBatteryLow
-  		elseif string.byte(psCommand, 4) == 0xE0 then
-  			if string.byte(psCommand, 2) == 0xff then
-  				lsCmd = RFXConstants.cmdJamming -- Master receiver jamming detected
-  			elseif string.byte(psCommand, 2) == 0x0 then
-  				lsCmd = RFXConstants.cmdJamming -- Slave receiver jamming detected
-  			else
-  				-- Unknown data packet received
-  			end
-  		elseif string.byte(psCommand, 4) == 0xF8 then
-  			if string.byte(psCommand, 2) == 0xff then
-  				lsCmd = RFXConstants.cmdJamming -- Master receiver jamming detected
-  			elseif string.byte(psCommand, 2) == 0x0 then
-  				lsCmd = RFXConstants.cmdJamming -- Slave receiver jamming detected
-  			else
-  				-- Unknown command
-  			end
-		
-		-- Marmitek KR21 code
-		elseif string.byte(psCommand, 4) == 0x6 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdArmAway
-		elseif string.byte(psCommand, 4) == 0x86 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdDisarm	
-		elseif string.byte(psCommand, 4) == 0x46 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdOn
-		elseif string.byte(psCommand, 4) == 0xC6 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdOff
-			
-		elseif string.byte(psCommand, 4) == 0x2 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdArmAway	
-  		elseif string.byte(psCommand, 4) == 0xE then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdArmHome
-  		elseif string.byte(psCommand, 4) == 0x22 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdPanic	
-  		elseif string.byte(psCommand, 4) == 0x42 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdGroupOn	
-		elseif string.byte(psCommand, 4) == 0x82 then
-  			lnSensorType = RFXConstants.sensorTypeKeyFob
-  			lsCmd = RFXConstants.cmdDisarm
+      -- First decode ID
+      -- lsID = "VIS" .. string.format("%02X%02X%02X-%d",string.byte(psCommand, 2),string.byte(psCommand, 3),string.byte(psCommand, 6),string.byte(psCommand,2) * 256 + string.byte(psCommand,3)) 
+    lsID = "VIS" .. string.format("%02X", string.byte(psCommand, 2) )
+      local liHsAddr = 0  
+      --liHsAddr = createhsaddr(psCommand)
+    
+      --if protocol = MODEB32 then
+      --  lsRFXMSG = string.format(" addr: %02x%d",string.byte(psCommand, 2),liHsAddr)
+      --else
+      --  lsRFXMSG = string.format(" addr: %s ID: %d,lsDevice,liHsAddr)
+      --end 
+    -- Next decode message data
+      if string.byte(psCommand, 4) == 0x44 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdTamper
+      elseif string.byte(psCommand, 4) == 0xC4 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdTamper
+      elseif string.byte(psCommand, 4) == 0x4 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdAlert 
+      elseif string.byte(psCommand, 4) == 0x5 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdBatteryLow
+      elseif string.byte(psCommand, 4) == 0x84 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdNormal  
+      elseif string.byte(psCommand, 4) == 0x85 then
+        lnSensorType = RFXConstants.sensorTypeDoor
+        lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdBatteryLow
+      elseif string.byte(psCommand, 4) == 0x4C then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdTamper
+      elseif string.byte(psCommand, 4) == 0xCC then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdTamper
+      elseif string.byte(psCommand, 4) == 0x0C then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdAlert
+      elseif string.byte(psCommand, 4) == 0x0D then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdAlert + RFXConstants.cmdBatteryLow
+      elseif string.byte(psCommand, 4) == 0x8C then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdNormal
+      elseif string.byte(psCommand, 4) == 0x8D then
+        lnSensorType = RFXConstants.sensorTypeMotion
+        lsCmd = RFXConstants.cmdNormal + RFXConstants.cmdBatteryLow
+      elseif string.byte(psCommand, 4) == 0xE0 then
+        if string.byte(psCommand, 2) == 0xff then
+          lsCmd = RFXConstants.cmdJamming -- Master receiver jamming detected
+        elseif string.byte(psCommand, 2) == 0x0 then
+          lsCmd = RFXConstants.cmdJamming -- Slave receiver jamming detected
         else
-  			-- Unknown data packet received
-  		end
-		
-  		-- Create RFXMSG text
-  		lsRFXMSG = string.format ("[%s:%d ID: %s CMD: %s]", lsSensorManufacturer,lnSensorType, lsID, lsCmd)
-		end
-  	
-		return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
-	end
-	
-	
+          -- Unknown data packet received
+        end
+      elseif string.byte(psCommand, 4) == 0xF8 then
+        if string.byte(psCommand, 2) == 0xff then
+          lsCmd = RFXConstants.cmdJamming -- Master receiver jamming detected
+        elseif string.byte(psCommand, 2) == 0x0 then
+          lsCmd = RFXConstants.cmdJamming -- Slave receiver jamming detected
+        else
+          -- Unknown command
+        end
+    
+    -- Marmitek KR21 code
+    elseif string.byte(psCommand, 4) == 0x6 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdArmAway
+    elseif string.byte(psCommand, 4) == 0x86 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdDisarm  
+    elseif string.byte(psCommand, 4) == 0x46 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdOn
+    elseif string.byte(psCommand, 4) == 0xC6 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdOff
+      
+    elseif string.byte(psCommand, 4) == 0x2 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdArmAway 
+      elseif string.byte(psCommand, 4) == 0xE then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdArmHome
+      elseif string.byte(psCommand, 4) == 0x22 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdPanic 
+      elseif string.byte(psCommand, 4) == 0x42 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdGroupOn 
+    elseif string.byte(psCommand, 4) == 0x82 then
+        lnSensorType = RFXConstants.sensorTypeKeyFob
+        lsCmd = RFXConstants.cmdDisarm
+        else
+        -- Unknown data packet received
+      end
+    
+      -- Create RFXMSG text
+      lsRFXMSG = string.format ("[%s:%d ID: %s CMD: %s]", lsSensorManufacturer,lnSensorType, lsID, lsCmd)
+    end
+    
+    return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
+  end
+  
+  
     function createhsaddr(psCommand)
         local liHsAddr = 0
@@ -757,5 +754,5 @@
             liHsAddr = bitw.bor(liHsAddr,0x100)
         end
-		
+    
         return liHsAddr
     end
@@ -763,222 +760,256 @@
     
   function decodeOregon(psCommand)
-	local lsCommand = string.sub( psCommand, 2)
-	local lsRFXMSG = ""
-	local lnSensorType = 0
-	local lsID = ""
-	local lsCmd = ""
-	local lsSensorManufacturer = ""
-	local liBitLength = bitw.band( string.byte(psCommand, 1), 0x7f)
-	if ( ( string.byte(lsCommand, 1) == 0x3a ) and ( string.byte(lsCommand, 2) == 0x0d ) ) then
-	  luup.log("Identified Oregon WGR918")
-      	  
-	  lnSensorType = RFXConstants.sensorTypeWindDirection + RFXConstants.sensorTypeWindSpeed + RFXConstants.sensorTypeWindSpeedAv
+  local lsCommand = string.sub( psCommand, 2)
+  local lsRFXMSG = ""
+  local lnSensorType = 0
+  local lsID = ""
+  local lsCmd = ""
+  local lsSensorManufacturer = ""
+  local liBitLength = bitw.band( string.byte(psCommand, 1), 0x7f)
+  if ( ( string.byte(lsCommand, 1) == 0x3a ) and ( string.byte(lsCommand, 2) == 0x0d ) ) then
+    luup.log("Identified Oregon WGR918")
+          
+    lnSensorType = RFXConstants.sensorTypeWindDirection + RFXConstants.sensorTypeWindSpeed + RFXConstants.sensorTypeWindSpeedAv
       lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-      local liDataDir = string.byte(lsCommand, 6) * 10 + bitw.rshift(string.byte(lsCommand, 5), 4)
+      local lnDataDir = (string.byte(lsCommand, 6) * 10 + bitw.rshift(string.byte(lsCommand, 5), 4) ) / 10
       local lnDataSpeed = bitw.band( string.byte(lsCommand, 8) , 0x0f) * 10 + (string.byte(lsCommand, 7) / 10 )
       local lnDataSpeedav = string.byte(lsCommand, 9) + ( bitw.rshift( string.byte(lsCommand, 8), 4) / 10)
       
-	  lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	  lsCmd = string.format("direction=%3d;speed=%5.2f;speedav=%5.2f",liDataDir, lnDataSpeed, lnDataSpeedav)
-      lsRFXMSG = string.format("[OREGON: WIND3 Device: %s Direction: %3d Speed: %5.2f Speed av: %5.2f]", lsID, liDataDir, lnDataSpeed, lnDataSpeedav)
-
-	elseif ( ( string.byte(lsCommand, 1) == 0x1A ) and ( string.byte(lsCommand, 2) == 0x2d ) ) then
-		luup.log("Identified Oregon THGN122N,THGR122NX,THGR228N,THGR268")
-
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-	  
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
-		
-		-- Support for Oregon THWR800 ca48 68
-	elseif ( ( string.byte(lsCommand, 1) == 0xca ) and ( string.byte(lsCommand, 2) == 0x48 ) ) then
-		luup.log("Identified Oregon THWR800")
-
-		lnSensorType = RFXConstants.sensorTypeTemperature
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-			  
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;battery=%d", lnDataTemp, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %5.1f Battery: %d]", lsID, lnDataTemp, lnDataBattery)
-
-		-- Support for Oregon THGR810 fa28 80
-	elseif ( ( string.byte(lsCommand, 1) == 0xfa ) and ( string.byte(lsCommand, 2) == 0x28 ) ) then
-		luup.log("Identified Oregon THGR810")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
-		
-		-- Support for Oregon THWR288A ea4c 68
-	elseif ( ( string.byte(lsCommand, 1) == 0xea ) and ( string.byte(lsCommand, 2) == 0x4c ) ) then
-		luup.log("Identified Oregon THWR288A")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
-	
-	
-	-- Support for Oregon TH3 Oregon RTGR328N 
-	elseif ( ( bitw.band(string.byte(lsCommand, 1), 0x0f) == 0x0a ) and ( string.byte(lsCommand, 2) == 0xcc ) ) then
-		luup.log("Identified Oregon TH3 RTGR328N ")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
-
-	-- Support for Oregon TH4 Oregon THGR328
-	elseif ( ( string.byte(lsCommand, 1) == 0xca ) and ( string.byte(lsCommand, 2) == 0x2c ) ) then
-		luup.log("Identified Oregon TH4 RTGR328 ")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
-		
-	-- Support for Oregon WTGR800 fab8 80
-	elseif ( ( string.byte(lsCommand, 1) == 0xfa ) and ( string.byte(lsCommand, 2) == 0xb8 ) ) then
-		luup.log("Identified Oregon WTGR800")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataPercentBattery = getOregonPercentBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lsID = "ORF" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataPercentBattery)
-		lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %5.1f Humidity: %d  Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataPercentBattery)
-		
-	-- Support for Oregon WTGR800 1A99 88
-	elseif ( ( string.byte(lsCommand, 1) == 0x1a ) and ( string.byte(lsCommand, 2) == 0x99 ) ) then
-		luup.log("Identified Oregon Anemo WTGR800")
-	
-		lnSensorType = RFXConstants.sensorTypeWindDirection
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+    lsCmd = string.format("direction=%.1f;speed=%.2f;speedav=%.2f",lnDataDir, lnDataSpeed, lnDataSpeedav)
+      lsRFXMSG = string.format("[OREGON: WIND3 Device: %s Direction: %.1f Speed: %.2f Speed av: %.2f]", lsID, lnDataDir, lnDataSpeed, lnDataSpeedav)
+
+  elseif ( ( string.byte(lsCommand, 1) == 0x1A ) and ( string.byte(lsCommand, 2) == 0x2d ) ) then
+    luup.log("Identified Oregon THGN122N,THGR122NX,THGR228N,THGR268")
+
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %5.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
+    
+    -- Support for Oregon THWR800 ca48 68
+  elseif ( ( string.byte(lsCommand, 1) == 0xca ) and ( string.byte(lsCommand, 2) == 0x48 ) ) then
+    luup.log("Identified Oregon THWR800")
+
+    lnSensorType = RFXConstants.sensorTypeTemperature
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+        
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;battery=%d", lnDataTemp, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %.1f Battery: %d]", lsID, lnDataTemp, lnDataBattery)
+
+    -- Support for Oregon THGR810 fa28 80
+  elseif ( ( string.byte(lsCommand, 1) == 0xfa ) and ( string.byte(lsCommand, 2) == 0x28 ) ) then
+    luup.log("Identified Oregon THGR810")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
+    
+    -- Support for Oregon THWR288A ea4c 68
+  elseif ( ( string.byte(lsCommand, 1) == 0xea ) and ( string.byte(lsCommand, 2) == 0x4c ) ) then
+    luup.log("Identified Oregon THWR288A")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
+  
+  
+  -- Support for Oregon TH3 Oregon RTGR328N 
+  elseif ( ( bitw.band(string.byte(lsCommand, 1), 0x0f) == 0x0a ) and ( string.byte(lsCommand, 2) == 0xcc ) ) then
+    luup.log("Identified Oregon TH3 RTGR328N ")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
+
+  -- Support for Oregon TH4 Oregon THGR328
+  elseif ( ( string.byte(lsCommand, 1) == 0xca ) and ( string.byte(lsCommand, 2) == 0x2c ) ) then
+    luup.log("Identified Oregon TH4 RTGR328 ")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temp1 Device: %s Temperature: %.1f Humidity: %d Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataBattery)
+    
+  -- Support for Oregon WTGR800 fab8 80
+  elseif ( ( string.byte(lsCommand, 1) == 0xfa ) and ( string.byte(lsCommand, 2) == 0xb8 ) ) then
+    luup.log("Identified Oregon WTGR800")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity 
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataPercentBattery = getOregonPercentBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lsID = "ORF" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;battery=%d", lnDataTemp, lnDataHum, lnDataPercentBattery)
+    lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %.1f Humidity: %d  Battery: %d]", lsID, lnDataTemp, lnDataHum, lnDataPercentBattery)
+    
+  -- Support for Oregon WTGR800 1A99 88
+  elseif ( ( string.byte(lsCommand, 1) == 0x1a ) and ( string.byte(lsCommand, 2) == 0x99 ) ) then
+    luup.log("Identified Oregon Anemo WTGR800")
+  
+    lnSensorType = RFXConstants.sensorTypeWindDirection
     -- + RFXConstants.sensorTypeWindSpeed + RFXConstants.sensorTypeWindSpeedAv
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-
-		local liDataDir = nib(lsCommand,8) * 22.5
-		local lnDataSpeed = nib(lsCommand,15)*10 + nib(lsCommand,12) + nib(lsCommand,13)/10
-		local lnDataSpeedav = nib(lsCommand,16)*10 + nib(lsCommand,17) + nib(lsCommand,14)/10
-		local lnDataPercentBattery = getOregonPercentBattery(lsCommand)
-
-		--conversion mps en kmh
-		--lnDataSpeed = lnDataSpeed * 3.6
-		--lnDataSpeedav = lnDataSpeedav * 3.6
-
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-		lsCmd = string.format("direction=%.2f;speed=%.2f;speedav=%.2f;battery=%d",liDataDir, lnDataSpeed, lnDataSpeedav, lnDataPercentBattery)
-		lsRFXMSG = string.format("[OREGON: Anemometer Device: %s Direction: %5.1f  Speed: %5.1f mps  Speed av: %5.1f mps  Battery: %d]", lsID, liDataDir, lnDataSpeed, lnDataSpeedav, lnDataPercentBattery)
-		
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+
+    local liDataDir = nib(lsCommand,8) * 22.5
+    local lnDataSpeed = nib(lsCommand,15)*10 + nib(lsCommand,12) + nib(lsCommand,13)/10
+    local lnDataSpeedav = nib(lsCommand,16)*10 + nib(lsCommand,17) + nib(lsCommand,14)/10
+    local lnDataPercentBattery = getOregonPercentBattery(lsCommand)
+
+    --conversion mps en kmh
+    --lnDataSpeed = lnDataSpeed * 3.6
+    --lnDataSpeedav = lnDataSpeedav * 3.6
+
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+    lsCmd = string.format("direction=%.2f;speed=%.2f;speedav=%.2f;battery=%d",liDataDir, lnDataSpeed, lnDataSpeedav, lnDataPercentBattery)
+    lsRFXMSG = string.format("[OREGON: Anemometer Device: %s Direction: %.1f  Speed: %.1f mps  Speed av: %.1f mps  Battery: %d]", lsID, liDataDir, lnDataSpeed, lnDataSpeedav, lnDataPercentBattery)
+    
          -- Support for Oregon BTHR918N 5a6d 96
-	elseif ( ( string.byte(lsCommand, 1) == 0x5a ) and ( string.byte(lsCommand, 2) == 0x6d ) ) then
-		luup.log("Identified Oregon BTHR918N")
-		lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity + RFXConstants.sensorTypeBarometer
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		
-		local lnDataTemp = getOregonTemperature(lsCommand)
-		local lnDataBattery = getOregonBattery(lsCommand)
-		local lnDataHum = getOregonHumidity(lsCommand)
-		
-		lnDataPres = 856 + string.byte(lsCommand, 9)
-	    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("temperature=%.1f;humidity=%d;pressure=%s;battery=%d", lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %5.1f Humidity: %d Pressure: %s Battery: %s]", lsID, lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
-
-		-- Support for Oregon PCR800 2a19 92
-	elseif ( ( string.byte(lsCommand, 1) == 0x2a ) and ( string.byte(lsCommand, 2) == 0x19 ) ) then
-		luup.log("Identified Oregon PCR800")
-		lnSensorType = RFXConstants.sensorTypeRain
-		lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
-		local lnDataRain = 0.0
-		local lnDataTRain = 0.0
-		local lnDataBattery = getOregonBattery(lsCommand)
-		
-		lnDataRain = bitw.band(bitw.lshift(string.byte(lsCommand, 7), 0),0x0f) * 10 + bitw.band(bitw.rshift(string.byte(lsCommand, 6), 4),0x0f) 
-		+ bitw.band(bitw.lshift(string.byte(lsCommand, 6), 0),0x0f) / 10 + bitw.band(bitw.rshift(string.byte(lsCommand, 5), 4),0x0f) / 100 
-		lnDataRain = 25.4 * lnDataRain
-		
-		lnDataTRain = bitw.band(bitw.lshift(string.byte(lsCommand, 10), 0),0x0f) * 1000 + bitw.band(bitw.rshift(string.byte(lsCommand, 9), 4),0x0f) * 10 
-		+ bitw.band(bitw.lshift(string.byte(lsCommand, 9), 0),0x0f) + bitw.band(bitw.rshift(string.byte(lsCommand, 8), 4),0x0f) / 10 
-		+ bitw.band(bitw.lshift(string.byte(lsCommand, 8), 0),0x0f) / 100 + bitw.band(bitw.rshift(string.byte(lsCommand, 7), 4),0x0f) / 1000
-				
-		lnDataTRain = 25.4 * lnDataTRain
-							  
-		lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
-	    lsCmd = string.format("rain=%s;train=%s;battery=%d", lnDataRain, lnDataTRain, lnDataBattery)
-		lsRFXMSG = string.format("[OREGON: Rain Device: %s Rain: %s TRain: %s Battery: %s]", lsID, lnDataRain, lnDataTRain, lnDataBattery)
-    end
-
-	return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
+  elseif ( ( string.byte(lsCommand, 1) == 0x5a ) and ( string.byte(lsCommand, 2) == 0x6d ) ) then
+    luup.log("Identified Oregon BTHR918N")
+    lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity + RFXConstants.sensorTypeBarometer
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    
+    local lnDataTemp = getOregonTemperature(lsCommand)
+    local lnDataBattery = getOregonBattery(lsCommand)
+    local lnDataHum = getOregonHumidity(lsCommand)
+    
+    lnDataPres = 856 + string.byte(lsCommand, 9)
+      lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;pressure=%s;battery=%d", lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %.1f Humidity: %d Pressure: %s Battery: %s]", lsID, lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
+
+    -- Support for Oregon PCR800 2a19 92
+  elseif ( ( string.byte(lsCommand, 1) == 0x2a ) and ( string.byte(lsCommand, 2) == 0x19 ) ) then
+    luup.log("Identified Oregon PCR800")
+    lnSensorType = RFXConstants.sensorTypeRain
+    lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+    local lnDataRain = 0.0
+    local lnDataTRain = 0.0
+    local lnDataBattery = getOregonBattery(lsCommand)
+    
+    lnDataRain = bitw.band(bitw.lshift(string.byte(lsCommand, 7), 0),0x0f) * 10 + bitw.band(bitw.rshift(string.byte(lsCommand, 6), 4),0x0f) 
+      + bitw.band(bitw.lshift(string.byte(lsCommand, 6), 0),0x0f) / 10 + bitw.band(bitw.rshift(string.byte(lsCommand, 5), 4),0x0f) / 100 
+    lnDataRain = 25.4 * lnDataRain
+    
+    lnDataTRain = bitw.band(bitw.lshift(string.byte(lsCommand, 10), 0),0x0f) * 1000 + bitw.band(bitw.rshift(string.byte(lsCommand, 9), 4),0x0f) * 10 
+      + bitw.band(bitw.lshift(string.byte(lsCommand, 9), 0),0x0f) + bitw.band(bitw.rshift(string.byte(lsCommand, 8), 4),0x0f) / 10 
+      + bitw.band(bitw.lshift(string.byte(lsCommand, 8), 0),0x0f) / 100 + bitw.band(bitw.rshift(string.byte(lsCommand, 7), 4),0x0f) / 1000
+        
+    lnDataTRain = 25.4 * lnDataTRain
+                
+    lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+    lsCmd = string.format("rain=%s;train=%s;battery=%d", lnDataRain, lnDataTRain, lnDataBattery)
+    lsRFXMSG = string.format("[OREGON: Rain Device: %s Rain: %s TRain: %s Battery: %s]", lsID, lnDataRain, lnDataTRain, lnDataBattery)
+    
+      -- Support for Oregon RGR126,RGR682,RGR918 2A1D 84  :  54 2A 1D 00 F9 00 00 12 91 A5 43 04  
+    elseif ( ( string.byte(lsCommand, 1) == 0x2a ) and ( string.byte(lsCommand, 2) == 0x1D ) ) then
+      luup.log("Identified Oregon RGR126,RGR682,RGR918")
+      lnSensorType = RFXConstants.sensorTypeRain
+      lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+      local lnDataRain = 0.0
+      local lnDataTRain = 0.0
+      local lnDataBattery = getOregonBattery(lsCommand)
+
+      lnDataRain = bitw.band(bitw.lshift(string.byte(lsCommand, 6), 0),0xff) * 10 + bitw.band(bitw.rshift(string.byte(lsCommand, 5), 4),0x0f) 
+
+      lnDataTRain = bitw.band(bitw.lshift(string.byte(lsCommand, 9), 0),0x0f) * 1000 + bitw.band(bitw.rshift(string.byte(lsCommand, 8), 0),0xff) * 10 
+        + bitw.band(bitw.rshift(string.byte(lsCommand, 7), 4),0x0f) 
+
+      lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("rain=%s;train=%s;battery=%d", lnDataRain, lnDataTRain, lnDataBattery)
+      lsRFXMSG = string.format("[OREGON: Rain Device: %s Rain: %s TRain: %s Battery: %s]", lsID, lnDataRain, lnDataTRain, lnDataBattery)
+      
+    -- Support for Oregon THGR918 1A3D   
+    elseif ( ( string.byte(lsCommand, 1) == 0x1a ) and ( string.byte(lsCommand, 2) == 0x3D ) ) then
+      luup.log("Identified Oregon THGR918")
+      lnSensorType = RFXConstants.sensorTypeTemperature + RFXConstants.sensorTypeHumidity + RFXConstants.sensorTypeBarometer
+      lsSensorManufacturer = RFXConstants.sensorManufacturerOregon
+
+      local lnDataTemp = getOregonTemperature(lsCommand)
+      local lnDataBattery = getOregonBattery(lsCommand)
+      local lnDataHum = getOregonHumidity(lsCommand)
+
+      lnDataPres = 795 + string.byte(lsCommand, 9)
+      lsID = "ORE" .. string.format("%02X", string.byte(lsCommand, 4) )
+      lsCmd = string.format("temperature=%.1f;humidity=%d;pressure=%s;battery=%d", lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
+      lsRFXMSG = string.format("[OREGON: Temperature Device: %s Temperature: %.1f Humidity: %d Pressure: %s Battery: %s]", lsID, lnDataTemp, lnDataHum, lnDataPres, lnDataBattery)
+
+    end
+
+    return lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer
   end    
-	
-	function getOregonTemperature(lsCommand)
-		local lnData = nib(lsCommand,10) * 10 + nib(lsCommand,11) + nib(lsCommand,8)/10
-		if (bitw.band( string.byte(lsCommand, 7) , 0x08) == 0) then
-		lnData = lnData
-		else
-		lnData = 0-lnData
-		end
-		return lnData
+  
+  function getOregonTemperature(lsCommand)
+    local lnData = nib(lsCommand,10) * 10 + nib(lsCommand,11) + nib(lsCommand,8)/10
+    if (bitw.band( string.byte(lsCommand, 7) , 0x08) == 0) then
+    lnData = lnData
+    else
+    lnData = 0-lnData
+    end
+    return lnData
     end
 
     function getOregonHumidity(lsCommand)
-		local lnData = nib(lsCommand,15) * 10 + nib(lsCommand,12)
-		return lnData
+    local lnData = nib(lsCommand,15) * 10 + nib(lsCommand,12)
+    return lnData
     end
 
     function getOregonBattery(lsCommand)
-		local battery_low = bitw.band( string.byte(lsCommand, 3) , 0x04)
-		local lnData = 90 --'hight'
-		if battery_low == 1 then
-			lnData = 10 --'low'
-		end
+    local battery_low = bitw.band( string.byte(lsCommand, 3) , 0x04)
+    local lnData = 90 --'high'
+    if battery_low == 1 then
+      lnData = 10 --'low'
+    end
     return lnData
     end
 
     function getOregonPercentBattery(lsCommand)
-		local lnData = 100 - 10*nib(lsCommand,9)
-		return lnData
+    local lnData = 100 - 10*nib(lsCommand,9)
+    return lnData
     end
 
     function nib(lsCommand,i)
-		local n = (i-i%2)/2 + 1
-		if (i%2 == 0) then
-		return bitw.band(bitw.rshift(string.byte(lsCommand, n), 4),0x0f)
-		else
-		return bitw.band(string.byte(lsCommand, n),0x0f)
-		end
+    local n = (i-i%2)/2 + 1
+    if (i%2 == 0) then
+    return bitw.band(bitw.rshift(string.byte(lsCommand, n), 4),0x0f)
+    else
+    return bitw.band(string.byte(lsCommand, n),0x0f)
+    end
     end
 
@@ -1013,7 +1044,7 @@
       -- Log found message and decode!!
       if ( lsCommand ~= nil and #lsCommand > 0 ) then
-  			-- luup.log("RFX message compleet: " .. formattohex(lsCommand))
-  			table.insert( RFXmsgTable, lsCommand )
-  			luup.call_delay("processMessage", 0 , "none")
+        -- luup.log("RFX message compleet: " .. formattohex(lsCommand))
+        table.insert( RFXmsgTable, lsCommand )
+        luup.call_delay("processMessage", 0 , "none")
       end
 
@@ -1024,567 +1055,564 @@
   end
  
-	------------------------------------------------------------------------------------			
-	-- Main routine to decode and process the received messages
-	------------------------------------------------------------------------------------			
+  ------------------------------------------------------------------------------------      
+  -- Main routine to decode and process the received messages
+  ------------------------------------------------------------------------------------      
   function processMessage(psCommand)
-		while ( #RFXmsgTable > 0 ) do
-			local lsRFXMSG = ""
-			local lnSensorType = 0
-			local lsID = ""
-			local lsCmd = ""
-			local lsSensorManufacturer = ""
-
-			psCommand = table.remove( RFXmsgTable, 1)
-			local liBitLength = bitw.band( string.byte(psCommand, 1), 0x7f)
-
-			luup.log(string.format("decodeMessage bits:%d data:%s",liBitLength,formattohex(psCommand)))
-
-			--psCommand = GetStringPart( psCommand, 2, string.len( psCommand ) -1 )
-			--local liCommandLength = string.len(psCommand)
-
-			-- Decode based on bitlength
-			if liBitLength == 12 then
-				luup.log("decodeHomeEasyHeater12")
-			elseif liBitLength == 13 then
-				luup.log("decodeMertikMaxitrol13")
-			elseif liBitLength == 20 then
-				luup.log("decodeATIRemoteWonder20")
-			elseif liBitLength == 22 then
-				luup.log("decodeRobocamNinja22")
-			elseif liBitLength == 24 then
-				luup.log("decodeArc24")
-				luup.log("decodeWaveman24")
-			elseif liBitLength == 25 then
-				luup.log("decodeHarrison25")
-			elseif liBitLength == 26 then
-				luup.log("decodeIkeaKoppla26")
-			elseif liBitLength == 32 then
-				luup.log("decodeX1032")
-				luup.log("decodeDM1032")
-				luup.log("decodePCRemote32")
-				luup.log("decodeRFXSensor32")			
+    while ( #RFXmsgTable > 0 ) do
+      local lsRFXMSG = ""
+      local lnSensorType = 0
+      local lsID = ""
+      local lsCmd = ""
+      local lsSensorManufacturer = ""
+
+      psCommand = table.remove( RFXmsgTable, 1)
+      local liBitLength = bitw.band( string.byte(psCommand, 1), 0x7f)
+
+      luup.log(string.format("decodeMessage bits:%d data:%s",liBitLength,formattohex(psCommand)))
+
+      --psCommand = GetStringPart( psCommand, 2, string.len( psCommand ) -1 )
+      --local liCommandLength = string.len(psCommand)
+
+      -- Decode based on bitlength
+      if liBitLength == 12 then
+        luup.log("decodeHomeEasyHeater12")
+      elseif liBitLength == 13 then
+        luup.log("decodeMertikMaxitrol13")
+      elseif liBitLength == 20 then
+        luup.log("decodeATIRemoteWonder20")
+      elseif liBitLength == 22 then
+        luup.log("decodeRobocamNinja22")
+      elseif liBitLength == 24 then
+        luup.log("decodeArc24")
+        luup.log("decodeWaveman24")
+      elseif liBitLength == 25 then
+        luup.log("decodeHarrison25")
+      elseif liBitLength == 26 then
+        luup.log("decodeIkeaKoppla26")
+      elseif liBitLength == 32 then
+        luup.log("decodeX1032")
+        luup.log("decodeDM1032")
+        luup.log("decodePCRemote32")
+        luup.log("decodeRFXSensor32")     
         lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeX10( psCommand )
-			elseif liBitLength == 33 then
-				luup.log("decodeHomeEasy33")							
-			elseif liBitLength == 34  then
-				lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy34(psCommand)
-			elseif liBitLength == 36  then
-				lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy36(psCommand)
-			elseif liBitLength == 37 then
-				luup.log("decodeHomeEasy37")							
-			elseif liBitLength == 41 then
-				luup.log("decodeX10Security41")
-				lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeVisonic(psCommand)
-			elseif liBitLength == 44 then
-				luup.log("decodeDigimaxRTS1044")							
-			elseif liBitLength == 47 then
-				luup.log("decodeCheaperTronics47")
-			elseif liBitLength == 56 or liBitLength > 59 then
-				luup.log("decodeoregon")
-				lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeOregon(psCommand)
-			end
-			
-			if ( string.len( lsRFXMSG ) == 0 ) then
-				luup.log("Unknown Msg : " .. formattohex(psCommand) )
-			else
-				------------------------------------------------------------------------------------			
-				-- ignore repeated messages.
-				-- Really new and decoded messages must be processed. After processing, update
-				-- last message variable
-				-- Unfortunately this sometimes has an unwanted effect. This is why after a pause we need
-				-- to forget the last message...
-				------------------------------------------------------------------------------------	
-				
-				if ((os.time() - RFXLastMsgTime) > 10) then
-				  RFXLastMsg = ""
-				end
-						
-				if ( RFXLastMsg ~= lsRFXMSG ) then
-					actOnMessage(lnSensorType,lsID,lsCmd)								
-					luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "Message", lsRFXMSG, THIS_DEVICE)
-					luup.log( lsRFXMSG )
-				end
-			end
-			
-			RFXLastMsgTime = os.time()
-			RFXLastMsg = lsRFXMSG
-		end
-	end
-
-	 
-	------------------------------------------------------------------------
-	-- Act on decoded message
-	-- 
-	-- If variable 'AutoCreate' is set to 1 and a received sensor doesn't
-	-- exist yet, it's created. 
-	-- Next execution depends on kind of sensor
-	-- Controller (lightswitch): Status variable is set based on cmdOn or cmdOff
-	-- Motion Sensor: Tripped status is set
-	-- Door Sensor: Tripped status is set
-	-- KeyFox: All door and motion sensors are armed or disarmed
-	------------------------------------------------------------------------
-
-	function actOnMessage(lnSensorType,lsID,lsCmd)
-
-		luup.log("Received command " .. lsCmd .. " for " .. lnSensorType .. " with ID " .. lsID)    
-
-		-- Check if we can find a device with the decoded ID and ourself as parent
-		local device = findChild(THIS_DEVICE, lsID )
+      elseif liBitLength == 33 then
+        luup.log("decodeHomeEasy33")              
+      elseif liBitLength == 34  then
+        lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy34(psCommand)
+      elseif liBitLength == 36  then
+        lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeHomeEasy36(psCommand)
+      elseif liBitLength == 37 then
+        luup.log("decodeHomeEasy37")              
+      elseif liBitLength == 41 then
+        luup.log("decodeX10Security41")
+        lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeVisonic(psCommand)
+      elseif liBitLength == 44 then
+        luup.log("decodeDigimaxRTS1044")              
+      elseif liBitLength == 47 then
+        luup.log("decodeCheaperTronics47")
+      elseif liBitLength == 56 or liBitLength > 59 then
+        luup.log("decodeoregon")
+        lsRFXMSG,lnSensorType,lsID,lsCmd,lsSensorManufacturer = decodeOregon(psCommand)
+      end
+      
+      if ( string.len( lsRFXMSG ) == 0 ) then
+        luup.log("Unknown Msg : " .. formattohex(psCommand) )
+      else
+        ------------------------------------------------------------------------------------      
+        -- ignore repeated messages.
+        -- Really new and decoded messages must be processed. After processing, update
+        -- last message variable
+        -- Unfortunately this sometimes has an unwanted effect. This is why after a pause we need
+        -- to forget the last message...
+        ------------------------------------------------------------------------------------  
+        
+        if ((os.time() - RFXLastMsgTime) > 10) then
+          RFXLastMsg = ""
+        end
+            
+        if ( RFXLastMsg ~= lsRFXMSG ) then
+          actOnMessage(lnSensorType,lsID,lsCmd)               
+          luup.variable_set("urn:upnp-esweb-nl:serviceId:rfxcom1", "Message", lsRFXMSG, THIS_DEVICE)
+          luup.log( lsRFXMSG )
+        end
+      end
+      
+      RFXLastMsgTime = os.time()
+      RFXLastMsg = lsRFXMSG
+    end
+  end
+
+   
+  ------------------------------------------------------------------------
+  -- Act on decoded message
+  -- 
+  -- If variable 'AutoCreate' is set to 1 and a received sensor doesn't
+  -- exist yet, it's created. 
+  -- Next execution depends on kind of sensor
+  -- Controller (lightswitch): Status variable is set based on cmdOn or cmdOff
+  -- Motion Sensor: Tripped status is set
+  -- Door Sensor: Tripped status is set
+  -- KeyFox: All door and motion sensors are armed or disarmed
+  ------------------------------------------------------------------------
+
+  function actOnMessage(lnSensorType,lsID,lsCmd)
+
+    luup.log("Received command " .. lsCmd .. " for " .. lnSensorType .. " with ID " .. lsID)    
+
+    -- Check if we can find a device with the decoded ID and ourself as parent
+    local device = findChild(THIS_DEVICE, lsID )
      
-		----------------------------------------------------------------------------------------
-		-- If we can't find a device and we have autocreate active, setup a new tree with child devices
-		-- and add a new child with the correct type and ID
-		----------------------------------------------------------------------------------------
-		if device == nil and luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", lul_device) == "1" then
-			luup.log( "device not found and autocreate enabled..." ) 
-			
-			local child_devices = luup.chdev.start(THIS_DEVICE);  
-
-			------------------------------------------------------------------------------------			
-			-- First add all 'old' children to the three
-			-- Start with door sensors
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountDS do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesDS[teller], "RFX DS sensor #" .. RFXDevicesDS[teller] , 
-				"urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false)
-			end
-			------------------------------------------------------------------------------------			
-			-- Next with motion sensors
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountMS do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesMS[teller], "RFX MS sensor #" .. RFXDevicesMS[teller] , 
-				"urn:schemas-micasaverde-com:device:MotionSensor:1","D_MotionSensor1.xml","","",false)
-			end			
-			------------------------------------------------------------------------------------			
-			-- Next with keyfobs
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountKF do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesKF[teller], "RFX KF sensor #" .. RFXDevicesKF[teller] , 
-				"urn:schemas-ActiveRFID:device:RFIDTransmitter:1","D_RFIDTransmitter.xml","","",false)
-			end			
-			------------------------------------------------------------------------------------			
-			-- Next with light switches
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountLS do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesLS[teller], "RFX LS #" .. RFXDevicesLS[teller] , 
-				"urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml","","",false)
-			end			
-			------------------------------------------------------------------------------------			
-			-- Next Harrison window covering
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCOM_HAR_Count do
-				luup.chdev.append(THIS_DEVICE, child_devices, RFXCOM_HAR_Devices[teller], 
-				  "Harrison #" .. RFXCOM_HAR_Devices[teller] , "urn:schemas-micasaverde-com:device:WindowCovering:1",
-				  "D_RFXCOMHarrison.xml","","",false)
-			end
-			------------------------------------------------------------------------------------			
-			-- Next with temperature devices
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountTS2 do
-			  luup.log("debut temp:" .. RFXDevicesTS2[teller])
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesTS2[teller], "RFX TS #" .. RFXDevicesTS2[teller] , 
-				"urn:schemas-micasaverde-com:device:TemperatureSensor:1", "D_TemperatureSensor1.xml","","",false)
-			end			
-			------------------------------------------------------------------------------------			
-			-- Next with humidity devices
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountHS2 do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesHS2[teller], "RFX HS #" .. RFXDevicesHS2[teller] , 
-				"urn:schemas-micasaverde-com:device:HumiditySensor:1", "D_HumiditySensor1.xml","","",false)
-			end	
-			------------------------------------------------------------------------------------			
-			-- Next with barometer devices
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountBS2 do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesBS2[teller], "RFX BS #" .. RFXDevicesBS2[teller] , 
-				"urn:schemas-micasaverde-com:device:BarometerSensor:1", "D_BarometerSensor1.xml","","",false)
-			end	
-			
-			------------------------------------------------------------------------------------			
-			-- Next with rain devices
-			------------------------------------------------------------------------------------			
-			for teller = 1, RFXCountRS2 do
-			  luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesRS2[teller], "RFX RS #" .. RFXDevicesRS2[teller] , 
-				"urn:schemas-micasaverde-com:device:RainSensor:1", "D_RainSensor1.xml","","",false)
-			end	
-			
-			------------------------------------------------------------------------------------
-			-- Next with EZAnemoSensor devices
-			------------------------------------------------------------------------------------
-			for teller = 1, RFXCountAS2 do
-				luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesAS2[teller], "RFX AS #" .. RFXDevicesAS2[teller] ,
-				"urn:schemas-upnp-org:device:EZAnemoSensor:1", "D_EZAnemoSensor.xml","","",false)
-			end
-
-			------------------------------------------------------------------------------------			
-			-- Now add the new device to the tree depending on the sensor type
-			------------------------------------------------------------------------------------			
-
-			luup.log("Tree buildup, now add " .. lsID .. " with sensortype " .. lnSensorType)
-
-			------------------------------------------------------------------------------------			
-			-- Add if doorsensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeDoor) ~= 0 then
-				luup.log("CREATING CHILD DEVICE DOOR SENSOR WITH ID " .. lsID)
-				luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX DS sensor #" .. lsID , 
-				  "urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false)
-				RFXCountDS = RFXCountDS + 1
-				RFXDevicesDS[RFXCountDS] = lsID
-			end
-			------------------------------------------------------------------------------------			
-			-- Add if motionsensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeMotion) ~= 0 then
-				luup.log("CREATING CHILD DEVICE MOTION SENSOR WITH ID " .. lsID)
-				luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX MS sensor #" .. lsID , 
-				  "urn:schemas-micasaverde-com:device:MotionSensor:1","D_MotionSensor1.xml","","",false)
-				RFXCountMS = RFXCountMS + 1
-				RFXDevicesMS[RFXCountMS] = lsID
-			end
-			------------------------------------------------------------------------------------			
-			-- Add if keybof
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeKeyFob) ~= 0 then
-				luup.log("CREATING CHILD DEVICE KEYFOB WITH ID " .. lsID)
-				luup.chdev.append(THIS_DEVICE, child_devices, "KF/" .. lsID, "RFX KF sensor #" .. lsID , 
-				  "urn:schemas-ActiveRFID:device:RFIDTransmitter:1","D_RFIDTransmitter.xml","","",false)
-				RFXCountKF = RFXCountKF + 1
-				RFXDevicesKF[RFXCountKF] = "KF/" .. lsID
-			end
-			------------------------------------------------------------------------------------			
-			-- Add if lightswitch
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeControler) ~= 0 then
-				luup.log("CREATING CHILD DEVICE LIGHT SWITCH WITH ID " .. lsID)
-				luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX LS #" .. lsID , 
-				  "urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml","","",false)
-				RFXCountLS = RFXCountLS + 1
-				RFXDevicesLS[RFXCountLS] = lsID
-			end			
-			------------------------------------------------------------------------------------			
-			-- Add if Harrison window covering
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeWindowCovering) ~= 0 then
-				luup.chdev.append(THIS_DEVICE, child_devices, lsID, "Harrison #" .. lsID ,
-					"urn:schemas-micasaverde-com:device:WindowCovering:1","D_RFXCOMHarrison.xml","","",false)			
-				RFXCOM_HAR_Count = RFXCOM_HAR_Count + 1
-				RFXCOM_HAR_Devices[RFXCOM_HAR_Count] = lsID
-			end	
-			------------------------------------------------------------------------------------			
-			-- Add temperature sensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeTemperature) ~= 0 then
-			    luup.chdev.append(THIS_DEVICE, child_devices, "TS/" .. lsID, "RFX TS #" .. lsID,
-					"urn:schemas-micasaverde-com:device:TemperatureSensor:1", "D_TemperatureSensor1.xml","","",false)
-				RFXCountTS2 = RFXCountTS2 + 1
-				RFXDevicesTS2[RFXCountTS2] = "TS/" .. lsID
-			end	
-			------------------------------------------------------------------------------------			
-			-- Add humidity sensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeHumidity) ~= 0 then
-			    luup.chdev.append(THIS_DEVICE, child_devices, "HS/" .. lsID, "RFX HS #" .. lsID,
-					"urn:schemas-micasaverde-com:device:HumiditySensor:1", "D_HumiditySensor1.xml","","",false)
-				RFXCountHS2 = RFXCountHS2 + 1
-				RFXDevicesHS2[RFXCountHS2] = "HS/" .. lsID
-			end	
-			------------------------------------------------------------------------------------			
-			-- Add barometer sensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeBarometer) ~= 0 then
-			    luup.chdev.append(THIS_DEVICE, child_devices, "BS/" .. lsID, "RFX BS #" .. lsID,
-					"urn:schemas-micasaverde-com:device:BarometerSensor:1", "D_BarometerSensor1.xml","","",false)
-				RFXCountBS2 = RFXCountBS2 + 1
-				RFXDevicesBS2[RFXCountBS2] = "BS/" .. lsID
-			end	
-			
-			------------------------------------------------------------------------------------			
-			-- Add rain sensor
-			------------------------------------------------------------------------------------			
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeRain) ~= 0 then
-			    luup.chdev.append(THIS_DEVICE, child_devices, "RS/" .. lsID, "RFX RS #" .. lsID,
-					"urn:schemas-micasaverde-com:device:RainSensor:1", "D_RainSensor1.xml","","",false)
-				RFXCountRS2 = RFXCountRS2 + 1
-				RFXDevicesRS2[RFXCountRS2] = "RS/" .. lsID
-			end	
-			
-			------------------------------------------------------------------------------------
-			-- Add D_EZAnemoSensor sensor
-			------------------------------------------------------------------------------------
-			if bitw.band(lnSensorType,RFXConstants.sensorTypeWindDirection) ~= 0 then
-				luup.chdev.append(THIS_DEVICE, child_devices, "AS/" .. lsID, "RFX AS #" .. lsID,
-				"urn:schemas-upnp-org:device:EZAnemoSensor:1", "D_EZAnemoSensor.xml","","",false)
-				RFXCountAS2 = RFXCountAS2 + 1
-				RFXDevicesAS2[RFXCountAS2] = "AS/" .. lsID
-			end
-			
-			
-			
-			luup.log("Tree buildup with number child devices:")
-			luup.log("       door sensors: " .. RFXCountDS)
-			luup.log("     motion sensors: " .. RFXCountMS)
-			luup.log("     keyfob sensors: " .. RFXCountKF)
-			luup.log("     light switches: " .. RFXCountLS)
-			luup.log("   window coverings: " .. RFXCOM_HAR_Count)
-			luup.log("temperature sensors: " .. RFXCountTS2)
-			luup.log("   humidity sensors: " .. RFXCountHS2)
-			luup.log("   pressure sensors: " .. RFXCountBS2)
-			luup.log("       rain sensors: " .. RFXCountRS2)
-			luup.log("      Anemo sensors: " .. RFXCountAS2)
-			
-			-- Synch the new tree with the old three
-			luup.log("Start sync")
-			luup.chdev.sync(THIS_DEVICE, child_devices)
-			luup.log("End sync")       
-		end
-		
-		------------------------------------------------------------------------------
-		-- Deliver message to all devices with the correct altid (multiple
-		-- devices can have the correct altid!)
-		------------------------------------------------------------------------------
-		
-		local fullId = ""
-		for k, v in pairs(luup.devices) do
-			-- Check if we have a device with the correct parent (THIS_DEVICE) and 
-			-- altid we are looking for (lsID)
-			if (v.device_num_parent == THIS_DEVICE) then
-				device = k
-
-				-- luup.log("Device found or created, now processing command " .. lsCmd .. " for " .. lsID)
-				-- luup.log("Device Number: " .. k ..
-				--		 " v.device_type: " .. tostring(v.device_type) ..
-				--		 " v.device_num_parent: " .. tostring(v.device_num_parent) ..
-				--		 " v.id: " .. tostring(v.id)
-				-- )
-			
-				-- Execution door sensors same as motion sensors
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeDoor) ~= 0 or bitw.band(lnSensorType,RFXConstants.sensorTypeMotion) ~= 0 
-				  and v.id == lsId then
-					local TrippedValue = "0"
-					if lsCmd == RFXConstants.cmdAlert then TrippedValue = "1" end
-					luup.log( "Set tripped value " .. TrippedValue .. " to device " .. lsID ) 
-					luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", TrippedValue, device)
-				end
-
-				-- Execution for keyfobs
-				-- Arm or Disarm all door and motion sensors when keyfob armed or disarmed
-				-- Set trip state keyfox as indication home or away
-				fullId = "KF/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeKeyFob) ~= 0 
-				    and v.id == fullId then
-					luup.log("KeyFob action: " .. lsCmd) 
-					
-					if lsCmd == RFXConstants.cmdArmAway or lsCmd == RFXConstants.cmdArmHome or lsCmd == RFXConstants.cmdDisarm then
-					ArmDisarmAll(lsCmd)
-					--    local newArmedValue = "1" -- armed
-					--	local newTrippedValue = "1" -- home
-		
-					--	if lsCmd == RFXConstants.cmdDisarm then 
-					--	newArmedValue = "0" 
-					--	newTrippedValue = "0"
-					--	end
-					--	if lsCmd == RFXConstants.cmdArmAway then newTrippedValue = "0" end
-					--    luup.log( "Set ArmedValue value " .. newArmedValue .. " to device " .. device ) 
-					--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, device)
-					--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", newTrippedValue, device)
-					elseif lsCmd == RFXConstants.cmdPanic then
-						-- not implemented
-					elseif lsCmd == RFXConstants.cmdOn	then
-						luup.log("urn:ActiveRFID:serviceId:RFIDTransmitter1  Action:On:Portail" .. fullId) 
-						local Pstatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",26)
-						if Pstatus == "0" then
-							luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","1",26)
-						else
-							luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","0",26)
-						end
-					elseif lsCmd == RFXConstants.cmdOff	then
-						luup.log("urn:ActiveRFID:serviceId:RFIDTransmitter1  Action:Off:Garage" .. fullId) 
-						local Pstatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",27)
-						if Pstatus == "0" then
-							luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","1",27)
-						else
-							luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","0",27)
-						end
-					end			
-				end	
-
-				-- Execution light switches. 
-				-- Set Status based on cmdOn or cmdOff
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeControler) ~= 0 
-				   and v.id == lsID then
-					local newTargetValue = "0"
-					
-					if lsCmd == RFXConstants.cmdOn then newTargetValue = "1" end
-					if lsCmd == RFXConstants.cmdGroupOn then newTargetValue = "1" end
-					
-					luup.log("SET TARGET from " .. lsID .. " with value " .. newTargetValue)
-					luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",newTargetValue,device)
-				end			
-				
-				-- Execution for temperature sensor
-				-- Set temperature to command
-				fullId = "TS/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeTemperature) ~= 0 
-						and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:TemperatureSensor:1" 
-						and v.id == fullId then
-				    for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
-						-- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
-						if lsKey == "temperature" then
-							luup.log("SET CURRENTTEMPERATURE from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature",
-								lsValue, device)
-						elseif lsKey == "battery" then
-							luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
-						end
-					end
-				end
-
-				-- Execution for humidity sensor
-				-- Set humidity to command 
-				fullId = "HS/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeHumidity) ~= 0 
-						and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:HumiditySensor:1" 
-						and v.id == fullId then
-				    for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
-						-- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
-						if lsKey == "humidity" then
-							luup.log("SET CURRENTLEVEL from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel",
-								lsValue, device)
-						elseif lsKey == "battery" then
-							luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
-						end
-					end
-				end	
-
-				-- Execution for pressure sensor
-				-- Set pressure to command
-				fullId = "BS/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeBarometer) ~= 0 
-						and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:BarometerSensor:1" 
-						and v.id == fullId then
-				    for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
-						-- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
-						if lsKey == "pressure" then
-							luup.log("SET CURRENTPRESSURE from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:BarometerSensor1", "CurrentPressure",
-								lsValue, device)
-						elseif lsKey == "battery" then
-							luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
-						end
-					end
-				end
-				fullId = "RS/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeRain) ~= 0 
-						and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:RainSensor:1" 
-						and v.id == fullId then
-				    for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
-						-- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
-						if lsKey == "rain" then
-							luup.log("SET CURRENTRAIN from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:RainSensor1", "CurrentRain", lsValue, device)
-						elseif lsKey == "train" then
-							luup.log("SET CURRENTTRAIN from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:RainSensor1", "CurrentTRain", lsValue, device) 
-						elseif lsKey == "battery" then
-							luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
-						end
-					end
-				end
-				fullId = "AS/" .. lsID
-				if bitw.band(lnSensorType,RFXConstants.sensorTypeWindDirection) ~= 0
-						and tostring(v.device_type) == "urn:schemas-upnp-org:device:EZAnemoSensor:1"
-						and v.id == fullId then
-				    for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
-						-- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
-						if lsKey == "direction" then
-							luup.log("SET DIRECTION from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "Direction", lsValue, device)
-						end
-						if lsKey == "speed" then
-							luup.log("SET SPEED from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "Speed", lsValue, device)
-						end
-						if lsKey == "speedav" then
-							luup.log("SET SPEEDAV from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "SpeedAv", lsValue, device)
-						end
-						if lsKey == "battery" then
-							luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
-							luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
-						end
-					end
-				end
-			end
-			
-		end 
-
-	end
+    ----------------------------------------------------------------------------------------
+    -- If we can't find a device and we have autocreate active, setup a new tree with child devices
+    -- and add a new child with the correct type and ID
+    ----------------------------------------------------------------------------------------
+    if device == nil and luup.variable_get("urn:upnp-esweb-nl:serviceId:rfxcom1", "AutoCreate", lul_device) == "1" then
+      luup.log( "device not found and autocreate enabled..." ) 
+      
+      local child_devices = luup.chdev.start(THIS_DEVICE);  
+
+      ------------------------------------------------------------------------------------      
+      -- First add all 'old' children to the tree
+      -- Start with door sensors
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountDS do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesDS[teller], "RFX DS sensor #" .. RFXDevicesDS[teller] , 
+        "urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false)
+      end
+      ------------------------------------------------------------------------------------      
+      -- Next with motion sensors
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountMS do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesMS[teller], "RFX MS sensor #" .. RFXDevicesMS[teller] , 
+        "urn:schemas-micasaverde-com:device:MotionSensor:1","D_MotionSensor1.xml","","",false)
+      end     
+      ------------------------------------------------------------------------------------      
+      -- Next with keyfobs
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountKF do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesKF[teller], "RFX KF sensor #" .. RFXDevicesKF[teller] , 
+        "urn:schemas-ActiveRFID:device:RFIDTransmitter:1","D_RFIDTransmitter.xml","","",false)
+      end     
+      ------------------------------------------------------------------------------------      
+      -- Next with light switches
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountLS do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesLS[teller], "RFX LS #" .. RFXDevicesLS[teller] , 
+        "urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml","","",false)
+      end     
+      ------------------------------------------------------------------------------------      
+      -- Next Harrison window covering
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCOM_HAR_Count do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXCOM_HAR_Devices[teller], 
+          "Harrison #" .. RFXCOM_HAR_Devices[teller] , "urn:schemas-micasaverde-com:device:WindowCovering:1",
+          "D_RFXCOMHarrison.xml","","",false)
+      end
+      ------------------------------------------------------------------------------------      
+      -- Next with temperature devices
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountTS2 do
+        luup.log("debut temp:" .. RFXDevicesTS2[teller])
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesTS2[teller], "RFX TS #" .. RFXDevicesTS2[teller] , 
+        "urn:schemas-micasaverde-com:device:TemperatureSensor:1", "D_TemperatureSensor1.xml","","",false)
+      end     
+      ------------------------------------------------------------------------------------      
+      -- Next with humidity devices
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountHS2 do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesHS2[teller], "RFX HS #" .. RFXDevicesHS2[teller] , 
+        "urn:schemas-micasaverde-com:device:HumiditySensor:1", "D_HumiditySensor1.xml","","",false)
+      end 
+      ------------------------------------------------------------------------------------      
+      -- Next with barometer devices
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountBS2 do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesBS2[teller], "RFX BS #" .. RFXDevicesBS2[teller] , 
+        "urn:schemas-micasaverde-com:device:BarometerSensor:1", "D_BarometerSensor1.xml","","",false)
+      end 
+      
+      ------------------------------------------------------------------------------------      
+      -- Next with rain devices
+      ------------------------------------------------------------------------------------      
+      for teller = 1, RFXCountRS2 do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesRS2[teller], "RFX RS #" .. RFXDevicesRS2[teller] , 
+        "urn:schemas-micasaverde-com:device:RainSensor:1", "D_RainSensor1.xml","","",false)
+      end 
+      
+      ------------------------------------------------------------------------------------
+      -- Next with EZAnemoSensor devices
+      ------------------------------------------------------------------------------------
+      for teller = 1, RFXCountAS2 do
+        luup.chdev.append(THIS_DEVICE, child_devices, RFXDevicesAS2[teller], "RFX AS #" .. RFXDevicesAS2[teller] ,
+        "urn:schemas-upnp-org:device:EZAnemoSensor:1", "D_EZAnemoSensor.xml","","",false)
+      end
+
+      ------------------------------------------------------------------------------------      
+      -- Now add the new device to the tree depending on the sensor type
+      ------------------------------------------------------------------------------------      
+
+      luup.log("Tree buildup, now add " .. lsID .. " with sensortype " .. lnSensorType)
+
+      ------------------------------------------------------------------------------------      
+      -- Add if doorsensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeDoor) ~= 0 then
+        luup.log("CREATING CHILD DEVICE DOOR SENSOR WITH ID " .. lsID)
+        luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX DS sensor #" .. lsID , 
+          "urn:schemas-micasaverde-com:device:DoorSensor:1","D_DoorSensor1.xml","","",false)
+        RFXCountDS = RFXCountDS + 1
+        RFXDevicesDS[RFXCountDS] = lsID
+      end
+      ------------------------------------------------------------------------------------      
+      -- Add if motionsensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeMotion) ~= 0 then
+        luup.log("CREATING CHILD DEVICE MOTION SENSOR WITH ID " .. lsID)
+        luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX MS sensor #" .. lsID , 
+          "urn:schemas-micasaverde-com:device:MotionSensor:1","D_MotionSensor1.xml","","",false)
+        RFXCountMS = RFXCountMS + 1
+        RFXDevicesMS[RFXCountMS] = lsID
+      end
+      ------------------------------------------------------------------------------------      
+      -- Add if keybof
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeKeyFob) ~= 0 then
+        luup.log("CREATING CHILD DEVICE KEYFOB WITH ID " .. lsID)
+        luup.chdev.append(THIS_DEVICE, child_devices, "KF/" .. lsID, "RFX KF sensor #" .. lsID , 
+          "urn:schemas-ActiveRFID:device:RFIDTransmitter:1","D_RFIDTransmitter.xml","","",false)
+        RFXCountKF = RFXCountKF + 1
+        RFXDevicesKF[RFXCountKF] = "KF/" .. lsID
+      end
+      ------------------------------------------------------------------------------------      
+      -- Add if lightswitch
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeControler) ~= 0 then
+        luup.log("CREATING CHILD DEVICE LIGHT SWITCH WITH ID " .. lsID)
+        luup.chdev.append(THIS_DEVICE, child_devices, lsID, "RFX LS #" .. lsID , 
+          "urn:schemas-upnp-org:device:BinaryLight:1","D_BinaryLight1.xml","","",false)
+        RFXCountLS = RFXCountLS + 1
+        RFXDevicesLS[RFXCountLS] = lsID
+      end     
+      ------------------------------------------------------------------------------------      
+      -- Add if Harrison window covering
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeWindowCovering) ~= 0 then
+        luup.chdev.append(THIS_DEVICE, child_devices, lsID, "Harrison #" .. lsID ,
+          "urn:schemas-micasaverde-com:device:WindowCovering:1","D_RFXCOMHarrison.xml","","",false)     
+        RFXCOM_HAR_Count = RFXCOM_HAR_Count + 1
+        RFXCOM_HAR_Devices[RFXCOM_HAR_Count] = lsID
+      end 
+      ------------------------------------------------------------------------------------      
+      -- Add temperature sensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeTemperature) ~= 0 then
+          luup.chdev.append(THIS_DEVICE, child_devices, "TS/" .. lsID, "RFX TS #" .. lsID,
+          "urn:schemas-micasaverde-com:device:TemperatureSensor:1", "D_TemperatureSensor1.xml","","",false)
+        RFXCountTS2 = RFXCountTS2 + 1
+        RFXDevicesTS2[RFXCountTS2] = "TS/" .. lsID
+      end 
+      ------------------------------------------------------------------------------------      
+      -- Add humidity sensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeHumidity) ~= 0 then
+          luup.chdev.append(THIS_DEVICE, child_devices, "HS/" .. lsID, "RFX HS #" .. lsID,
+          "urn:schemas-micasaverde-com:device:HumiditySensor:1", "D_HumiditySensor1.xml","","",false)
+        RFXCountHS2 = RFXCountHS2 + 1
+        RFXDevicesHS2[RFXCountHS2] = "HS/" .. lsID
+      end 
+      ------------------------------------------------------------------------------------      
+      -- Add barometer sensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeBarometer) ~= 0 then
+          luup.chdev.append(THIS_DEVICE, child_devices, "BS/" .. lsID, "RFX BS #" .. lsID,
+          "urn:schemas-micasaverde-com:device:BarometerSensor:1", "D_BarometerSensor1.xml","","",false)
+        RFXCountBS2 = RFXCountBS2 + 1
+        RFXDevicesBS2[RFXCountBS2] = "BS/" .. lsID
+      end 
+      
+      ------------------------------------------------------------------------------------      
+      -- Add rain sensor
+      ------------------------------------------------------------------------------------      
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeRain) ~= 0 then
+          luup.chdev.append(THIS_DEVICE, child_devices, "RS/" .. lsID, "RFX RS #" .. lsID,
+          "urn:schemas-micasaverde-com:device:RainSensor:1", "D_RainSensor1.xml","","",false)
+        RFXCountRS2 = RFXCountRS2 + 1
+        RFXDevicesRS2[RFXCountRS2] = "RS/" .. lsID
+      end 
+      
+      ------------------------------------------------------------------------------------
+      -- Add D_EZAnemoSensor sensor
+      ------------------------------------------------------------------------------------
+      if bitw.band(lnSensorType,RFXConstants.sensorTypeWindDirection) ~= 0 then
+        luup.chdev.append(THIS_DEVICE, child_devices, "AS/" .. lsID, "RFX AS #" .. lsID,
+        "urn:schemas-upnp-org:device:EZAnemoSensor:1", "D_EZAnemoSensor.xml","","",false)
+        RFXCountAS2 = RFXCountAS2 + 1
+        RFXDevicesAS2[RFXCountAS2] = "AS/" .. lsID
+      end
+      
+      
+      
+      luup.log("Tree buildup with number child devices:")
+      luup.log("       door sensors: " .. RFXCountDS)
+      luup.log("     motion sensors: " .. RFXCountMS)
+      luup.log("     keyfob sensors: " .. RFXCountKF)
+      luup.log("     light switches: " .. RFXCountLS)
+      luup.log("   window coverings: " .. RFXCOM_HAR_Count)
+      luup.log("temperature sensors: " .. RFXCountTS2)
+      luup.log("   humidity sensors: " .. RFXCountHS2)
+      luup.log("   pressure sensors: " .. RFXCountBS2)
+      luup.log("       rain sensors: " .. RFXCountRS2)
+      luup.log("      Anemo sensors: " .. RFXCountAS2)
+      
+      -- Synch the new tree with the old three
+      luup.log("Start sync")
+      luup.chdev.sync(THIS_DEVICE, child_devices)
+      luup.log("End sync")       
+    end
+    
+    ------------------------------------------------------------------------------
+    -- Deliver message to all devices with the correct altid (multiple
+    -- devices can have the correct altid!)
+    ------------------------------------------------------------------------------
+    
+    local fullId = ""
+    for k, v in pairs(luup.devices) do
+      -- Check if we have a device with the correct parent (THIS_DEVICE) and 
+      -- altid we are looking for (lsID)
+      if (v.device_num_parent == THIS_DEVICE) then
+        device = k
+
+        -- luup.log("Device found or created, now processing command " .. lsCmd .. " for " .. lsID)
+        -- luup.log("Device Number: " .. k ..
+        --     " v.device_type: " .. tostring(v.device_type) ..
+        --     " v.device_num_parent: " .. tostring(v.device_num_parent) ..
+        --     " v.id: " .. tostring(v.id)
+        -- )
+      
+        -- Execution door sensors same as motion sensors
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeDoor) ~= 0 or bitw.band(lnSensorType,RFXConstants.sensorTypeMotion) ~= 0 
+          and v.id == lsId then
+          local TrippedValue = "0"
+          if lsCmd == RFXConstants.cmdAlert then TrippedValue = "1" end
+          luup.log( "Set tripped value " .. TrippedValue .. " to device " .. lsID ) 
+          luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", TrippedValue, device)
+        end
+
+        -- Execution for keyfobs
+        -- Arm or Disarm all door and motion sensors when keyfob armed or disarmed
+        -- Set trip state keyfob as indication home or away
+        fullId = "KF/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeKeyFob) ~= 0 
+            and v.id == fullId then
+          luup.log("KeyFob action: " .. lsCmd) 
+          
+          if lsCmd == RFXConstants.cmdArmAway or lsCmd == RFXConstants.cmdArmHome or lsCmd == RFXConstants.cmdDisarm then
+            ArmDisarmAll(lsCmd)
+          --  local newArmedValue = "1" -- armed
+          --  local newTrippedValue = "1" -- home
+    
+          --  if lsCmd == RFXConstants.cmdDisarm then 
+          --  newArmedValue = "0" 
+          --  newTrippedValue = "0"
+          --  end
+          --  if lsCmd == RFXConstants.cmdArmAway then newTrippedValue = "0" end
+          --    luup.log( "Set ArmedValue value " .. newArmedValue .. " to device " .. device ) 
+          --  luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, device)
+          --  luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", newTrippedValue, device)
+          elseif lsCmd == RFXConstants.cmdPanic then
+            -- not implemented
+          elseif lsCmd == RFXConstants.cmdOn  then
+            luup.log("urn:ActiveRFID:serviceId:RFIDTransmitter1  Action:On:Portail" .. fullId) 
+            local Pstatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",26)
+            if Pstatus == "0" then
+              luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","1",26)
+            else
+              luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","0",26)
+            end
+          elseif lsCmd == RFXConstants.cmdOff then
+            luup.log("urn:ActiveRFID:serviceId:RFIDTransmitter1  Action:Off:Garage" .. fullId) 
+            local Pstatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",27)
+            if Pstatus == "0" then
+              luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","1",27)
+            else
+              luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status","0",27)
+            end
+          end     
+        end 
+
+        -- Execution light switches. 
+        -- Set Status based on cmdOn or cmdOff
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeControler) ~= 0 
+           and v.id == lsID then
+          local newTargetValue = "0"
+          
+          if lsCmd == RFXConstants.cmdOn then newTargetValue = "1" end
+          if lsCmd == RFXConstants.cmdGroupOn then newTargetValue = "1" end
+          
+          luup.log("SET TARGET from " .. lsID .. " with value " .. newTargetValue)
+          luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",newTargetValue,device)
+        end     
+        
+        -- Execution for temperature sensor
+        -- Set temperature to command
+        fullId = "TS/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeTemperature) ~= 0 
+            and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:TemperatureSensor:1" 
+            and v.id == fullId then
+            for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
+            -- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
+            if lsKey == "temperature" then
+              luup.log("SET CURRENTTEMPERATURE from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature",
+                lsValue, device)
+            elseif lsKey == "battery" then
+              luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
+            end
+          end
+        end
+
+        -- Execution for humidity sensor
+        -- Set humidity to command 
+        fullId = "HS/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeHumidity) ~= 0 
+            and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:HumiditySensor:1" 
+            and v.id == fullId then
+            for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
+            -- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
+            if lsKey == "humidity" then
+              luup.log("SET CURRENTLEVEL from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:micasaverde-com:serviceId:HumiditySensor1", "CurrentLevel",
+                lsValue, device)
+            elseif lsKey == "battery" then
+              luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
+            end
+          end
+        end 
+
+        -- Execution for pressure sensor
+        -- Set pressure to command
+        fullId = "BS/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeBarometer) ~= 0 
+            and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:BarometerSensor:1" 
+            and v.id == fullId then
+            for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
+            -- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
+            if lsKey == "pressure" then
+              luup.log("SET CURRENTPRESSURE from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:upnp-org:serviceId:BarometerSensor1", "CurrentPressure",
+                lsValue, device)
+            elseif lsKey == "battery" then
+              luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
+            end
+          end
+        end
+        fullId = "RS/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeRain) ~= 0 
+            and tostring(v.device_type) == "urn:schemas-micasaverde-com:device:RainSensor:1" 
+            and v.id == fullId then
+            for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
+            -- luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
+            if lsKey == "rain" then
+              luup.log("SET CURRENTRAIN from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:upnp-org:serviceId:RainSensor1", "CurrentRain", lsValue, device)
+            elseif lsKey == "train" then
+              luup.log("SET CURRENTTRAIN from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:upnp-org:serviceId:RainSensor1", "CurrentTRain", lsValue, device) 
+            elseif lsKey == "battery" then
+              luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
+              luup.variable_set("urn:micasaverde-com:serviceId:HaDevice1", "BatteryLevel", lsValue, device)
+            end
+          end
+        end
+        fullId = "AS/" .. lsID
+        if bitw.band(lnSensorType,RFXConstants.sensorTypeWindDirection) ~= 0
+            and tostring(v.device_type) == "urn:schemas-upnp-org:device:EZAnemoSensor:1"
+            and v.id == fullId then
+            for lsKey,lsValue in string.gmatch(lsCmd, "(%w+)=([%w%.%-_]+)") do
+              luup.log("Key=" ..  lsKey .. ";Value=" .. lsValue .. ";")
+              if lsKey == "direction" then
+                luup.log("SET DIRECTION from " .. lsID .. " with value " .. lsValue)
+                luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "Direction", lsValue, device)
+              end
+              if lsKey == "speed" then
+                luup.log("SET SPEED from " .. lsID .. " with value " .. lsValue)
+                luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "Speed", lsValue, device)
+              end
+              if lsKey == "speedav" then
+                luup.log("SET SPEEDAV from " .. lsID .. " with value " .. lsValue)
+                luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "SpeedAv", lsValue, device)
+              end
+              if lsKey == "battery" then
+                luup.log("SET BATTERY from " .. lsID .. " with value " .. lsValue)
+                luup.variable_set("urn:upnp-org:serviceId:EZAnemoSensor1", "Battery", lsValue, device)
+              end
+            end
+        end
+      end
+      
+    end 
+
+  end
  
-	------------------------------------------------------------------------
-	-- Arm or Disarm
-	-- 
-	-- Arm or Disarm all motion and door sensors based on command given.
-	-- KeyFob sensor gets armed or disarmed also and trip state 
-	-- is used to indicate home or away status (triped = home)
-	------------------------------------------------------------------------
-	
-	function ArmDisarmAll(lsCmd)
-		local newArmedValue = "1" -- armed
-		local newTrippedValue = "1" -- home
-		
-		if lsCmd == RFXConstants.cmdDisarm then 
-			newArmedValue = "0" 
-			newTrippedValue = "0"
-		end
-		if lsCmd == RFXConstants.cmdArmAway then newTrippedValue = "0" end
-		luup.log("urn:ActiveRFID:serviceId:RFIDTransmitter1  Action::SetArmed:" .. newArmedValue .. "device:" .. RFXDevicesKF[1]) 
-		luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, 41)
-		luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, 42)
-		luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, 43)
-		luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue, 44)
-		
-		-- Iterate all door sensors and set armed value 
-		-- for teller = 1, RFXCountDS do
-		--	local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesDS[teller] )
-			
-		--	luup.log("Action::SetArmed: " .. newArmedValue .. " for door sensor device " .. RFXDevicesDS[teller] .. "/" .. lsOtherDevices)
-		--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
-		-- end
-
-		-- Iterate all  motion sensors and set armed value 
-		-- for teller = 1, RFXCountMS do
-		--	local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesMS[teller] )
-		--	
-		--	luup.log("Action::SetArmed: " .. newArmedValue .. " for motion sensor device " .. RFXDevicesMS[teller] .. "/" .. lsOtherDevices)
-		--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
-		
-		-- end	
-
-		-- Iterate all keyfobs and set armed value and 
-		-- set tripped value based on armed-home (1) or armed-away (0)
-		-- for teller = 1, RFXCountKF do
-		--	local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesKF[teller] )
-		--	
-		--	luup.log("Action::SetArmed: " .. newArmedValue .. "for KeyFob device " .. RFXDevicesKF[teller] .. "/" .. lsOtherDevices)
-		--	luup.log("Action::SetTripped: " .. newTrippedValue .. "for KeyFob device " .. RFXDevicesKF[teller] .. "/" .. lsOtherDevices)
-		--	
-		--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
-		--	luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",newTrippedValue,lsOtherDevices)			
-		--end				
-	end
-	
-	
+  ------------------------------------------------------------------------
+  -- Arm or Disarm
+  -- 
+  -- Arm or Disarm all motion and door sensors based on command given.
+  -- KeyFob sensor gets armed or disarmed also and trip state 
+  -- is used to indicate home or away status (tripped = home)
+  ------------------------------------------------------------------------
+  
+  function ArmDisarmAll(lsCmd)
+    local newArmedValue = "1" -- armed
+    local newTrippedValue = "1" -- home
+    
+    if lsCmd == RFXConstants.cmdDisarm then 
+      newArmedValue = "0" 
+      newTrippedValue = "0"
+    end
+    if lsCmd == RFXConstants.cmdArmAway then 
+      newTrippedValue = "0" 
+    end
+    
+    -- Iterate all door sensors and set armed value 
+    for teller = 1, RFXCountDS do
+      local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesDS[teller] )
+      
+      luup.log("Action::SetArmed: " .. newArmedValue .. " for door sensor device " .. RFXDevicesDS[teller] .. "/" .. lsOtherDevices)
+      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
+    end
+
+    -- Iterate all  motion sensors and set armed value 
+    for teller = 1, RFXCountMS do
+      local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesMS[teller] )
+      
+      luup.log("Action::SetArmed: " .. newArmedValue .. " for motion sensor device " .. RFXDevicesMS[teller] .. "/" .. lsOtherDevices)
+      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
+    
+     end  
+
+    -- Iterate all keyfobs and set armed value and 
+    -- set tripped value based on armed-home (1) or armed-away (0)
+    for teller = 1, RFXCountKF do
+      local lsOtherDevices = findChild(THIS_DEVICE, RFXDevicesKF[teller] )
+      
+      luup.log("Action::SetArmed: " .. newArmedValue .. "for KeyFob device " .. RFXDevicesKF[teller] .. "/" .. lsOtherDevices)
+      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Armed",newArmedValue,lsOtherDevices)
+
+      luup.log("Action::SetTripped: " .. newTrippedValue .. "for KeyFob device " .. RFXDevicesKF[teller] .. "/" .. lsOtherDevices)
+      luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",newTrippedValue,lsOtherDevices)     
+    end       
+  end
+  
+  
  
     -- Thanks to guessed for this snippet.
     function findChild(parentDevice, label)
       for k, v in pairs(luup.devices) do
-	       if (v.device_num_parent == parentDevice and string.find(v.id, label .. "$", 1) ~= nil) then
-		       return k
+         if (v.device_num_parent == parentDevice and string.find(v.id, label .. "$", 1) ~= nil) then
+           return k
         end
       end
@@ -1627,96 +1655,96 @@
 
   <startup>mainStartup</startup>
-	<actionList>
-		<action>
-			<serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
-			<name>SetTarget</name>
-			<run>
-				local ls_id = luup.devices[lul_device].id
-				local lul_reverse = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1","ReverseOnOff",lul_device)
-				
-				luup.log("SET TARGET from " .. ls_id .. " with value " .. lul_settings.newTargetValue)
-				
-				if ( lul_settings.newTargetValue == "1"  or (lul_settings.newTargetValue=="0" and lul_reverse=="1") ) then
-					SendCmd( ls_id,RFXConstants.cmdOn )
-				else
-					SendCmd( ls_id,RFXConstants.cmdOff )
-				end
-				luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",lul_settings.newTargetValue,lul_device)
-			</run>
-		</action>
-
-		<action> 
-			<serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 
-			<name>SetArmed</name> 
-			<run> 
-				--debug("Action::SetArmed:"..lul_settings.newArmedValue) 
-				luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", lul_settings.newArmedValue, lul_device) 
-			</run> 
-		</action> 
-
-		<action> 
-			<serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId> 
-			<name>ToggleState</name> 
-			<run> 
-				--debug("Action::ToggleState:" .. lul_device) 
-			</run> 
-		</action> 
-		  
-
-		<action>
-			<serviceId>urn:upnp-esweb-nl:serviceId:rfxcom1</serviceId>
-			<name>AddHarrisonCurtain</name>
-			<run>
-				local lsHouseCode = lul_settings.HouseCode
-				actOnMessage(RFXConstants.sensorTypeWindowCovering,lsHouseCode,"")
-			</run>
-		</action>
-		 <action>
-			<serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
-			<name>Stop</name>
-			<run>
-			  local har_id = luup.devices[lul_device].id
-			  SendHarrisonCmd( har_id, "STOP")
-			</run>
-		  </action>
-		  <action>     
-			<serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
-			<name>Up</name>
-			<run>
-			  luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",0,lul_device)
-			  local har_id = luup.devices[lul_device].id
-			  SendHarrisonCmd( har_id, "OPEN")
-			</run>
-		  </action>
-		  <action>
-			<serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
-			<name>Down</name>
-			<run>
-			  luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",1,lul_device)
-			  local har_id = luup.devices[lul_device].id
-			  SendHarrisonCmd( har_id, "CLOSE")
-			</run>
-		  </action>
-
-		  <action>
-			<serviceId>urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1</serviceId>
-			<name>SetStatus</name>
-			<run>
-			   luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",lul_settings.newStatusValue,lul_device)
-			   local har_id = luup.devices[lul_device].id
-			   if ( lul_settings.newStatusValue == "1" ) then
-				SendHarrisonCmd( har_id, "OPEN")
-			   else
-				SendHarrisonCmd( har_id, "CLOSE")
-			   end
-			</run>
-		  </action>
-		  <action>
-			<serviceId>urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1</serviceId>
-			<name>GetStatus</name>
-			<run>
-			   lul_settings.ResultStatus = luup.variable_get("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",lul_device)
-			</run>
-		  </action>
-	</actionList>
+  <actionList>
+    <action>
+      <serviceId>urn:upnp-org:serviceId:SwitchPower1</serviceId>
+      <name>SetTarget</name>
+      <run>
+        local ls_id = luup.devices[lul_device].id
+        local lul_reverse = luup.variable_get("urn:micasaverde-com:serviceId:HaDevice1","ReverseOnOff",lul_device)
+        
+        luup.log("SET TARGET from " .. ls_id .. " with value " .. lul_settings.newTargetValue)
+        
+        if ( lul_settings.newTargetValue == "1"  or (lul_settings.newTargetValue=="0" and lul_reverse=="1") ) then
+          SendCmd( ls_id,RFXConstants.cmdOn )
+        else
+          SendCmd( ls_id,RFXConstants.cmdOff )
+        end
+        luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","Status",lul_settings.newTargetValue,lul_device)
+      </run>
+    </action>
+
+    <action> 
+      <serviceId>urn:micasaverde-com:serviceId:SecuritySensor1</serviceId> 
+      <name>SetArmed</name> 
+      <run> 
+        --debug("Action::SetArmed:"..lul_settings.newArmedValue) 
+        luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", lul_settings.newArmedValue, lul_device) 
+      </run> 
+    </action> 
+
+    <action> 
+      <serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId> 
+      <name>ToggleState</name> 
+      <run> 
+        --debug("Action::ToggleState:" .. lul_device) 
+      </run> 
+    </action> 
+      
+
+    <action>
+      <serviceId>urn:upnp-esweb-nl:serviceId:rfxcom1</serviceId>
+      <name>AddHarrisonCurtain</name>
+      <run>
+        local lsHouseCode = lul_settings.HouseCode
+        actOnMessage(RFXConstants.sensorTypeWindowCovering,lsHouseCode,"")
+      </run>
+    </action>
+     <action>
+      <serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
+      <name>Stop</name>
+      <run>
+        local har_id = luup.devices[lul_device].id
+        SendHarrisonCmd( har_id, "STOP")
+      </run>
+      </action>
+      <action>     
+      <serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
+      <name>Up</name>
+      <run>
+        luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",0,lul_device)
+        local har_id = luup.devices[lul_device].id
+        SendHarrisonCmd( har_id, "OPEN")
+      </run>
+      </action>
+      <action>
+      <serviceId>urn:upnp-org:serviceId:WindowCovering1</serviceId>
+      <name>Down</name>
+      <run>
+        luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",1,lul_device)
+        local har_id = luup.devices[lul_device].id
+        SendHarrisonCmd( har_id, "CLOSE")
+      </run>
+      </action>
+
+      <action>
+      <serviceId>urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1</serviceId>
+      <name>SetStatus</name>
+      <run>
+         luup.variable_set("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",lul_settings.newStatusValue,lul_device)
+         local har_id = luup.devices[lul_device].id
+         if ( lul_settings.newStatusValue == "1" ) then
+        SendHarrisonCmd( har_id, "OPEN")
+         else
+        SendHarrisonCmd( har_id, "CLOSE")
+         end
+      </run>
+      </action>
+      <action>
+      <serviceId>urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1</serviceId>
+      <name>GetStatus</name>
+      <run>
+         lul_settings.ResultStatus = luup.variable_get("urn:upnp-esweb-nl:serviceId:RFXCOMHarrison1","CurtainStatus",lul_device)
+      </run>
+      </action>
+  </actionList>
 </implementation>
Index: /D_EZAnemoSensor.xml
===================================================================
--- /D_EZAnemoSensor.xml	(revision 20)
+++ /D_EZAnemoSensor.xml	(revision 30)
@@ -24,4 +24,9 @@
         <SCPDURL>S_EZAnemoSensor.xml</SCPDURL>
       </service>
+      <service>
+        <serviceType>urn:schemas-micasaverde-com:service:HaDevice:1</serviceType>
+        <serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
+        <SCPDURL>S_HaDevice1.xml</SCPDURL>
+      </service>
     </serviceList>
   </device>
Index: /D_RainSensor1.xml
===================================================================
--- /D_RainSensor1.xml	(revision 20)
+++ /D_RainSensor1.xml	(revision 30)
@@ -7,5 +7,5 @@
   <device>
     <deviceType>urn:schemas-micasaverde-com:device:RainSensor:1</deviceType>
-	<staticJson>D_RainSensor1.json</staticJson>
+	  <staticJson>D_RainSensor1.json</staticJson>
     <serviceList>
       <service>
Index: BarometerSensor1_fr.xml
===================================================================
--- /D_BarometerSensor1_fr.xml	(revision 20)
+++ 	(revision )
@@ -1,42 +1,0 @@
-<?xml version="1.0"?>
-<root xmlns="urn:schemas-upnp-org:device-1-0">
-  <specVersion>
-    <major>1</major>
-    <minor>0</minor>
-  </specVersion>
-  <device>
-    <deviceType>urn:schemas-micasaverde-com:device:BarometerSensor:1</deviceType>
-	<staticJson>D_BarometerSensor1.json</staticJson>
-    <serviceList>
-      <service>
-        <serviceType>urn:schemas-upnp-org:service:BarometerSensor:1</serviceType>
-        <serviceId>urn:upnp-org:serviceId:BarometerSensor1</serviceId>
-        <SCPDURL>S_BarometerSensor1.xml</SCPDURL>
-      </service>
-      <service>
-        <serviceType>urn:schemas-micasaverde-com:service:HaDevice:1</serviceType>
-        <serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
-        <SCPDURL>S_HaDevice1.xml</SCPDURL>
-      </service>
-    </serviceList>
-  <eventList>
-{
-	"event_1":{
-		"label": "Pressure is reached",
-		"serviceId": "urn:upnp-org:serviceId:BarometerSensor1",
-		"argumentList" :
-		{
-			"argument_1" :
-			{
-				"dataType": "i4",
-				"name": "CurrentPressure",
-				"comparisson": "&gt;",
-				"prefix": "pressure: ",
-				"suffix": " bar"
-			}
-		}
-	}	
-}
-  </eventList>
-  </device>
-</root>
Index: EZAnemoSensor_fr.xml
===================================================================
--- /D_EZAnemoSensor_fr.xml	(revision 20)
+++ 	(revision )
@@ -1,30 +1,0 @@
-<?xml version="1.0"?>
-<root xmlns="urn:schemas-upnp-org:device-1-0">
-  <specVersion>
-    <major>1</major>
-    <minor>0</minor>
-  </specVersion>
-  <device>
-    <deviceType>urn:schemas-upnp-org:device:EZAnemoSensor:1</deviceType>
-    <staticJson>D_EZAnemoSensor.json</staticJson> 
-    <friendlyName>Anemometre Sensor</friendlyName>
-    <manufacturer>Simplearetenir</manufacturer>
-    <manufacturerURL></manufacturerURL>
-    <modelDescription>AnemoSensor</modelDescription>
-    <modelName>AnemoSensor</modelName>
-    <modelNumber>1.0</modelNumber>
-    <protocol>cr</protocol>
-    <handleChildren>0</handleChildren>
-	<serviceList>
-      <service>
-        <serviceType>urn:schemas-upnp-org:service:EZAnemoSensor:1</serviceType>
-        <serviceId>urn:upnp-org:serviceId:EZAnemoSensor1</serviceId>
-        <controlURL>/upnp/control/EZAnemoSensor1</controlURL>
-        <eventSubURL>/upnp/event/EZAnemoSensor1</eventSubURL>
-        <SCPDURL>S_EZAnemoSensor.xml</SCPDURL>
-      </service>
-    </serviceList>
-  </device>
-</root>
- 
- 
