From: amiraj <amiraj.95@uci.edu>
Date: Thu, 1 Aug 2019 18:15:36 +0000 (-0700)
Subject: Changes in classes: new concept for latest value + all types of events generated... 
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d3802bd96ca8963ae52b9740443f9be6896f0e18;p=smartthings-infrastructure.git

Changes in classes: new concept for latest value + all types of events generated by apps + sending events after changing the value of devices' features
---

diff --git a/AccelerationSensor/AccelerationSensor.groovy b/AccelerationSensor/AccelerationSensor.groovy
index 1bec3cd..78a9bed 100644
--- a/AccelerationSensor/AccelerationSensor.groovy
+++ b/AccelerationSensor/AccelerationSensor.groovy
@@ -22,8 +22,8 @@ public class AccelerationSensor {
 	}
 
 	def setValue(String value) {
-		this.accelerationLatestValue = acceleration
 		println("the acceleration sensor with id:$id is triggered to $value!")
+		this.accelerationLatestValue = value
 		this.acceleration = value
 		this.currentAcceleration = value
 		this.states.add(value)
diff --git a/AccelerationSensor/AccelerationSensors.groovy b/AccelerationSensor/AccelerationSensors.groovy
index 8c1992c..d7a9f99 100644
--- a/AccelerationSensor/AccelerationSensors.groovy
+++ b/AccelerationSensor/AccelerationSensors.groovy
@@ -17,6 +17,7 @@ public class AccelerationSensors {
 	private String acceleration = "inactive"
 	private String currentAcceleration = "inactive"
 	private String accelerationLatestValue = "inactive"
+	
 
 		
 	AccelerationSensors(Closure sendEvent, int deviceNumbers) {
@@ -38,10 +39,10 @@ public class AccelerationSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != accelerationSensors[0].acceleration) {
+			this.accelerationLatestValue = eventDataMap["value"]
+			this.acceleration = eventDataMap["value"]
+			this.currentAcceleration = eventDataMap["value"]
 			accelerationSensors[0].setValue(eventDataMap["value"])
-			this.accelerationLatestValue = accelerationSensors[0].accelerationLatestValue
-			this.acceleration = accelerationSensors[0].acceleration
-			this.currentAcceleration = accelerationSensors[0].acceleration
 			sendEvent(eventDataMap)
 		}
 	}
@@ -56,6 +57,9 @@ public class AccelerationSensors {
 	def each(Closure Input) {
 		accelerationSensors.each(Input)
 	}
+	def sort(Closure Input) {
+		accelerationSensors.each(Input)
+	}
 	def find(Closure Input) {
 		accelerationSensors.find(Input)
 	}
diff --git a/AeonKeyFob/AeonKeyFobs.groovy b/AeonKeyFob/AeonKeyFobs.groovy
index 673afa0..bbb1a35 100644
--- a/AeonKeyFob/AeonKeyFobs.groovy
+++ b/AeonKeyFob/AeonKeyFobs.groovy
@@ -37,6 +37,9 @@ public class AeonKeyFobs {
 	def each(Closure Input) {
 		aeonKeyFobs.each(Input)
 	}
+	def sort(Closure Input) {
+		aeonKeyFobs.sort(Input)
+	}
 	def find(Closure Input) {
 		aeonKeyFobs.find(Input)
 	}
diff --git a/Alarm/Alarm.groovy b/Alarm/Alarm.groovy
index d3834f1..446face 100644
--- a/Alarm/Alarm.groovy
+++ b/Alarm/Alarm.groovy
@@ -26,8 +26,8 @@ public class Alarm {
 
 	//By model checker
 	def setValue(String value) {
-		this.alarmLatestValue = alarm
 		println("the alarm with id:$id is triggered to $value!")
+		this.alarmLatestValue = value
 		this.alarm = value
 		this.currentAlarm = value
 	}
@@ -37,11 +37,13 @@ public class Alarm {
 	def both() {
 		if (alarm != "both") {
 			println("the alarm with id:$id is changed to both!")
-			this.alarmLatestValue = this.alarm
+			this.alarmLatestValue = "both"
 			this.alarm = "both"
 			this.currentAlarm = "both"
 			sendEvent([name: "alarm", value: "both", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "alarm.both", value: "both", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -52,33 +54,39 @@ public class Alarm {
 	def off() {
 		if (alarm != "off") {
 			println("the alarm with id:$id is changed to off!")
-			this.alarmLatestValue = this.alarm
+			this.alarmLatestValue = "off"
 			this.alarm = "off"
 			this.currentAlarm = "off"
 			sendEvent([name: "alarm", value: "off", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "alarm.off", value: "off", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
 	def siren() {
 		if (alarm != "siren") {
 			println("the alarm with id:$id is changed to siren!")
-			this.alarmLatestValue = this.alarm
+			this.alarmLatestValue = "siren"
 			this.alarm = "siren"
 			this.currentAlarm = "siren"
 			sendEvent([name: "alarm", value: "siren", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "alarm.siren", value: "siren", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
 	def strobe() {
 		if (alarm != "strobe") {
 			println("the alarm with id:$id is changed to strobe!")
-			this.alarmLatestValue = this.alarm
+			this.alarmLatestValue = "strobe"
 			this.alarm = "strobe"
 			this.currentAlarm = "strobe"
 			sendEvent([name: "alarm", value: "strobe", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "alarm.strobe", value: "strobe", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
diff --git a/Alarm/Alarms.groovy b/Alarm/Alarms.groovy
index bc805e1..3e0842d 100644
--- a/Alarm/Alarms.groovy
+++ b/Alarm/Alarms.groovy
@@ -41,10 +41,10 @@ public class Alarms {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != alarms[0].alarm) {
+			this.alarmLatestValue = eventDataMap["value"]
+			this.alarm = eventDataMap["value"]
+			this.currentAlarm = eventDataMap["value"]
 			alarms[0].setValue(eventDataMap["value"])
-			this.alarmLatestValue = alarms[0].alarmLatestValue
-			this.alarm = alarms[0].alarm
-			this.currentAlarm = alarms[0].alarm
 			sendEvent(eventDataMap)
 		}
 	}
@@ -62,6 +62,9 @@ public class Alarms {
 	def find(Closure Input) {
 		alarms.find(Input)
 	}
+	def sort(Closure Input) {
+		alarms.sort(Input)
+	}
 	def collect(Closure Input) {
 		alarms.collect(Input)
 	}
@@ -69,19 +72,19 @@ public class Alarms {
 	//By Apps
 	def both() {
 		if (alarm != "both") {
-			alarms[0].both()
-			alarmLatestValue = alarm
+			alarmLatestValue = "both"
 			alarm = "both"
 			currentAlarm = "both"
+			alarms[0].both()
 		}
 	}
 
 	def off() {
 		if (alarm != "off") {
-			alarms[0].off()
-			alarmLatestValue = alarm
+			alarmLatestValue = "off"
 			alarm = "off"
 			currentAlarm = "off"
+			alarms[0].off()
 		}
 	}
 
@@ -91,19 +94,19 @@ public class Alarms {
 
 	def siren() {
 		if (alarm != "siren") {
-			alarms[0].siren()
-			alarmLatestValue = alarm
+			alarmLatestValue = "siren"
 			alarm = "siren"
 			currentAlarm = "siren"
+			alarms[0].siren()
 		}
 	}
 
 	def strobe() {
 		if (alarm != "strobe") {
-			alarms[0].strobe()
-			alarmLatestValue = alarm
+			alarmLatestValue = "strobe"
 			alarm = "strobe"
 			currentAlarm = "strobe"
+			alarms[0].strobe()
 		}
 	}
 
diff --git a/AtomicState/AtomicState.groovy b/AtomicState/AtomicState.groovy
deleted file mode 100644
index a57a4a3..0000000
--- a/AtomicState/AtomicState.groovy
+++ /dev/null
@@ -1,21 +0,0 @@
-//Create a class for atomic state
-package AtomicState
-
-public class AtomicState {
-	def bucketKey
-	def accessKey
-	def bucketName
-	def isBucketCreated
-	def grokerSubdomain
-	def eventBuffer
-	def version
-	def isDisabled
-	def queue
-	def poll
-
-	AtomicState() {
-		this.version = "1.0"
-		this.accessKey = 15
-		this.bucketKey = 20
-	}
-}
diff --git a/Battery/Batteries.groovy b/Battery/Batteries.groovy
index 8aca5e2..36a203f 100644
--- a/Battery/Batteries.groovy
+++ b/Battery/Batteries.groovy
@@ -16,6 +16,7 @@ public class Batteries {
 	private String displayName = "battery0"
 	private int battery = 50
 	private int currentBattery = 50
+	private int batteryLatestValue = 50
 
 		
 	Batteries(Closure sendEvent, int deviceNumbers) {
@@ -31,10 +32,11 @@ public class Batteries {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != batteries[0].battery) {
+		if (eventDataMap["value"].toInteger() != batteries[0].battery) {
+			this.battery = eventDataMap["value"].toInteger()
+			this.currentBattery = eventDataMap["value"].toInteger()
+			this.batteryLatestValue = eventDataMap["value"].toInteger()
 			batteries[0].setValue(eventDataMap["value"])
-			this.battery = batteries[0].battery
-			this.currentBattery = batteries[0].battery
 			sendEvent(eventDataMap)
 		}
 	}
@@ -49,6 +51,9 @@ public class Batteries {
 	def each(Closure Input) {
 		batteries.each(Input)
 	}
+	def sort(Closure Input) {
+		batteries.sort(Input)
+	}
 	def find(Closure Input) {
 		batteries.find(Input)
 	}
@@ -61,6 +66,10 @@ public class Batteries {
 		batteries[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def latestValue(String deviceFeature) {
+		batteries[0].latestValue(deviceFeature)//It is called if we have only one device
+	}
+
 	def getAt(int ix) {
 		batteries[ix]
 	}
diff --git a/Battery/Battery.groovy b/Battery/Battery.groovy
index 5358fbd..df4b01a 100644
--- a/Battery/Battery.groovy
+++ b/Battery/Battery.groovy
@@ -8,6 +8,7 @@ public class Battery {
 	private String displayName
 	private int battery
 	private int currentBattery
+	private int batteryLatestValue
 
 	Battery(String id, String label, String displayName, int battery) {
 		this.id = id
@@ -15,6 +16,7 @@ public class Battery {
 		this.displayName = displayName
 		this.battery = battery
 		this.currentBattery = battery
+		this.batteryLatestValue = battery
 	}
 
 	//By Model Checker
@@ -22,6 +24,7 @@ public class Battery {
 		println("the battery level with id:$id is changed to $value!")
 		this.battery = value.toInteger()
 		this.currentBattery = value.toInteger()
+		this.batteryLatestValue = value.toInteger()
 	}
 
 	def currentValue(String deviceFeature) {
@@ -30,4 +33,10 @@ public class Battery {
 		}
 	}
 
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "battery") {
+			return batteryLatestValue
+		}
+	}
+
 }
diff --git a/BeaconSensor/BeaconSensor.groovy b/BeaconSensor/BeaconSensor.groovy
index 5f07e4c..1aafbb4 100644
--- a/BeaconSensor/BeaconSensor.groovy
+++ b/BeaconSensor/BeaconSensor.groovy
@@ -20,8 +20,8 @@ public class BeaconSensor {
 	}
 
 	def setValue(String value) {
-		this.presenceLatestValue = presence
 		println("the beacon sensor with id:$id is triggered to $value!")
+		this.presenceLatestValue = value
 		this.presence = value
 		this.currentPresence = value
 	}
diff --git a/BeaconSensor/BeaconSensors.groovy b/BeaconSensor/BeaconSensors.groovy
index 33dd1fe..a36a4a4 100644
--- a/BeaconSensor/BeaconSensors.groovy
+++ b/BeaconSensor/BeaconSensors.groovy
@@ -38,10 +38,10 @@ public class BeaconSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != beaconSensors[0].presence) {
+			this.presenceLatestValue = eventDataMap["value"]
+			this.presence = eventDataMap["value"]
+			this.currentPresence = eventDataMap["value"]
 			beaconSensors[0].setValue(eventDataMap["value"])
-			this.presenceLatestValue = beaconSensors[0].presenceLatestValue
-			this.presence = beaconSensors[0].presence
-			this.currentPresence = beaconSensors[0].presence
 			sendEvent(eventDataMap)
 		}
 	}
@@ -56,6 +56,9 @@ public class BeaconSensors {
 	def each(Closure Input) {
 		beaconSensors.each(Input)
 	}
+	def sort(Closure Input) {
+		beaconSensors.sort(Input)
+	}
 	def find(Closure Input) {
 		beaconSensors.find(Input)
 	}
diff --git a/CarbonMonoxideDetector/CarbonMonoxideDetector.groovy b/CarbonMonoxideDetector/CarbonMonoxideDetector.groovy
index 2943479..213d153 100644
--- a/CarbonMonoxideDetector/CarbonMonoxideDetector.groovy
+++ b/CarbonMonoxideDetector/CarbonMonoxideDetector.groovy
@@ -20,8 +20,8 @@ public class CarbonMonoxideDetector {
 	}
 
 	def setValue(String value) {
-		this.carbonMonoxideLatestValue = carbonMonoxide
 		println("the carbon monoxide detector with id:$id is triggered to $value!")
+		this.carbonMonoxideLatestValue = value
 		this.carbonMonoxide = value
 		this.currentCarbonMonoxideValue = value
 	}
diff --git a/CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy b/CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy
index 2eb9d74..3449552 100644
--- a/CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy
+++ b/CarbonMonoxideDetector/CarbonMonoxideDetectors.groovy
@@ -41,10 +41,10 @@ public class CarbonMonoxideDetectors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != carbonMonoxideDetectors[0].currentCarbonMonoxideValue) {
+			this.carbonMonoxideLatestValue = eventDataMap["value"]
+			this.carbonMonoxide = eventDataMap["value"]
+			this.currentCarbonMonoxideValue = eventDataMap["value"]
 			carbonMonoxideDetectors[0].setValue(eventDataMap["value"])
-			this.carbonMonoxideLatestValue = carbonMonoxideDetectors[0].carbonMonoxideLatestValue
-			this.carbonMonoxide = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
-			this.currentCarbonMonoxideValue = carbonMonoxideDetectors[0].currentCarbonMonoxideValue
 			sendEvent(eventDataMap)
 		}
 	}
@@ -62,6 +62,9 @@ public class CarbonMonoxideDetectors {
 	def find(Closure Input) {
 		carbonMonoxideDetectors.find(Input)
 	}
+	def sort(Closure Input) {
+		carbonMonoxideDetectors.sort(Input)
+	}
 	def collect(Closure Input) {
 		carbonMonoxideDetectors.collect(Input)
 	}
diff --git a/ColorControl/ColorControl.groovy b/ColorControl/ColorControl.groovy
index ac80290..53658dc 100644
--- a/ColorControl/ColorControl.groovy
+++ b/ColorControl/ColorControl.groovy
@@ -8,16 +8,22 @@ public class ColorControl {
 	private String label
 	private String displayName
 	private String color
+	private String currentSwitch
+	private int level
 	private int hue
 	private int saturation
+	private int colorTemperature
 	
-	ColorControl(String id, String label, String displayName, String color, int hue, int saturation) {
+	ColorControl(String id, String label, String displayName, String color, int hue, int saturation, int level, String currentSwitch, int colorTemperature) {
 		this.id = id
 		this.label = label
 		this.displayName = displayName
 		this.color = color
 		this.hue = hue
 		this.saturation = saturation
+		this.level = level
+		this.currentSwitch = currentSwitch
+		this.colorTemperature = colorTemperature
 	}
 	
 	//By model checker
@@ -28,9 +34,18 @@ public class ColorControl {
 		} else if ((name == "hue") && (value != this.hue)) {
 			this.hue = value.toInteger()
 			println("The hue level of the light is changed to $value!")
-		} else if (value != this.saturation) {
+		} else if ((name == "saturation") && (value != this.saturation)) {
 			this.saturation = value.toInteger()
 			println("The saturation level of the light is changed to $value!")
+		} else if ((name == "level") && (value != this.level)) {
+			this.level = value.toInteger()
+			println("The level of the light is changed to $value!")
+		} else if ((name == "currentSwitch") && (value != this.currentSwitch)) {
+			this.currentSwitch = value
+			println("The light is changed to $value!")
+		} else if ((name == "colorTemperature") && (value != this.colorTemperature)) {
+			this.colorTemperature = value.toInteger()
+			println("The color temperature level of the light is changed to $value!")
 		}
 	}
 
@@ -62,6 +77,46 @@ public class ColorControl {
 		}
 	}
 
+	def setLevel(int level) {
+		if (level != this.level) {
+			this.level = level
+			println("The level of the light is changed to $level!")
+			sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		}
+	}
+
+	def setColorTemperature(int colorTemperature) {
+		if (colorTemperature != this.colorTemperature) {
+			this.colorTemperature = colorTemperature
+			println("The color temperature level of the light is changed to $colorTemperature!")
+			sendEvent([name: "colorTemperature", value: "$colorTemperature", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		}
+	}
+
+	def on(String currentSwitch) {
+		if (currentSwitch != this.currentSwitch) {
+			this.currentSwitch = currentSwitch
+			println("The light is changed to $currentSwitch!")
+			sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		}
+	}
+
+	def off(String currentSwitch) {
+		if (currentSwitch != this.currentSwitch) {
+			this.currentSwitch = currentSwitch
+			println("The light is changed to $currentSwitch!")
+			sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		}
+	}
+
 	def currentValue(String deviceFeature) {
 		if (deviceFeature == "color") {
 			return color
@@ -69,6 +124,28 @@ public class ColorControl {
 			return saturation
 		} else if (deviceFeature == "hue") {
 			return hue
+		} else if (deviceFeature == "level") {
+			return level
+		} else if (deviceFeature == "colorTemperature") {
+			return colorTemperature
+		} else if (deviceFeature == "switch") {
+			return currentSwitch
+		}
+	}
+
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "color") {
+			return color
+		} else if (deviceFeature == "saturation") {
+			return saturation
+		} else if (deviceFeature == "hue") {
+			return hue
+		} else if (deviceFeature == "level") {
+			return level
+		} else if (deviceFeature == "colorTemperature") {
+			return colorTemperature
+		} else if (deviceFeature == "switch") {
+			return currentSwitch
 		}
 	}
 }
diff --git a/ColorControl/ColorControls.groovy b/ColorControl/ColorControls.groovy
index d96b978..74964fe 100644
--- a/ColorControl/ColorControls.groovy
+++ b/ColorControl/ColorControls.groovy
@@ -15,10 +15,13 @@ public class ColorControls {
 	private String label = "colorControl0"
 	private String displayName = "colorControl0"
 	private String color = "red"
+	private String currentSwitch = "off"
+	private int level = 50
 	private int hue = 50
 	private int saturation = 50
+	private int colorTemperature = 15000
 	
-		
+
 	ColorControls(Closure sendEvent, int deviceNumbers) {
 		this.sendEvent = sendEvent
 		this.deviceNumbers = deviceNumbers
@@ -37,7 +40,7 @@ public class ColorControls {
 			this.color = "blue"
 		}
 
-		colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
+		colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
 	}
 
 	//Methods for closures
@@ -53,6 +56,9 @@ public class ColorControls {
 	def find(Closure Input) {
 		colorControls.find(Input)
 	}
+	def sort(Closure Input) {
+		colorControls.sort(Input)
+	}
 	def collect(Closure Input) {
 		colorControls.collect(Input)
 	}
@@ -61,20 +67,38 @@ public class ColorControls {
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["name"] == "color") {
 			if (eventDataMap["value"] != colorControls[0].color) {
+				this.color = eventDataMap["value"]
 				colorControls[0].setValue(eventDataMap["value"], "color")
-				this.color = colorControls[0].color
 				sendEvent(eventDataMap)
 			}	
 		} else if (eventDataMap["name"] == "hue") {
-			if (eventDataMap["value"] != colorControls[0].hue) {
+			if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
+				this.hue = eventDataMap["value"].toInteger()
 				colorControls[0].setValue(eventDataMap["value"], "hue")
-				this.hue = colorControls[0].hue
 				sendEvent(eventDataMap)
 			}
-		} else {
-			if (eventDataMap["value"] != colorControls[0].saturation) {
+		} else if (eventDataMap["name"] == "saturation") {
+			if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
+				this.saturation = eventDataMap["value"].toInteger()
 				colorControls[0].setValue(eventDataMap["value"], "saturation")
-				this.saturation = colorControls[0].saturation
+				sendEvent(eventDataMap)
+			}
+		} else if (eventDataMap["name"] == "switch") {
+			if (eventDataMap["value"] != colorControls[0].currentSwitch) {
+				this.currentSwitch = eventDataMap["value"]
+				colorControls[0].setValue(eventDataMap["value"], "switch")
+				sendEvent(eventDataMap)
+			}
+		} else if (eventDataMap["name"] == "colorTemperature") {
+			if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
+				this.colorTemperature = eventDataMap["value"].toInteger()
+				colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
+				sendEvent(eventDataMap)
+			}
+		} else if (eventDataMap["name"] == "level") {
+			if (eventDataMap["value"].toInteger() != colorControls[0].level) {
+				this.level = eventDataMap["value"].toInteger()
+				colorControls[0].setValue(eventDataMap["value"], "level")
 				sendEvent(eventDataMap)
 			}
 		}
@@ -84,29 +108,61 @@ public class ColorControls {
 	//methods
 	def setColor(String color) {
 		if (color != this.color) {
-			colorControls[0].setColor(color)
 			this.color = color
+			colorControls[0].setColor(color)			
 		}
 	}
 
 	def setHue(int hue) {
-		if (hue != this.hue) {		
+		if (hue != this.hue) {
+			this.hue = hue	
 			colorControls[0].setHue(hue)
-			this.hue = hue
 		}
 	}
 
 	def setSaturation(int saturation) {
 		if (saturation != this.saturation) {
-			colorControls[0].setSaturation(saturation)
 			this.saturation = saturation
+			colorControls[0].setSaturation(saturation)			
 		}	
 	}
 
+	def setLevel(int level) {
+		if (level != this.level) {
+			this.level = level
+			colorControls[0].setLevel(level)
+		}
+	}
+
+	def setColorTemperature(String colorTemperature) {
+		if (colorTemperature != this.colorTemperature) {
+			this.colorTemperature = colorTemperature
+			colorControls[0].setColorTemperature(colorTemperature)			
+		}
+	}
+
+	def on(String currentSwitch) {
+		if (currentSwitch != this.currentSwitch) {
+			this.currentSwitch = currentSwitch
+			colorControls[0].on(currentSwitch)			
+		}
+	}
+
+	def off(String currentSwitch) {
+		if (currentSwitch != this.currentSwitch) {
+			this.currentSwitch = currentSwitch
+			colorControls[0].off(currentSwitch)			
+		}
+	}
+
 	def currentValue(String deviceFeature) {
 		colorControls[0].currentValue(deviceFeature)
 	}
 
+	def latestValue(String deviceFeature) {
+		colorControls[0].latestValue(deviceFeature)
+	}	
+
 	def getAt(int ix) {
 		colorControls[ix]
 	}
diff --git a/ContactSensor/ContactSensor.groovy b/ContactSensor/ContactSensor.groovy
index d13993a..b4ed629 100644
--- a/ContactSensor/ContactSensor.groovy
+++ b/ContactSensor/ContactSensor.groovy
@@ -10,6 +10,8 @@ public class ContactSensor {
 	private String currentContact	
 	private String latestValue
 	private String alarmState
+	private List events = []
+	private List timeOfEvents = []
 	
 
 	ContactSensor(String id, String label, String displayName, String contactState, String currentContact, String alarmState, String latestValue) {
@@ -23,10 +25,22 @@ public class ContactSensor {
 	}
 
 	def setValue(String value) {
-		this.latestValue = contactState
 		println("the contact sensor with id:$id is triggered to $value!")
 		this.contactState = value
 		this.currentContact = value
+		this.latestValue = value
+		this.events.add(eventDataMap)
+		this.timeOfEvents.add(System.currentTimeMillis())
+	}
+
+	def eventsSince(Date dateObj) {
+		def List happenedEvents = []
+		def sinceThen = dateObj.time
+		for (int i = 0;i < timeOfEvents.size();i++) {
+			if (timeOfEvents[i]>=sinceThen)
+				happenedEvents.add(events[i])
+		}
+		return happenedEvents
 	}
 	
 	def on() {
@@ -45,6 +59,12 @@ public class ContactSensor {
 		}
 	}
 
+	def currentState(String deviceFeature) {
+		if (deviceFeature == "contact") {
+			return contactState
+		}
+	}
+
 	def latestValue(String deviceFeature) {
 		if (deviceFeature == "contact") {
 			return latestValue
diff --git a/ContactSensor/ContactSensors.groovy b/ContactSensor/ContactSensors.groovy
index 489200d..ca55a09 100644
--- a/ContactSensor/ContactSensors.groovy
+++ b/ContactSensor/ContactSensors.groovy
@@ -58,6 +58,9 @@ public class ContactSensors {
 	def find(Closure Input) {
 		contacts.find(Input)
 	}
+	def sort(Closure Input) {
+		contacts.sort(Input)
+	}
 	def collect(Closure Input) {
 		contacts.collect(Input)
 	}
@@ -65,28 +68,32 @@ public class ContactSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != contacts[0].contactState) {
+			this.latestValue = eventDataMap["value"]
+			this.contactState = eventDataMap["value"]
+			this.currentContact = eventDataMap["value"]
 			contacts[0].setValue(eventDataMap["value"])
-			this.latestValue = contacts[0].latestValue
-			this.contactState = contacts[0].contactState
-			this.currentContact = contacts[0].contactState
 			sendEvent(eventDataMap)
 		}
 	}
 
 	def on() {
-		contacts[0].on()
 		this.alarmState = "armed"
+		contacts[0].on()
 	}
 
 	def off() {
-		contacts[0].off()
 		this.alarmState = "not armed"
+		contacts[0].off()
 	}
 
 	def currentValue(String deviceFeature) {
 		contacts[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def currentState(String deviceFeature) {
+		contacts[0].currentState(deviceFeature)//It is called if we have only one device
+	}
+
 	def latestValue(String deviceFeature) {
 		contacts[0].latestValue(deviceFeature)//It is called if we have only one device
 	}
diff --git a/DoorControl/DoorControl.groovy b/DoorControl/DoorControl.groovy
index 1830070..d0b04d2 100644
--- a/DoorControl/DoorControl.groovy
+++ b/DoorControl/DoorControl.groovy
@@ -19,16 +19,19 @@ public class DoorControl {
 		this.label = label
 		this.displayName = displayName
 		this.doorState = doorState
+		this.doorLatestValue = doorLatestValue
 	}
 
 	//By Apps
 	def open() {
 		if (doorState != "open") {
 			println("the door with id:$id is open!")
-			this.doorLatestValue = this.doorState
+			this.doorLatestValue = "open"
 			this.doorState = "open"
 			sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "doorControl.open", value: "open", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -36,10 +39,12 @@ public class DoorControl {
 		if (doorState != "open") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the door with id:$id is open!")
-				this.doorLatestValue = this.doorState
+				this.doorLatestValue = "open"
 				this.doorState = "open"
 				sendEvent([name: "doorControl", value: "open", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "doorControl.open", value: "open", deviceId: this.id, descriptionText: "",
+				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -47,10 +52,12 @@ public class DoorControl {
 	def close() {
 		if (doorState != "closed") {
 			println("the door with id:$id is closed!")
-			this.doorLatestValue = this.doorState
+			this.doorLatestValue = "closed"
 			this.doorState = "closed"
 			sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "doorControl.closed", value: "closed", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -58,10 +65,12 @@ public class DoorControl {
 		if (doorState != "closed") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the door with id:$id is closed!")
-				this.doorLatestValue = this.doorState
+				this.doorLatestValue = "closed"
 				this.doorState = "closed"
 				sendEvent([name: "doorControl", value: "closed", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "doorControl.closed", value: "closed", deviceId: this.id, descriptionText: "",
+			    	    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -69,7 +78,7 @@ public class DoorControl {
 	//By Model Checker
 	def setValue(String value) {
 		println("the door with id:$id is $value!")
-		this.doorLatestValue = this.doorState
+		this.doorLatestValue = value
 		this.doorState = value
 	}
 	
diff --git a/DoorControl/DoorControls.groovy b/DoorControl/DoorControls.groovy
index 2581800..d47d7d4 100644
--- a/DoorControl/DoorControls.groovy
+++ b/DoorControl/DoorControls.groovy
@@ -48,6 +48,9 @@ public class DoorControls {
 	def find(Closure Input) {
 		doorControls.find(Input)
 	}
+	def sort(Closure Input) {
+		doorControls.sort(Input)
+	}
 	def collect(Closure Input) {
 		doorControls.collect(Input)
 	}
@@ -82,8 +85,9 @@ public class DoorControls {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != doorControls[0].doorState) {
+			this.doorState = eventDataMap["value"]
+			this.doorLatestValue = eventDataMap["value"]
 			doorControls[0].setValue(eventDataMap["value"])
-			this.doorState = doorControls[0].doorState
 			sendEvent(eventDataMap)
 		}
 	}
diff --git a/EnergyMeter/EnergyMeter.groovy b/EnergyMeter/EnergyMeter.groovy
index a0ab13e..c4eca23 100644
--- a/EnergyMeter/EnergyMeter.groovy
+++ b/EnergyMeter/EnergyMeter.groovy
@@ -29,4 +29,9 @@ public class EnergyMeter {
 		}
 	}
 
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "energy") {
+			return energy
+		}
+	}
 }
diff --git a/EnergyMeter/EnergyMeters.groovy b/EnergyMeter/EnergyMeters.groovy
index a3f2b8d..296cdaa 100644
--- a/EnergyMeter/EnergyMeters.groovy
+++ b/EnergyMeter/EnergyMeters.groovy
@@ -31,10 +31,10 @@ public class EnergyMeters {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != energyMeters[0].energy) {
-			energyMeters[0].setValue(eventDataMap["value"])
-			this.energy = energyMeters[0].energy
-			this.currentEnergy = energyMeters[0].currentEnergy		
+		if (eventDataMap["value"].toInteger() != energyMeters[0].energy) {
+			this.energy = eventDataMap["value"].toInteger()
+			this.currentEnergy = eventDataMap["value"].toInteger()
+			energyMeters[0].setValue(eventDataMap["value"])	
 			sendEvent(eventDataMap)
 		}
 	}
@@ -52,6 +52,9 @@ public class EnergyMeters {
 	def find(Closure Input) {
 		energyMeters.find(Input)
 	}
+	def sort(Closure Input) {
+		energyMeters.sort(Input)
+	}
 	def collect(Closure Input) {
 		energyMeters.collect(Input)
 	}
@@ -61,6 +64,10 @@ public class EnergyMeters {
 		energyMeters[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def latestValue(String deviceFeature) {
+		energyMeters[0].latestValue(deviceFeature)//It is called if we have only one device
+	}
+
 	def getAt(int ix) {
 		energyMeters[ix]
 	}
diff --git a/Extractor/App1/App1.groovy b/Extractor/App1/App1.groovy
index 94ec37c..b41e7a6 100644
--- a/Extractor/App1/App1.groovy
+++ b/Extractor/App1/App1.groovy
@@ -1,115 +1,179 @@
+/**
+ * 	Color Coordinator 
+ *  Version 1.1.1 - 11/9/16
+ *  By Michael Struck
+ *
+ *  1.0.0 - Initial release
+ *  1.1.0 - Fixed issue where master can be part of slaves. This causes a loop that impacts SmartThings. 
+ *  1.1.1 - Fix NPE being thrown for slave/master inputs being empty.
+ *
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
+ *  in compliance with the License. You may obtain a copy of the License at:
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
+ *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
+ *  for the specific language governing permissions and limitations under the License.
+ *
+ */
 definition(
-    name: "Enhanced Auto Lock Door",
-    namespace: "Lock Auto Super Enhanced",
-    author: "Arnaud",
-    description: "Automatically locks a specific door after X minutes when closed  and unlocks it when open after X seconds.",
-    category: "Safety & Security",
-    iconUrl: "http://www.gharexpert.com/mid/4142010105208.jpg",
-    iconX2Url: "http://www.gharexpert.com/mid/4142010105208.jpg"
+	name: "Color Coordinator",
+	namespace: "MichaelStruck",
+	author: "Michael Struck",
+	description: "Ties multiple colored lights to one specific light's settings",
+	category: "Convenience",
+	iconUrl: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC.png",
+	iconX2Url: "https://raw.githubusercontent.com/MichaelStruck/SmartThings/master/Other-SmartApps/ColorCoordinator/CC@2x.png"
 )
 
-preferences{
-    section("Select the door lock:") {
-        input "lock1", "capability.lock", required: true
-    }
-    section("Select the door contact sensor:") {
-        input "contact", "capability.contactSensor", required: true
-    }   
-    section("Automatically lock the door when closed...") {
-        input "minutesLater", "number", title: "Delay (in minutes):", required: true
-    }
-    section("Automatically unlock the door when open...") {
-        input "secondsLater", "number", title: "Delay (in seconds):", required: true
-    }
-    section( "Notifications" ) {
-        input("recipients", "contact", title: "Send notifications to", required: false) {
-            input "phoneNumber", "phone", title: "Warn with text message (optional)", description: "Phone Number", required: false
+preferences {
+	page name: "mainPage"
+}
+
+def mainPage() {
+	section("Master Light") {
+		input "master", "capability.colorControl", title: "Colored Light", required: true
+	}
+	section("Lights that follow the master settings") {
+		input "slaves", "capability.colorControl", title: "Colored Lights",  multiple: true, required: true, submitOnChange: true
+	}
+    	section([mobileOnly:true], "Options") {
+		input "randomYes", "bool",title: "When Master Turned On, Randomize Color", defaultValue: false
+		href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
+        }
+	
+	dynamicPage(name: "mainPage", title: "", install: true, uninstall: false) {
+	def masterInList = slaves?.id?.find{it==master?.id}
+        if (masterInList) {
+        	section ("**WARNING**"){
+            		paragraph "You have included the Master Light in the Slave Group. This will cause a loop in execution. Please remove this device from the Slave Group.", image: "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/caution.png"
+            	}
         }
-    }
+        
+	page(name: "pageAbout", title: "About ${textAppName()}", uninstall: true) {
+			section {
+				paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
+			}
+			section("Instructions") {
+				paragraph textHelp()
+			}
+			section("Tap button below to remove application"){
+			}
+		}
+		
+	}
 }
 
-def installed(){
-    initialize()
+def installed() {   
+	init() 
 }
 
 def updated(){
-    unsubscribe()
-    unschedule()
-    initialize()
+	unsubscribe()
+    init()
 }
 
-def initialize(){
-    log.debug "Settings: ${settings}"
-    subscribe(lock1, "lock", doorHandler, [filterEvents: false])
-    subscribe(lock1, "unlock", doorHandler, [filterEvents: false])  
-    subscribe(contact, "contact.open", doorHandler)
-    subscribe(contact, "contact.closed", doorHandler)
+def init() {
+    subscribe(master, "switch", onOffHandler)
+    subscribe(master, "level", colorHandler)
+    subscribe(master, "hue", colorHandler)
+    subscribe(master, "saturation", colorHandler)
+    subscribe(master, "colorTemperature", tempHandler)
+}
+//-----------------------------------
+def onOffHandler(evt){
+	if (slaves && master) {
+		if (!slaves?.id.find{it==master?.id}){
+		if (master?.currentValue("switch") == "on"){
+		    if (randomYes) getRandomColorMaster()
+				else slaves?.on()
+		}
+		else {
+		    slaves?.off()  
+		}
+		}
+	}
 }
 
-def lockDoor(){
-    log.debug "Locking the door."
-    lock1.lock()
-    if(location.contactBookEnabled) {
-        if ( recipients ) {
-            log.debug ( "Sending Push Notification..." ) 
-            sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
-        }
-    }
-    if (phoneNumber) {
-        log.debug("Sending text message...")
-        sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
-    }
+def colorHandler(evt) {
+	if (slaves && master) {
+		if (!slaves?.id?.find{it==master?.id} && master?.currentValue("switch") == "on"){
+			log.debug "Changing Slave units H,S,L"
+		def dimLevel = master?.currentValue("level")
+		def hueLevel = master?.currentValue("hue")
+		def saturationLevel = master.currentValue("saturation")
+			def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
+		slaves?.setColor(newValue)
+		try {
+			log.debug "Changing Slave color temp"
+			def tempLevel = master?.currentValue("colorTemperature")
+			slaves?.setColorTemperature(tempLevel)
+		}
+			catch (e){
+			log.debug "Color temp for master --"
+		}
+		}
+	}
 }
 
-def unlockDoor(){
-    log.debug "Unlocking the door."
-    lock1.unlock()
-    if(location.contactBookEnabled) {
-        if ( recipients ) {
-            log.debug ( "Sending Push Notification..." ) 
-            sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
-        }
-    }
-    if ( phoneNumber ) {
-        log.debug("Sending text message...")
-        sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
-    }
+def getRandomColorMaster(){
+    def hueLevel = Math.floor(Math.random() *1000)
+    def saturationLevel = Math.floor(Math.random() * 100)
+    def dimLevel = master?.currentValue("level")
+	def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
+    log.debug hueLevel
+    log.debug saturationLevel
+    master.setColor(newValue)
+    slaves?.setColor(newValue)   
 }
 
-def doorHandler(evt){
-    if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...  
-        //def delay = (secondsLater) // runIn uses seconds
-        runIn( secondsLater, unlockDoor )   // ...schedule (in minutes) to unlock...  We don't want the door to be closed while the lock is engaged. 
-    }
-    else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
-        unschedule( unlockDoor ) // ...we don't need to unlock it later.
-    }
-    else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
-        unschedule( lockDoor ) // ...we don't need to lock it later.
-    }   
-    else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
-       //def delay = (minutesLater * 60) // runIn uses seconds
-        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-    }
-    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
-        unschedule( lockDoor ) // ...we don't need to lock it later.
-    }
-    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
-        //def delay = (minutesLater * 60) // runIn uses seconds
-        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-    }
-    else { //Opening or Closing door when locked (in case you have a handle lock)
-        log.debug "Unlocking the door."
-        lock1.unlock()
-        if(location.contactBookEnabled) {
-            if ( recipients ) {
-                log.debug ( "Sending Push Notification..." ) 
-                sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
-            }
-        }
-        if ( phoneNumber ) {
-            log.debug("Sending text message...")
-            sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
-        }
-    }
+def tempHandler(evt){
+	if (slaves && master) {
+	    if (!slaves?.id?.find{it==master?.id} && master?.currentValue("switch") == "on"){
+		if (evt.value != "--") {
+		    log.debug "Changing Slave color temp based on Master change"
+		    def tempLevel = master.currentValue("colorTemperature")
+		    slaves?.setColorTemperature(tempLevel)
+		}
+		}
+	}
 }
+
+//Version/Copyright/Information/Help
+
+private def textAppName() {
+	def text = "Color Coordinator"
+}	
+
+private def textVersion() {
+    def text = "Version 1.1.1 (12/13/2016)"
+}
+
+private def textCopyright() {
+    def text = "Copyright © 2016 Michael Struck"
+}
+
+private def textLicense() {
+    def text =
+		"Licensed under the Apache License, Version 2.0 (the 'License'); "+
+		"you may not use this file except in compliance with the License. "+
+		"You may obtain a copy of the License at"+
+		"\n\n"+
+		"    http://www.apache.org/licenses/LICENSE-2.0"+
+		"\n\n"+
+		"Unless required by applicable law or agreed to in writing, software "+
+		"distributed under the License is distributed on an 'AS IS' BASIS, "+
+		"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. "+
+		"See the License for the specific language governing permissions and "+
+		"limitations under the License."
+}
+
+private def textHelp() {
+	def text =
+    	"This application will allow you to control the settings of multiple colored lights with one control. " +
+        "Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
+        "including on/off conditions, hue, saturation, level and color temperature. Also includes a random color feature."
+}
+
diff --git a/Extractor/App1/extractedFunctionsApp1.groovy b/Extractor/App1/extractedFunctionsApp1.groovy
deleted file mode 100644
index b7e30e6..0000000
--- a/Extractor/App1/extractedFunctionsApp1.groovy
+++ /dev/null
@@ -1,12 +0,0 @@
-//Global Object for functions in subscribe method!
-def installed = this.&installed
-//Global Object for functions in subscribe method!
-def updated = this.&updated
-//Global Object for functions in subscribe method!
-def initialize = this.&initialize
-//Global Object for functions in subscribe method!
-def lockDoor = this.&lockDoor
-//Global Object for functions in subscribe method!
-def unlockDoor = this.&unlockDoor
-//Global Object for functions in subscribe method!
-def doorHandler = this.&doorHandler
diff --git a/Extractor/App1/extractedObjectsApp1.groovy b/Extractor/App1/extractedObjectsApp1.groovy
deleted file mode 100644
index 79d75bb..0000000
--- a/Extractor/App1/extractedObjectsApp1.groovy
+++ /dev/null
@@ -1,12 +0,0 @@
-//Object for class lock!
-def lock1
-//Object for class contactSensor!
-def contact
-//Global variable for number!
-def minutesLater = 70
-//Global variable for number!
-def secondsLater = 93
-//Global variable for contact!
-def recipients = "AJ"
-//Global variable for phone!
-def phoneNumber = 9495379373
diff --git a/Extractor/App1/extractedObjectsConstructorApp1.groovy b/Extractor/App1/extractedObjectsConstructorApp1.groovy
deleted file mode 100644
index 29bfad5..0000000
--- a/Extractor/App1/extractedObjectsConstructorApp1.groovy
+++ /dev/null
@@ -1,4 +0,0 @@
-lock1 = obj.lockObject
-contact = obj.contactObject
-//Global variable for settings!
-settings = [app:app, lock1:lock1, contact:contact, minutesLater:minutesLater, secondsLater:secondsLater, recipients:recipients, phoneNumber:phoneNumber]
diff --git a/Extractor/App2/App2.groovy b/Extractor/App2/App2.groovy
index 61b6434..3c4c9d1 100644
--- a/Extractor/App2/App2.groovy
+++ b/Extractor/App2/App2.groovy
@@ -1,308 +1,188 @@
 /**
- *  Beacon Control
+ *  Medicine Management - Contact Sensor
  *
- *  Copyright 2014 Physical Graph Corporation
+ *  Copyright 2016 Jim Mangione
  *
  *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  *  in compliance with the License. You may obtain a copy of the License at:
- *
+ * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  *  for the specific language governing permissions and limitations under the License.
  *
+ * Logic: 
+ * --- Send notification at the medicine reminder time IF draw wasn't alread opened in past 60 minutes
+ * --- If draw still isn't open 10 minutes AFTER reminder time, LED will turn RED.
+ * --- ----- Once draw IS open, LED will return back to it's original color
+ *
  */
-definition(
-	name: "Beacon Control",
-	category: "SmartThings Internal",
-	namespace: "smartthings",
-	author: "SmartThings",
-	description: "Execute a Hello, Home phrase, turn on or off some lights, and/or lock or unlock your door when you enter or leave a monitored region",
-	iconUrl: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol.png",
-	iconX2Url: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol@2x.png"
-)
-
-preferences {
-	page(name: "timeIntervalInput", title: "Only during a certain time") {
-		section {
-			input "starting", "time", title: "Starting", required: false
-			input "ending", "time", title: "Ending", required: false
-		}
-	}
-	
-	page(name: "mainPage")
-}
+import groovy.time.TimeCategory 
 
-def mainPage() {
-	dynamicPage(name: "mainPage", install: true, uninstall: true) {
-
-		section("Where do you want to watch?") {
-			input name: "beacons", type: "capability.beacon", title: "Select your beacon(s)", 
-				multiple: true, required: true
-		}
-
-		section("Who do you want to watch for?") {
-			input name: "phones", type: "device.mobilePresence", title: "Select your phone(s)", 
-				multiple: true, required: true
-		}
-
-		section("What do you want to do on arrival?") {
-			input name: "arrivalPhrase", type: "enum", title: "Execute a phrase", 
-				options: listPhrases(), required: false
-			input "arrivalOnSwitches", "capability.switch", title: "Turn on some switches", 
-				multiple: true, required: false
-			input "arrivalOffSwitches", "capability.switch", title: "Turn off some switches", 
-				multiple: true, required: false
-			input "arrivalLocks", "capability.lock", title: "Unlock the door",
-				multiple: true, required: false
-		}
-
-		section("What do you want to do on departure?") {
-			input name: "departPhrase", type: "enum", title: "Execute a phrase", 
-				options: listPhrases(), required: false
-			input "departOnSwitches", "capability.switch", title: "Turn on some switches", 
-				multiple: true, required: false
-			input "departOffSwitches", "capability.switch", title: "Turn off some switches", 
-				multiple: true, required: false
-			input "departLocks", "capability.lock", title: "Lock the door",
-				multiple: true, required: false
-		}
+definition(
+    name: "Medicine Management - Contact Sensor",
+    namespace: "MangioneImagery",
+    author: "Jim Mangione",
+    description: "This supports devices with capabilities of ContactSensor and ColorControl (LED). It sends an in-app and ambient light notification if you forget to open the drawer or cabinet where meds are stored. A reminder will be set to a single time per day. If the draw or cabinet isn't opened within 60 minutes of that reminder, an in-app message will be sent. If the draw or cabinet still isn't opened after an additional 10 minutes, then an LED light turns red until the draw or cabinet is opened",
+    category: "Health & Wellness",
+    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
+    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
+    iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
 
-		section("Do you want to be notified?") {
-			input "pushNotification", "bool", title: "Send a push notification"
-			input "phone", "phone", title: "Send a text message", description: "Tap to enter phone number", 
-				required: false
-		}
 
-		section {
-			label title: "Give your automation a name", description: "e.g. Goodnight Home, Wake Up"
-		}
+preferences {
 
-		def timeLabel = timeIntervalLabel()
-		section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
-			href "timeIntervalInput", title: "Only during a certain time", 
-				description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
+	section("My Medicine Draw/Cabinet"){
+		input "deviceContactSensor", "capability.contactSensor", title: "Opened Sensor" 
+	} 
 
-			input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
-				options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
+    section("Remind me to take my medicine at"){
+        input "reminderTime", "time", title: "Time"
+    }
+    
+    // NOTE: Use REAL device - virtual device causes compilation errors
+    section("My LED Light"){
+    	input "deviceLight", "capability.colorControl", title: "Smart light"
+    }
 
-			input "modes", "mode", title: "Only when mode is", multiple: true, required: false
-		}
-	}
 }
 
-// Lifecycle management
 def installed() {
-	log.debug "<beacon-control> Installed with settings: ${settings}"
+	log.debug "Installed with settings: ${settings}"
+	
 	initialize()
 }
 
 def updated() {
-	log.debug "<beacon-control> Updated with settings: ${settings}"
+	log.debug "Updated with settings: ${settings}"
+
 	unsubscribe()
+        
 	initialize()
 }
 
 def initialize() {
-	subscribe(beacons, "presence", beaconHandler)
-}
-
-// Event handlers
-def beaconHandler(evt) {
-	log.debug "<beacon-control> beaconHandler: $evt"
-
-	if (allOk) {
-		def data = new groovy.json.JsonSlurper().parseText(evt.data)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> data: $data - phones: " + phones*.deviceNetworkId
 
-		def beaconName = getBeaconName(evt)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> beaconName: $beaconName"
-
-		def phoneName = getPhoneName(data)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> phoneName: $phoneName"
-		if (phoneName != null) {
-            def action = data.presence == "1" ? "arrived" : "left"
-            def msg = "$phoneName has $action ${action == 'arrived' ? 'at ' : ''}the $beaconName"
-
-            if (action == "arrived") {
-                msg = arriveActions(msg)
-            }
-            else if (action == "left") {
-                msg = departActions(msg)
-            }
-            log.debug "<beacon-control> msg: $msg"
-
-            if (pushNotification || phone) {
-                def options = [
-                    method: (pushNotification && phone) ? "both" : (pushNotification ? "push" : "sms"),
-                    phone: phone
-                ]
-                sendNotification(msg, options)
-            }
+    // will stop LED notification incase it was set by med reminder
+    subscribe(deviceContactSensor, "contact", contactHandler)
+
+    // how many minutes to look in the past from the reminder time, for an open draw
+    state.minutesToCheckOpenDraw = 60
+    
+    // is true when LED notification is set after exceeding 10 minutes past reminder time
+    state.ledNotificationTriggered = false
+    
+    // Set a timer to run once a day to notify if draw wasn't opened yet
+    schedule(reminderTime, checkOpenDrawInPast)
+   
+}
+
+// Should turn off any LED notification on OPEN state
+def contactHandler(evt){
+	if (evt.value == "open") {
+        // if LED notification triggered, reset it.
+        log.debug "Cabinet opened"
+        if (state.ledNotificationTriggered) {
+            resetLEDNotification()
         }
 	}
 }
 
-// Helpers
-private arriveActions(msg) {
-	if (arrivalPhrase || arrivalOnSwitches || arrivalOffSwitches || arrivalLocks) msg += ", so"
-	
-	if (arrivalPhrase) {
-		log.debug "<beacon-control> executing: $arrivalPhrase"
-		executePhrase(arrivalPhrase)
-		msg += " ${prefix('executed')} $arrivalPhrase."
-	}
-	if (arrivalOnSwitches) {
-		log.debug "<beacon-control> turning on: $arrivalOnSwitches"
-		arrivalOnSwitches.on()
-		msg += " ${prefix('turned')} ${list(arrivalOnSwitches)} on."
-	}
-	if (arrivalOffSwitches) {
-		log.debug "<beacon-control> turning off: $arrivalOffSwitches"
-		arrivalOffSwitches.off()
-		msg += " ${prefix('turned')} ${list(arrivalOffSwitches)} off."
-	}
-	if (arrivalLocks) {
-		log.debug "<beacon-control> unlocking: $arrivalLocks"
-		arrivalLocks.unlock()
-		msg += " ${prefix('unlocked')} ${list(arrivalLocks)}."
-	}
-	msg
-}
-
-private departActions(msg) {
-	if (departPhrase || departOnSwitches || departOffSwitches || departLocks) msg += ", so"
-	
-	if (departPhrase) {
-		log.debug "<beacon-control> executing: $departPhrase"
-		executePhrase(departPhrase)
-		msg += " ${prefix('executed')} $departPhrase."
-	}
-	if (departOnSwitches) {
-		log.debug "<beacon-control> turning on: $departOnSwitches"
-		departOnSwitches.on()
-		msg += " ${prefix('turned')} ${list(departOnSwitches)} on."
-	}
-	if (departOffSwitches) {
-		log.debug "<beacon-control> turning off: $departOffSwitches"
-		departOffSwitches.off()
-		msg += " ${prefix('turned')} ${list(departOffSwitches)} off."
-	}
-	if (departLocks) {
-		log.debug "<beacon-control> unlocking: $departLocks"
-		departLocks.lock()
-		msg += " ${prefix('locked')} ${list(departLocks)}."
-	}
-	msg
-}
-
-private prefix(word) {
-	def result
-	def index = settings.prefixIndex == null ? 0 : settings.prefixIndex + 1
-	switch (index) {
-		case 0:
-			result = "I $word"
-			break
-		case 1:
-			result = "I also $word"
-			break
-		case 2:
-			result = "And I $word"
-			break
-		default:
-			result = "And $word"
-			break
-	}
-
-	settings.prefixIndex = index
-	log.trace "prefix($word'): $result"
-	result
-}
-
-private listPhrases() {
-	location.helloHome.getPhrases().label
-}
-
-private executePhrase(phraseName) {
-	if (phraseName) {
-		location.helloHome.execute(phraseName)
-		log.debug "<beacon-control> executed phrase: $phraseName"
-	}
-}
-
-private getBeaconName(evt) {
-	def beaconName = beacons.find { b -> b.id == evt.deviceId }
-	return beaconName
-}
-
-private getPhoneName(data) {    
-	def phoneName = phones.find { phone ->
-		// Work around DNI bug in data
-		def pParts = phone.deviceNetworkId.split('\\|')
-		def dParts = data.dni.split('\\|')
-        pParts[0] == dParts[0]
+// If the draw was NOT opened within 60 minutes of the timer send notification out.
+def checkOpenDrawInPast(){
+	log.debug "Checking past 60 minutes of activity from $reminderTime"
+    
+    // check activity of sensor for past 60 minutes for any OPENED status
+    def cabinetOpened = isOpened(state.minutesToCheckOpenDraw)
+	log.debug "Cabinet found opened: $cabinetOpened"
+    
+    // if it's opened, then do nothing and assume they took their meds
+    if (!cabinetOpened) {    
+    	sendNotification("Hi, please remember to take your meds in the cabinet")
+       
+       // if no open activity, send out notification and set new reminder    
+        def reminderTimePlus10 = new Date(now() + (10 * 60000))
+
+        // needs to be scheduled if draw wasn't already opened
+        runOnce(reminderTimePlus10, checkOpenDrawAfterReminder)
+    }
+}
+
+// If the draw was NOT opened after 10 minutes past reminder, use LED notification
+def checkOpenDrawAfterReminder(){
+	log.debug "Checking additional 10 minutes of activity from $reminderTime"
+    
+    // check activity of sensor for past 10 minutes for any OPENED status
+    def cabinetOpened = isOpened(10)    
+    
+   	log.debug "Cabinet found opened: $cabinetOpened"
+        
+    // if no open activity, blink lights
+    if (!cabinetOpened) {
+    	log.debug "Set LED to Notification color"
+        setLEDNotification()
+    }
+    
+}
+
+// Helper function for sending out an app notification
+def sendNotification(msg){
+        log.debug "Message Sent: $msg"
+        sendPush(msg)
+}
+
+// Check if the sensor has been opened since the minutes entered
+// Return true if opened found, else false.
+def isOpened(minutes){
+    // query last X minutes of activity log    
+    def previousDateTime = new Date(now() - (minutes * 60000))
+    
+    // capture all events recorded
+    def evts = deviceContactSensor.eventsSince(previousDateTime)   
+    def cabinetOpened = false
+    if (evts.size() > 0) {
+        evts.each{
+            if(it.value == "open") {
+                cabinetOpened = true 
+            }
+        }
 	}
-	return phoneName
+    
+    return cabinetOpened
 }
 
-private hideOptionsSection() {
-	(starting || ending || days || modes) ? false : true
-}
+// Saves current color and sets the light to RED
+def setLEDNotification(){
 
-private getAllOk() {
-	modeOk && daysOk && timeOk
-}
+	state.ledNotificationTriggered = true
+    
+	// turn light back off when reset is called if it was originally off
+ 	state.ledState = deviceLight.currentValue("switch")
 
-private getModeOk() {
-	def result = !modes || modes.contains(location.mode)
-	log.trace "<beacon-control> modeOk = $result"
-	result
-}
+	// set light to RED and store original color until stopped    
+    state.origColor = deviceLight.currentValue("hue")
+    deviceLight.on()
+    deviceLight.setHue(100)
+    
+    log.debug "LED set to RED. Original color stored: $state.origColor"
 
-private getDaysOk() {
-	def result = true
-	if (days) {
-		def df = new java.text.SimpleDateFormat("EEEE")
-		if (location.timeZone) {
-			df.setTimeZone(location.timeZone)
-		}
-		else {
-			df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
-		}
-		def day = df.format(new Date())
-		result = days.contains(day)
-	}
-	log.trace "<beacon-control> daysOk = $result"
-	result
 }
 
-private getTimeOk() {
-	def result = true
-	if (starting && ending) {
-		def currTime = now()
-		def start = timeToday(starting, location?.timeZone).time
-		def stop = timeToday(ending, location?.timeZone).time
-		result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
-	}
-	log.trace "<beacon-control> timeOk = $result"
-	result
-}
+// Sets the color back to the original saved color
+def resetLEDNotification(){
 
-private hhmm(time, fmt = "h:mm a") {
-	def t = timeToday(time, location.timeZone)
-	def f = new java.text.SimpleDateFormat(fmt)
-	f.setTimeZone(location.timeZone ?: timeZone(time))
-	f.format(t)
-}
-
-private timeIntervalLabel() {
-	(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
-}
+	state.ledNotificationTriggered = false
+    
+    // return color to original
+    log.debug "Reset LED color to: $state.origColor"
+    if (state.origColor != null) {
+    	deviceLight.setHue(state.origColor)
+    }
+    
+    // if the light was turned on just for the notification, turn it back off now
+    if (state.ledState == "off") {
+    	deviceLight.off()
+    }
 
-private list(Object names) {
-	return names[0]
 }
diff --git a/Extractor/App2/extractedFunctionsApp2.groovy b/Extractor/App2/extractedFunctionsApp2.groovy
deleted file mode 100644
index 8430b82..0000000
--- a/Extractor/App2/extractedFunctionsApp2.groovy
+++ /dev/null
@@ -1,40 +0,0 @@
-//Global Object for functions in subscribe method!
-def mainPage = this.&mainPage
-//Global Object for functions in subscribe method!
-def installed = this.&installed
-//Global Object for functions in subscribe method!
-def updated = this.&updated
-//Global Object for functions in subscribe method!
-def initialize = this.&initialize
-//Global Object for functions in subscribe method!
-def beaconHandler = this.&beaconHandler
-//Global Object for functions in subscribe method!
-def arriveActions = this.&arriveActions
-//Global Object for functions in subscribe method!
-def departActions = this.&departActions
-//Global Object for functions in subscribe method!
-def prefix = this.&prefix
-//Global Object for functions in subscribe method!
-def listPhrases = this.&listPhrases
-//Global Object for functions in subscribe method!
-def executePhrase = this.&executePhrase
-//Global Object for functions in subscribe method!
-def getBeaconName = this.&getBeaconName
-//Global Object for functions in subscribe method!
-def getPhoneName = this.&getPhoneName
-//Global Object for functions in subscribe method!
-def hideOptionsSection = this.&hideOptionsSection
-//Global Object for functions in subscribe method!
-def getAllOk = this.&getAllOk
-//Global Object for functions in subscribe method!
-def getModeOk = this.&getModeOk
-//Global Object for functions in subscribe method!
-def getDaysOk = this.&getDaysOk
-//Global Object for functions in subscribe method!
-def getTimeOk = this.&getTimeOk
-//Global Object for functions in subscribe method!
-def hhmm = this.&hhmm
-//Global Object for functions in subscribe method!
-def timeIntervalLabel = this.&timeIntervalLabel
-//Global Object for functions in subscribe method!
-def list = this.&list
diff --git a/Extractor/App2/extractedObjectsApp2.groovy b/Extractor/App2/extractedObjectsApp2.groovy
deleted file mode 100644
index 6f0f42e..0000000
--- a/Extractor/App2/extractedObjectsApp2.groovy
+++ /dev/null
@@ -1,32 +0,0 @@
-//Global variable for time!
-def starting = "15:00"
-//Global variable for time!
-def ending = "15:00"
-//Object for class beacon sensor!
-def beacons
-//Object for class mobile presence!
-def phones
-//Global variable for enum!
-def arrivalPhrase = "Good Night!"
-//Object for class switch!
-def arrivalOnSwitches
-//Object for class switch!
-def arrivalOffSwitches
-//Object for class lock!
-def arrivalLocks
-//Global variable for enum!
-def departPhrase = "Good Night!"
-//Object for class switch!
-def departOnSwitches
-//Object for class switch!
-def departOffSwitches
-//Object for class lock!
-def departLocks
-//Global variable for boolean!
-def pushNotification = "0"
-//Global variable for phone!
-def phone = 9495379373
-//Global variable for enum!
-def days = "Monday"
-//Global variable for mode!
-def modes = "night"
diff --git a/Extractor/App2/extractedObjectsConstructorApp2.groovy b/Extractor/App2/extractedObjectsConstructorApp2.groovy
deleted file mode 100644
index e10e014..0000000
--- a/Extractor/App2/extractedObjectsConstructorApp2.groovy
+++ /dev/null
@@ -1,10 +0,0 @@
-beacons = obj.beaconSensorObject
-phones = obj.mobilePresenceObject
-arrivalOnSwitches = obj.switchObject
-arrivalOffSwitches = obj.switchObject
-arrivalLocks = obj.lockObject
-departOnSwitches = obj.switchObject
-departOffSwitches = obj.switchObject
-departLocks = obj.lockObject
-//Global variable for settings!
-settings = [app:app, starting:starting, ending:ending, beacons:beacons, phones:phones, arrivalPhrase:arrivalPhrase, arrivalOnSwitches:arrivalOnSwitches, arrivalOffSwitches:arrivalOffSwitches, arrivalLocks:arrivalLocks, departPhrase:departPhrase, departOnSwitches:departOnSwitches, departOffSwitches:departOffSwitches, departLocks:departLocks, pushNotification:pushNotification, phone:phone, days:days, modes:modes]
diff --git a/Extractor/Extractor.groovy b/Extractor/Extractor.groovy
index 309223d..502fdc3 100644
--- a/Extractor/Extractor.groovy
+++ b/Extractor/Extractor.groovy
@@ -82,6 +82,8 @@ import Timer.SimulatedTimer
 @Field def log = new Logger()
 //Create a global variable for optional property
 @Field def optional = false //by default for now
+//Global Object for class AtomicState!
+@Field def atomicState = [history: "15:00"]
 
 
 //Global variables for files
@@ -348,6 +350,7 @@ def timeToday(String time, Object timeZone) {
 @Field boolVariable5
 
 
+
 /////Input Methods/////
 //input "",""
 def input(String name, String type) {
@@ -395,7 +398,7 @@ def input(LinkedHashMap metaData) {
 
 			lockObjects=lockObjects+1
 
-			settings.put(metaData['name'], metaData['name']) 
+			settings.put(metaData['name'], new Locks({}, 1)) 
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class lock!\n")
@@ -421,7 +424,7 @@ def input(LinkedHashMap metaData) {
 
 			alarmObjects=alarmObjects+1
 
-			settings.put(metaData['name'], metaData['name']) 
+			settings.put(metaData['name'], new Alarms({}, 1)) 
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class alarm!\n")
@@ -447,7 +450,7 @@ def input(LinkedHashMap metaData) {
 
 			batteryObjects=batteryObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new Batteries({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class Battery!\n")
@@ -473,7 +476,7 @@ def input(LinkedHashMap metaData) {
 
 			beaconSensorObjects=beaconSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new BeaconSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class beacon sensor!\n")
@@ -499,7 +502,7 @@ def input(LinkedHashMap metaData) {
 
 			carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new CarbonMonoxideDetectors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
@@ -525,7 +528,7 @@ def input(LinkedHashMap metaData) {
 
 			colorControlObjects=colorControlObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new ColorControls({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class color control!\n")
@@ -551,7 +554,7 @@ def input(LinkedHashMap metaData) {
 
 			contactObjects=contactObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new ContactSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class contactSensor!\n")
@@ -577,7 +580,7 @@ def input(LinkedHashMap metaData) {
 
 			doorControlObjects=doorControlObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new DoorControls({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class door control!\n")
@@ -603,7 +606,7 @@ def input(LinkedHashMap metaData) {
 
 			energyMeterObjects=energyMeterObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new EnergyMeters({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class energy meter!\n")
@@ -629,7 +632,7 @@ def input(LinkedHashMap metaData) {
 
 			illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new IlluminanceMeasurements({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
@@ -655,7 +658,7 @@ def input(LinkedHashMap metaData) {
 
 			accelerationSensorObjects=accelerationSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new AccelerationSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
@@ -681,7 +684,7 @@ def input(LinkedHashMap metaData) {
 
 			motionSensorObjects=motionSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new MotionSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class Motion Sensor!\n")
@@ -707,7 +710,7 @@ def input(LinkedHashMap metaData) {
 
 			musicPlayerObjects=musicPlayerObjects+1
 
-			settings.put(metaData['name'], metaData['name']) 
+			settings.put(metaData['name'], new MusicPlayers({}, 1)) 
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class music player!\n")
@@ -733,7 +736,7 @@ def input(LinkedHashMap metaData) {
 
 			powerMeterObjects=powerMeterObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new PowerMeters({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class power meter!\n")
@@ -759,7 +762,7 @@ def input(LinkedHashMap metaData) {
 
 			presenceSensorObjects=presenceSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new PresenceSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class presence sensor!\n")
@@ -785,7 +788,7 @@ def input(LinkedHashMap metaData) {
 
 			humidityMeasurementObjects=humidityMeasurementObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new RelativeHumidityMeasurements({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class humidity measurement!\n")
@@ -811,7 +814,7 @@ def input(LinkedHashMap metaData) {
 
 			relaySwitchObjects=relaySwitchObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new RelaySwitches({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class relay switch!\n")
@@ -837,7 +840,7 @@ def input(LinkedHashMap metaData) {
 
 			sleepSensorObjects=sleepSensorObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new SleepSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class sleep sensor!\n")
@@ -863,7 +866,7 @@ def input(LinkedHashMap metaData) {
 
 			smokeDetectorObjects=smokeDetectorObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new SmokeDetectors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class smoke detector!\n")
@@ -889,7 +892,7 @@ def input(LinkedHashMap metaData) {
 
 			stepSensorObjects=stepSensorObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new StepSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class step sensor!\n")
@@ -915,7 +918,7 @@ def input(LinkedHashMap metaData) {
 
 			switchObjects=switchObjects+1
 			
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new Switches({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class switch!\n")
@@ -941,7 +944,7 @@ def input(LinkedHashMap metaData) {
 
 			switchLevelObjects=switchLevelObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new SwitchLevels({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class switch level!\n")
@@ -967,7 +970,7 @@ def input(LinkedHashMap metaData) {
 
 			temperatureMeasurementObjects=temperatureMeasurementObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new TemperatureMeasurements({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class temperature measurement!\n")
@@ -993,7 +996,7 @@ def input(LinkedHashMap metaData) {
 
 			thermostatObjects=thermostatObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new Thermostats({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class thermostat!\n")
@@ -1019,7 +1022,7 @@ def input(LinkedHashMap metaData) {
 
 			valveObjects=valveObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new Valves({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class valve!\n")
@@ -1045,7 +1048,7 @@ def input(LinkedHashMap metaData) {
 
 			speechSynthesisObjects=speechSynthesisObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new SpeechSynthesises({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class speech synthesis!\n")
@@ -1071,7 +1074,7 @@ def input(LinkedHashMap metaData) {
 
 			waterSensorObjects=waterSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new WaterSensors({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class water sensor!\n")
@@ -1097,7 +1100,7 @@ def input(LinkedHashMap metaData) {
 
 			touchSensorObjects=touchSensorObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new NfcTouch({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
@@ -1123,7 +1126,7 @@ def input(LinkedHashMap metaData) {
 
 			imageCaptureObjects=imageCaptureObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new ImageCaptures({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class Image Capture!\n")
@@ -1149,7 +1152,7 @@ def input(LinkedHashMap metaData) {
 
 			mobilePresenceObjects=mobilePresenceObjects+1
 
-			settings.put(metaData['name'], metaData['name'])
+			settings.put(metaData['name'], new MobilePresences({}, 1))
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class mobile presence!\n")
@@ -1175,7 +1178,7 @@ def input(LinkedHashMap metaData) {
 
 			aeonKeyFobObjects=aeonKeyFobObjects+1
 
-			settings.put(metaData['name'], metaData['name']) 
+			settings.put(metaData['name'], new AeonKeyFobs({}, 1)) 
 
 			if (App == "App1") {
 				extractedObjectsApp1.append("//Object for class aeon key fob!\n")
@@ -1212,7 +1215,11 @@ def input(LinkedHashMap metaData) {
 				this[mode5] = userInput
 			}
 
-			modeVariables=modeVariables+1
+			if (modeVariables != 5)
+				modeVariables=modeVariables+1
+			else
+				modeVariables=0
+
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1247,7 +1254,10 @@ def input(LinkedHashMap metaData) {
 				this[decimal5] = userInput
 			}
 
-			decimalVariables=decimalVariables+1
+			if (decimalVariables != 5)
+				decimalVariables=decimalVariables+1
+			else
+				decimalVariables=0
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1282,7 +1292,11 @@ def input(LinkedHashMap metaData) {
 				this[text5] = userInput
 			}
 
-			textVariables=textVariables+1
+			if (textVariables != 5)
+				textVariables=textVariables+1
+			else
+				textVariables=0
+
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1317,7 +1331,12 @@ def input(LinkedHashMap metaData) {
 				this[number5] = userInput
 			}
 
-			numberVariables=numberVariables+1
+
+			if (numberVariables != 5)
+				numberVariables=numberVariables+1
+			else
+				numberVariables=0
+			
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1352,7 +1371,10 @@ def input(LinkedHashMap metaData) {
 				this[time5] = userInput
 			}
 
-			timeVariables=timeVariables+1
+			if (timeVariables != 5)
+				timeVariables=timeVariables+1
+			else
+				timeVariables=0
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1367,8 +1389,10 @@ def input(LinkedHashMap metaData) {
 		case "enum":
 			if (metaData['options'] != null)
 				modes = metaData['options']
-			else // If it is not named 'options' then it is captured as 'metadata'
+			else if (metaData['metadata'] != null) { // If it is not named 'options' then it is captured as 'metadata'
 				modes = metaData['metadata']
+				modes = modes['values']
+			}
 			def userInput = modes[0]
 	
 			if (enumVariables == 0) {
@@ -1391,7 +1415,11 @@ def input(LinkedHashMap metaData) {
 				this[enum5] = userInput
 			}
 
-			enumVariables=enumVariables+1
+			if (enumVariables != 5)
+				enumVariables=enumVariables+1
+			else
+				enumVariables=0			
+
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1426,7 +1454,11 @@ def input(LinkedHashMap metaData) {
 				this[bool5] = userInput
 			}
 
-			boolVariables=boolVariables+1
+			if (boolVariables != 5)
+				boolVariables=boolVariables+1
+			else
+				boolVariables=0
+
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1461,7 +1493,10 @@ def input(LinkedHashMap metaData) {
 				this[phone5] = userInput
 			}
 
-			phoneVariables=phoneVariables+1
+			if (phoneVariables != 5)
+				phoneVariables=phoneVariables+1
+			else
+				phoneVariables=0
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1496,7 +1531,10 @@ def input(LinkedHashMap metaData) {
 				this[contact5] = userInput
 			}
 
-			contactVariables=contactVariables+1
+			if (contactVariables != 5)
+				contactVariables=contactVariables+1
+			else
+				contactVariables=0
 
 			settings.put(metaData['name'], metaData['name'])
 
@@ -1552,12 +1590,27 @@ def definition(LinkedHashMap metaData) {
 
 def preferences(Closure inputData) {
 	find(inputData) //Run the closure to extract pages/sections/inputMethods
-	if (App == "App1") {			
+	settings.put("END", "END")
+	if (App == "App1") {		
 		extractedObjectsConstructorApp1.append("//Global variable for settings!\n")
-		extractedObjectsConstructorApp1.append("settings = $settings\n")
+		extractedObjectsConstructorApp1.append("settings = [")
+		settings.each{
+    			key, value ->
+			if (value != "END")
+				extractedObjectsConstructorApp1.append("$key: $key, ")
+			else
+				extractedObjectsConstructorApp1.append("END: \"END\"]\n")
+		}
 	} else {
 		extractedObjectsConstructorApp2.append("//Global variable for settings!\n")
-		extractedObjectsConstructorApp2.append("settings = $settings\n")
+		extractedObjectsConstructorApp2.append("settings = [")
+		settings.each{
+    			key, value ->
+			if (value != "END")
+				extractedObjectsConstructorApp2.append("$key: $key, ")
+			else
+				extractedObjectsConstructorApp2.append("END: \"END\"]\n")
+		}
 	}
 }
 
@@ -1601,6 +1654,10 @@ def section(LinkedHashMap metaData, Closure inputData) {
 	find(inputData) //Run the closure to extract inputMethods
 }
 
+def section(LinkedHashMap metaData, String data, Closure inputData) {
+	find(inputData)
+}
+
 def mappings(Closure inputData) {
 	println("//IGNORE--some data//")
 }
diff --git a/Extractor/extractorFile.groovy b/Extractor/extractorFile.groovy
deleted file mode 100644
index 3696113..0000000
--- a/Extractor/extractorFile.groovy
+++ /dev/null
@@ -1,1921 +0,0 @@
-////////////////////
-@Field App
-App = "App2"
-////////////////////////////////////////
-//import libraries
-import groovy.transform.Field
-
-
-//import classes
-//Importing Classes
-import ContactSensor.ContactSensor
-import ContactSensor.ContactSensors
-import DoorControl.DoorControl
-import DoorControl.DoorControls
-import Lock.Lock
-import Lock.Locks
-import Thermostat.Thermostat
-import Thermostat.Thermostats
-import Switch.Switch
-import Switch.Switches
-import PresenceSensor.PresenceSensor
-import PresenceSensor.PresenceSensors
-import Logger.Logger
-import Location.LocationVar
-import Location.Phrase
-import appTouch.Touched
-import NfcTouch.NfcTouch
-import AeonKeyFob.AeonKeyFob
-import AeonKeyFob.AeonKeyFobs
-import MusicPlayer.MusicPlayer
-import MusicPlayer.MusicPlayers
-import MotionSensor.MotionSensor
-import MotionSensor.MotionSensors
-import ImageCapture.ImageCapture
-import ImageCapture.ImageCaptures
-import SmokeDetector.SmokeDetector
-import SmokeDetector.SmokeDetectors
-import Alarm.Alarm
-import Alarm.Alarms
-import SpeechSynthesis.SpeechSynthesis
-import SpeechSynthesis.SpeechSynthesises
-import AccelerationSensor.AccelerationSensor
-import AccelerationSensor.AccelerationSensors
-import Battery.Battery
-import Battery.Batteries
-import BeaconSensor.BeaconSensor
-import BeaconSensor.BeaconSensors
-import CarbonMonoxideDetector.CarbonMonoxideDetector
-import CarbonMonoxideDetector.CarbonMonoxideDetectors
-import ColorControl.ColorControl
-import ColorControl.ColorControls
-import EnergyMeter.EnergyMeter
-import EnergyMeter.EnergyMeters
-import IlluminanceMeasurement.IlluminanceMeasurement
-import IlluminanceMeasurement.IlluminanceMeasurements
-import PowerMeter.PowerMeter
-import PowerMeter.PowerMeters
-import RelativeHumidityMeasurement.RelativeHumidityMeasurement
-import RelativeHumidityMeasurement.RelativeHumidityMeasurements
-import RelaySwitch.RelaySwitch
-import RelaySwitch.RelaySwitches
-import SleepSensor.SleepSensor
-import SleepSensor.SleepSensors
-import StepSensor.StepSensor
-import StepSensor.StepSensors
-import SwitchLevel.SwitchLevel
-import SwitchLevel.SwitchLevels
-import TemperatureMeasurement.TemperatureMeasurement
-import TemperatureMeasurement.TemperatureMeasurements
-import WaterSensor.WaterSensor
-import WaterSensor.WaterSensors
-import Valve.Valve
-import Valve.Valves
-import MobilePresence.MobilePresence
-import MobilePresence.MobilePresences
-import Timer.SimulatedTimer
-
-//GlobalVariables
-@Field def location = new LocationVar()
-//Settings variable defined to settings on purpose
-@Field def settings = [app: "app"]
-//Global variable for state[mode]
-@Field def state = [home:[],away:[],night:[]]
-//Create a global logger object for methods
-@Field def log = new Logger()
-//Create a global variable for optional property
-@Field def optional = false //by default for now
-
-
-//Global variables for files
-@Field File extractedObjectsApp1 = new File("Extractor/App1/extractedObjectsApp1.groovy")
-@Field File extractedObjectsApp2 = new File("Extractor/App2/extractedObjectsApp2.groovy")
-@Field File extractedObjectsConstructorApp1 = new File("Extractor/App1/extractedObjectsConstructorApp1.groovy")
-@Field File extractedObjectsConstructorApp2 = new File("Extractor/App2/extractedObjectsConstructorApp2.groovy")
-
-
-//Empty the files
-if (App == "App1") {
-	extractedObjectsApp1.write("")
-	extractedObjectsConstructorApp1.write("")
-} else if (App == "App2") {
-	extractedObjectsApp2.write("")
-	extractedObjectsConstructorApp2.write("")
-}
-
-
-
-//Some of methods-May be needed even in install
-/////////////////////////////////////////////////////////////////////
-def timeToday(String time, Object timeZone) {
-	def timeOfDay = new Date()
-	def _inputTime = time.split(':')
-	def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60+1564191100415
-	timeOfDay.time = inputTime
-	return timeOfDay
-}
-
-
-
-//Global objects
-//Global Object for class Touch Sensor!
-@Field touchSensorObjects = 0
-@Field def touchSensorObject0
-@Field def touchSensorObject1
-@Field def touchSensorObject2
-//Global Object for class switch!
-@Field switchObjects = 0
-@Field def switchObject0
-@Field def switchObject1
-@Field def switchObject2
-//Global Object for class lock!
-@Field lockObjects = 0
-@Field def lockObject0
-@Field def lockObject1
-@Field def lockObject2
-//Global Object for class door control!
-@Field doorControlObjects = 0
-@Field def doorControlObject0
-@Field def doorControlObject1
-@Field def doorControlObject2
-//Global Object for class contact sensor!
-@Field contactObjects = 0
-@Field def contactObject0
-@Field def contactObject1
-@Field def contactObject2
-//Global Object for class presence sensor!
-@Field presenceSensorObjects = 0
-@Field def presenceSensorObject0
-@Field def presenceSensorObject1
-@Field def presenceSensorObject2
-//Global Object for class thermostat!
-@Field thermostatObjects = 0
-@Field def thermostatObject0
-@Field def thermostatObject1
-@Field def thermostatObject2
-//Global Object for class music player!
-@Field musicPlayerObjects = 0
-@Field def musicPlayerObject0
-@Field def musicPlayerObject1
-@Field def musicPlayerObject2
-//Global Object for class aeon key fob!
-@Field aeonKeyFobObjects = 0
-@Field def aeonKeyFobObject0
-@Field def aeonKeyFobObject1
-@Field def aeonKeyFobObject2
-//Global Object for class motion sensor!
-@Field motionSensorObjects = 0
-@Field def motionSensorObject0
-@Field def motionSensorObject1
-@Field def motionSensorObject2
-//Global Object for class image capture!
-@Field imageCaptureObjects = 0
-@Field def imageCaptureObject0
-@Field def imageCaptureObject1
-@Field def imageCaptureObject2
-//Global Object for class smoke detector!
-@Field smokeDetectorObjects = 0
-@Field def smokeDetectorObject0
-@Field def smokeDetectorObject1
-@Field def smokeDetectorObject2
-//Global Object for class alarm!
-@Field alarmObjects = 0
-@Field def alarmObject0
-@Field def alarmObject1
-@Field def alarmObject2
-//Global Object for class speech synthesis!
-@Field speechSynthesisObjects = 0
-@Field def speechSynthesisObject0
-@Field def speechSynthesisObject1
-@Field def speechSynthesisObject2
-//Global Object for class acceleration sensor!
-@Field accelerationSensorObjects = 0
-@Field def accelerationSensorObject0
-@Field def accelerationSensorObject1
-@Field def accelerationSensorObject2
-//Global Object for class battery!
-@Field batteryObjects = 0
-@Field def batteryObject0
-@Field def batteryObject1
-@Field def batteryObject2
-//Global Object for class beacon sensor!
-@Field beaconSensorObjects = 0
-@Field def beaconSensorObject0
-@Field def beaconSensorObject1
-@Field def beaconSensorObject2
-//Global Object for class carbon monoxide detector!
-@Field carbonMonoxideDetectorObjects = 0
-@Field def carbonMonoxideDetectorObject0
-@Field def carbonMonoxideDetectorObject1
-@Field def carbonMonoxideDetectorObject2
-//Global Object for class color control!
-@Field colorControlObjects = 0
-@Field def colorControlObject0
-@Field def colorControlObject1
-@Field def colorControlObject2
-//Global Object for class energy meter!
-@Field energyMeterObjects = 0
-@Field def energyMeterObject0
-@Field def energyMeterObject1
-@Field def energyMeterObject2
-//Global Object for class energy meter!
-@Field illuminanceMeasurementObjects = 0
-@Field def illuminanceMeasurementObject0
-@Field def illuminanceMeasurementObject1
-@Field def illuminanceMeasurementObject2
-//Global Object for class power meter!
-@Field powerMeterObjects = 0
-@Field def powerMeterObject0
-@Field def powerMeterObject1
-@Field def powerMeterObject2
-//Global Object for class power meter!
-@Field humidityMeasurementObjects = 0
-@Field def humidityMeasurementObject0
-@Field def humidityMeasurementObject1
-@Field def humidityMeasurementObject2
-//Global Object for class relay switch!
-@Field relaySwitchObjects = 0
-@Field def relaySwitchObject0
-@Field def relaySwitchObject1
-@Field def relaySwitchObject2
-//Global Object for class sleep sensor!
-@Field sleepSensorObjects = 0
-@Field def sleepSensorObject0
-@Field def sleepSensorObject1
-@Field def sleepSensorObject2
-//Global Object for class sleep sensor!
-@Field stepSensorObjects = 0
-@Field def stepSensorObject0
-@Field def stepSensorObject1
-@Field def stepSensorObject2
-//Global Object for class switch level!
-@Field switchLevelObjects = 0
-@Field def switchLevelObject0
-@Field def switchLevelObject1
-@Field def switchLevelObject2
-//Global Object for class temperature measurement!
-@Field temperatureMeasurementObjects = 0
-@Field def temperatureMeasurementObject0
-@Field def temperatureMeasurementObject1
-@Field def temperatureMeasurementObject2
-//Global Object for class temperature measurement!
-@Field waterSensorObjects = 0
-@Field def waterSensorObject0
-@Field def waterSensorObject1
-@Field def waterSensorObject2
-//Global Object for class valve!
-@Field valveObjects = 0
-@Field def valveObject0
-@Field def valveObject1
-@Field def valveObject2
-//Global Object for class valve!
-@Field mobilePresenceObjects = 0
-@Field def mobilePresenceObject0
-@Field def mobilePresenceObject1
-@Field def mobilePresenceObject2
-
-
-
-//Global variables
-//For mode
-@Field modeVariables = 0
-@Field mode0
-@Field mode1
-@Field mode2
-@Field mode3
-@Field mode4
-@Field mode5
-//For number
-@Field numberVariables = 0
-@Field number0
-@Field number1
-@Field number2
-@Field number3
-@Field number4
-@Field number5
-//For decimal
-@Field decimalVariables = 0
-@Field decimal0
-@Field decimal1
-@Field decimal2
-@Field decimal3
-@Field decimal4
-@Field decimal5
-//For time
-@Field timeVariables = 0
-@Field time0
-@Field time1
-@Field time2
-@Field time3
-@Field time4
-@Field time5
-//For enum
-@Field enumVariables = 0
-@Field enum0
-@Field enum1
-@Field enum2
-@Field enum3
-@Field enum4
-@Field enum5
-//For phone
-@Field phoneVariables = 0
-@Field phone0
-@Field phone1
-@Field phone2
-@Field phone3
-@Field phone4
-@Field phone5
-//For contact
-@Field contactVariables = 0
-@Field contact0
-@Field contact1
-@Field contact2
-@Field contact3
-@Field contact4
-@Field contact5
-//For text
-@Field textVariables = 0
-@Field textVariable0
-@Field textVariable1
-@Field textVariable2
-@Field textVariable3
-@Field textVariable4
-@Field textVariable5
-//For boolean
-@Field boolVariables = 0
-@Field boolVariable0
-@Field boolVariable1
-@Field boolVariable2
-@Field boolVariable3
-@Field boolVariable4
-@Field boolVariable5
-
-
-/////Input Methods/////
-//input "",""
-def input(String name, String type) {
-	LinkedHashMap metaData = []
-	metaData.put('name',name)
-	metaData.put('type',type)
-	input(metaData)
-}
-
-//input "","",linkedHashMap
-def input(LinkedHashMap metaData, String name, String type) {
-	metaData.put('name',name)
-	metaData.put('type',type)
-	input(metaData)
-}
-
-//input "", "", linkedHashMap, Closure
-def input(LinkedHashMap metaData, String name, String type, Closure Input) {
-	metaData.put('name',name)
-	metaData.put('type',type)
-	input(metaData)
-	find(Input)
-}
-
-//input linkedHashMap
-def input(LinkedHashMap metaData) {
-	if (metaData.containsKey('title')) {
-		println metaData['title']
-	}
-	if (metaData.containsKey('options')) {
-		println "Options: "+metaData['options']
-	}
-	switch(metaData['type']) {
-		case "capability.lock":
-			if (lockObjects == 0) {
-				lockObject0 = metaData['name']
-				this[lockObject0] = new Locks({}, 1)
-			} else if (lockObjects == 1) {
-				lockObject1 = metaData['name']
-				this[lockObject1] = new Locks({}, 1)
-			} else if (lockObjects == 2) {
-				lockObject2 = metaData['name']
-				this[lockObject2] = new Locks({}, 1)
-			}
-
-			lockObjects=lockObjects+1
-
-			settings.put(metaData['name'], metaData['name']) 
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class lock!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.lockObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class lock!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.lockObject\n")
-			}
-			break
-		case "capability.alarm":
-			if (alarmObjects == 0) {
-				alarmObject0 = metaData['name']
-				this[alarmObject0] = new Alarms({}, 1)
-			} else if (alarmObjects == 1) {
-				alarmObject1 = metaData['name']
-				this[alarmObject1] = new Alarms({}, 1)
-			} else if (alarmObjects == 2) {
-				alarmObject2 = metaData['name']
-				this[alarmObject2] = new Alarms({}, 1)
-			}
-
-			alarmObjects=alarmObjects+1
-
-			settings.put(metaData['name'], metaData['name']) 
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class alarm!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.alarmObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class alarm!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.alarmObject\n")
-			}
-			break
-		case "capability.battery":
-			if (batteryObjects == 0) {
-				batteryObject0 = metaData['name']
-				this[batteryObject0] = new Batteries({}, 1)
-			} else if (batteryObjects == 1) {
-				batteryObject1 = metaData['name']
-				this[batteryObject1] = new Batteries({}, 1)
-			} else if (batteryObjects == 2) {
-				batteryObject2 = metaData['name']
-				this[batteryObject2] = new Batteries({}, 1)
-			}
-
-			batteryObjects=batteryObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class Battery!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.batteryObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class Battery!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.batteryObject\n")
-			}
-			break
-		case "capability.beacon":
-			if (beaconSensorObjects == 0) {
-				beaconSensorObject0 = metaData['name']
-				this[beaconSensorObject0] = new BeaconSensors({}, 1)
-			} else if (beaconSensorObjects == 1) {
-				beaconSensorObject1 = metaData['name']
-				this[beaconSensorObject1] = new BeaconSensors({}, 1)
-			} else if (beaconSensorObjects == 2) {
-				beaconSensorObject2 = metaData['name']
-				this[beaconSensorObject2] = new BeaconSensors({}, 1)
-			}
-
-			beaconSensorObjects=beaconSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class beacon sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.beaconSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class beacon sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.beaconSensorObject\n")
-			}
-			break
-		case "capability.carbonMonoxideDetector":
-			if (carbonMonoxideDetectorObjects == 0) {
-				carbonMonoxideDetectorObject0 = metaData['name']
-				this[carbonMonoxideDetectorObject0] = new CarbonMonoxideDetectors({}, 1)
-			} else if (carbonMonoxideDetectorObjects == 1) {
-				carbonMonoxideDetectorObject1 = metaData['name']
-				this[carbonMonoxideDetectorObject1] = new CarbonMonoxideDetectors({}, 1)
-			} else if (carbonMonoxideDetectorObjects == 2) {
-				carbonMonoxideDetectorObject2 = metaData['name']
-				this[carbonMonoxideDetectorObject2] = new CarbonMonoxideDetectors({}, 1)
-			}
-
-			carbonMonoxideDetectorObjects=carbonMonoxideDetectorObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class carbon monoxide detector!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class carbon monoxide detector!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.carbonMonoxideDetectorObject\n")
-			}
-			break
-		case "capability.colorControl":
-			if (colorControlObjects == 0) {
-				colorControlObject0 = metaData['name']
-				this[colorControlObject0] = new ColorControls({}, 1)
-			} else if (colorControlObjects == 1) {
-				colorControlObject1 = metaData['name']
-				this[colorControlObject1] = new ColorControls({}, 1)
-			} else if (colorControlObjects == 2) {
-				colorControlObject2 = metaData['name']
-				this[colorControlObject2] = new ColorControls({}, 1)
-			}
-
-			colorControlObjects=colorControlObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class color control!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.colorControlObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class color control!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.colorControlObject\n")
-			}
-			break
-		case "capability.contactSensor":
-			if (contactObjects == 0) {
-				contactObject0 = metaData['name']
-				this[contactObject0] = new ContactSensors({}, 1)
-			} else if (contactObjects == 1) {
-				contactObject1 = metaData['name']
-				this[contactObject1] = new ContactSensors({}, 1)
-			} else if (contactObjects == 2) {
-				contactObject2 = metaData['name']
-				this[contactObject2] = new ContactSensors({}, 1)
-			}
-
-			contactObjects=contactObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class contactSensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.contactObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class contactSensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.contactObject\n")
-			}
-			break
-		case "capability.doorControl":
-			if (doorControlObjects == 0) {
-				doorControlObject0 = metaData['name']
-				this[doorControlObject0] = new DoorControls({}, 1)
-			} else if (doorControlObjects == 1) {
-				doorControlObject1 = metaData['name']
-				this[doorControlObject1] = new DoorControls({}, 1)
-			} else if (doorControlObjects == 2) {
-				doorControlObject2 = metaData['name']
-				this[doorControlObject2] = new DoorControls({}, 1)
-			}
-
-			doorControlObjects=doorControlObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class door control!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.doorControlObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class door control!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.doorControlObject\n")
-			}
-			break
-		case "capability.energyMeter":
-			if (energyMeterObjects == 0) {
-				energyMeterObject0 = metaData['name']
-				this[energyMeterObject0] = new EnergyMeters({}, 1)
-			} else if (energyMeterObjects == 1) {
-				energyMeterObject1 = metaData['name']
-				this[energyMeterObject1] = new EnergyMeters({}, 1)
-			} else if (energyMeterObjects == 2) {
-				energyMeterObject2 = metaData['name']
-				this[energyMeterObject2] = new EnergyMeters({}, 1)
-			}
-
-			energyMeterObjects=energyMeterObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class energy meter!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.energyMeterObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class energy meter!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.energyMeterObject\n")
-			}
-			break
-		case "capability.illuminanceMeasurement":
-			if (illuminanceMeasurementObjects == 0) {
-				illuminanceMeasurementObject0 = metaData['name']
-				this[illuminanceMeasurementObject0] = new IlluminanceMeasurements({}, 1)
-			} else if (illuminanceMeasurementObjects == 1) {
-				illuminanceMeasurementObject1 = metaData['name']
-				this[illuminanceMeasurementObject1] = new IlluminanceMeasurements({}, 1)
-			} else if (illuminanceMeasurementObjects == 2) {
-				illuminanceMeasurementObject2 = metaData['name']
-				this[illuminanceMeasurementObject2] = new IlluminanceMeasurements({}, 1)
-			}
-
-			illuminanceMeasurementObjects=illuminanceMeasurementObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class illuminance measurement!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class illuminance measurement!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.illuminanceMeasurementObject\n")
-			}
-			break
-		case "capability.accelerationSensor":
-			if (accelerationSensorObjects == 0) {
-				accelerationSensorObject0 = metaData['name']
-				this[accelerationSensorObject0] = new AccelerationSensors({}, 1)
-			} else if (accelerationSensorObjects == 1) {
-				accelerationSensorObject1 = metaData['name']
-				this[accelerationSensorObject1] = new AccelerationSensors({}, 1)
-			} else if (accelerationSensorObjects == 2) {
-				accelerationSensorObject2 = metaData['name']
-				this[accelerationSensorObject2] = new AccelerationSensors({}, 1)
-			}
-
-			accelerationSensorObjects=accelerationSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class Acceleration Sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.accelerationSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class Acceleration Sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.accelerationSensorObject\n")
-			}
-			break
-		case "capability.motionSensor":
-			if (motionSensorObjects == 0) {
-				motionSensorObject0 = metaData['name']
-				this[motionSensorObject0] = new MotionSensors({}, 1)
-			} else if (motionSensorObjects == 1) {
-				motionSensorObject1 = metaData['name']
-				this[motionSensorObject1] = new MotionSensors({}, 1)
-			} else if (motionSensorObjects == 2) {
-				motionSensorObject2 = metaData['name']
-				this[motionSensorObject2] = new MotionSensors({}, 1)
-			}
-
-			motionSensorObjects=motionSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class Motion Sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.motionSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class Motion Sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.motionSensorObject\n")
-			}
-			break
-		case "capability.musicPlayer":
-			if (musicPlayerObjects == 0) {
-				musicPlayerObject0 = metaData['name']
-				this[musicPlayerObject0] = new MusicPlayers({}, 1)
-			} else if (musicPlayerObjects == 1) {
-				musicPlayerObject1 = metaData['name']
-				this[musicPlayerObject1] = new MusicPlayers({}, 1)
-			} else if (musicPlayerObjects == 2) {
-				musicPlayerObject2 = metaData['name']
-				this[musicPlayerObject2] = new MusicPlayers({}, 1)
-			}
-
-			musicPlayerObjects=musicPlayerObjects+1
-
-			settings.put(metaData['name'], metaData['name']) 
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class music player!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.musicPlayerObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class music player!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.musicPlayerObject\n")
-			}
-			break
-		case "capability.powerMeter":
-			if (powerMeterObjects == 0) {
-				powerMeterObject0 = metaData['name']
-				this[powerMeterObject0] = new PowerMeters({}, 1)
-			} else if (powerMeterObjects == 1) {
-				powerMeterObject1 = metaData['name']
-				this[powerMeterObject1] = new PowerMeters({}, 1)
-			} else if (powerMeterObjects == 2) {
-				powerMeterObject2 = metaData['name']
-				this[powerMeterObject2] = new PowerMeters({}, 1)
-			}
-
-			powerMeterObjects=powerMeterObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class power meter!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.powerMeterObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class power meter!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.powerMeterObject\n")
-			}
-			break
-		case "capability.presenceSensor":
-			if (presenceSensorObjects == 0) {
-				presenceSensorObject0 = metaData['name']
-				this[presenceSensorObject0] = new PresenceSensors({}, 1)
-			} else if (presenceSensorObjects == 1) {
-				presenceSensorObject1 = metaData['name']
-				this[presenceSensorObject1] = new PresenceSensors({}, 1)
-			} else if (presenceSensorObjects == 2) {
-				presenceSensorObject2 = metaData['name']
-				this[presenceSensorObject2] = new PresenceSensors({}, 1)
-			}
-
-			presenceSensorObjects=presenceSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class presence sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.presenceSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class presence sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.presenceSensorObject\n")
-			}
-			break
-		case "capability.relativeHumidityMeasurement":
-			if (humidityMeasurementObjects == 0) {
-				humidityMeasurementObject0 = metaData['name']
-				this[humidityMeasurementObject0] = new RelativeHumidityMeasurements({}, 1)
-			} else if (humidityMeasurementObjects == 1) {
-				humidityMeasurementObject1 = metaData['name']
-				this[humidityMeasurementObject1] = new RelativeHumidityMeasurements({}, 1)
-			} else if (humidityMeasurementObjects == 2) {
-				humidityMeasurementObject2 = metaData['name']
-				this[humidityMeasurementObject2] = new RelativeHumidityMeasurements({}, 1)
-			}
-
-			humidityMeasurementObjects=humidityMeasurementObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class humidity measurement!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.humidityMeasurementObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class humidity measurement!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.humidityMeasurementObject\n")
-			}
-			break
-		case "capability.relaySwitch":
-			if (relaySwitchObjects == 0) {
-				relaySwitchObject0 = metaData['name']
-				this[relaySwitchObject0] = new RelaySwitches({}, 1)
-			} else if (relaySwitchObjects == 1) {
-				relaySwitchObject1 = metaData['name']
-				this[relaySwitchObject1] = new RelaySwitches({}, 1)
-			} else if (relaySwitchObjects == 2) {
-				relaySwitchObject2 = metaData['name']
-				this[relaySwitchObject2] = new RelaySwitches({}, 1)
-			}
-
-			relaySwitchObjects=relaySwitchObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class relay switch!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.relaySwitchObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class relay switch!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.relaySwitchObject\n")
-			}
-			break
-		case "capability.sleepSensor":
-			if (sleepSensorObjects == 0) {
-				sleepSensorObject0 = metaData['name']
-				this[sleepSensorObject0] = new SleepSensors({}, 1)
-			} else if (sleepSensorObjects == 1) {
-				sleepSensorObject1 = metaData['name']
-				this[sleepSensorObject1] = new SleepSensors({}, 1)
-			} else if (sleepSensorObjects == 2) {
-				sleepSensorObject2 = metaData['name']
-				this[sleepSensorObject2] = new SleepSensors({}, 1)
-			}
-
-			sleepSensorObjects=sleepSensorObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class sleep sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.sleepSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class sleep sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.sleepSensorObject\n")
-			}
-			break
-		case "capability.smokeDetector":
-			if (smokeDetectorObjects == 0) {
-				smokeDetectorObject0 = metaData['name']
-				this[smokeDetectorObject0] = new SmokeDetectors({}, 1)
-			} else if (smokeDetectorObjects == 1) {
-				smokeDetectorObject1 = metaData['name']
-				this[smokeDetectorObject1] = new SmokeDetectors({}, 1)
-			} else if (smokeDetectorObjects == 2) {
-				smokeDetectorObject2 = metaData['name']
-				this[smokeDetectorObject2] = new SmokeDetectors({}, 1)
-			}
-
-			smokeDetectorObjects=smokeDetectorObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class smoke detector!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.smokeDetectorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class smoke detector!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.smokeDetectorObject\n")
-			}
-			break
-		case "capability.stepSensor":
-			if (stepSensorObjects == 0) {
-				stepSensorObject0 = metaData['name']
-				this[stepSensorObject0] = new StepSensors({}, 1)
-			} else if (stepSensorObjects == 1) {
-				stepSensorObject1 = metaData['name']
-				this[stepSensorObject1] = new StepSensors({}, 1)
-			} else if (stepSensorObjects == 2) {
-				stepSensorObject2 = metaData['name']
-				this[stepSensorObject2] = new StepSensors({}, 1)
-			}
-
-			stepSensorObjects=stepSensorObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class step sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.stepSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class step sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.stepSensorObject\n")
-			}
-			break
-		case "capability.switch":
-			if (switchObjects == 0) {
-				switchObject0 = metaData['name']
-				this[switchObject0] = new Switches({}, 1)
-			} else if (switchObjects == 1) {
-				switchObject1 = metaData['name']
-				this[switchObject1] = new Switches({}, 1)
-			} else if (switchObjects == 2) {
-				switchObject2 = metaData['name']
-				this[switchObject2] = new Switches({}, 1)
-			}
-
-			switchObjects=switchObjects+1
-			
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class switch!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class switch!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchObject\n")
-			}
-			break
-		case "capability.switchLevel":
-			if (switchLevelObjects == 0) {
-				switchLevelObject0 = metaData['name']
-				this[switchLevelObject0] = new SwitchLevels({}, 1)
-			} else if (switchLevelObjects == 1) {
-				switchLevelObject1 = metaData['name']
-				this[switchLevelObject1] = new SwitchLevels({}, 1)
-			} else if (switchLevelObjects == 2) {
-				switchLevelObject2 = metaData['name']
-				this[switchLevelObject2] = new SwitchLevels({}, 1)
-			}
-
-			switchLevelObjects=switchLevelObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class switch level!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.switchLevelObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class switch level!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.switchLevelObject\n")
-			}
-			break
-		case "capability.temperatureMeasurement":
-			if (temperatureMeasurementObjects == 0) {
-				temperatureMeasurementObject0 = metaData['name']
-				this[temperatureMeasurementObject0] = new TemperatureMeasurements({}, 1)
-			} else if (temperatureMeasurementObjects == 1) {
-				temperatureMeasurementObject1 = metaData['name']
-				this[temperatureMeasurementObject1] = new TemperatureMeasurements({}, 1)
-			} else if (temperatureMeasurementObjects == 2) {
-				temperatureMeasurementObject2 = metaData['name']
-				this[temperatureMeasurementObject2] = new TemperatureMeasurements({}, 1)
-			}
-
-			temperatureMeasurementObjects=temperatureMeasurementObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class temperature measurement!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.temperatureMeasurementObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class temperature measurement!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.temperatureMeasurementObject\n")
-			}
-			break
-		case "capability.thermostat":
-			if (thermostatObjects == 0) {
-				thermostatObject0 = metaData['name']
-				this[thermostatObject0] = new Thermostats({}, 1)
-			} else if (thermostatObjects == 1) {
-				thermostatObject1 = metaData['name']
-				this[thermostatObject1] = new Thermostats({}, 1)
-			} else if (thermostatObjects == 2) {
-				thermostatObject2 = metaData['name']
-				this[thermostatObject2] = new Thermostats({}, 1)
-			}
-
-			thermostatObjects=thermostatObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class thermostat!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.thermostatObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class thermostat!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.thermostatObject\n")
-			}
-			break
-		case "capability.valve":
-			if (valveObjects == 0) {
-				valveObject0 = metaData['name']
-				this[valveObject0] = new Valves({}, 1)
-			} else if (valveObjects == 1) {
-				valveObject1 = metaData['name']
-				this[valveObject1] = new Valves({}, 1)
-			} else if (valveObjects == 2) {
-				valveObject2 = metaData['name']
-				this[valveObject2] = new Valves({}, 1)
-			}
-
-			valveObjects=valveObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class valve!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.valveObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class valve!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.valveObject\n")
-			}
-			break
-		case "capability.speechSynthesis":
-			if (speechSynthesisObjects == 0) {
-				speechSynthesisObject0 = metaData['name']
-				this[speechSynthesisObject0] = new SpeechSynthesises({}, 1)
-			} else if (speechSynthesisObjects == 1) {
-				speechSynthesisObject1 = metaData['name']
-				this[speechSynthesisObject1] = new SpeechSynthesises({}, 1)
-			} else if (speechSynthesisObjects == 2) {
-				speechSynthesisObject2 = metaData['name']
-				this[speechSynthesisObject2] = new SpeechSynthesises({}, 1)
-			}
-
-			speechSynthesisObjects=speechSynthesisObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class speech synthesis!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.speechSynthesisObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class speech synthesis!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.speechSynthesisObject\n")
-			}
-			break
-		case "capability.waterSensor":
-			if (waterSensorObjects == 0) {
-				waterSensorObject0 = metaData['name']
-				this[waterSensorObject0] = new WaterSensors({}, 1)
-			} else if (waterSensorObjects == 1) {
-				waterSensorObject1 = metaData['name']
-				this[waterSensorObject1] = new WaterSensors({}, 1)
-			} else if (waterSensorObjects == 2) {
-				waterSensorObject2 = metaData['name']
-				this[waterSensorObject2] = new WaterSensors({}, 1)
-			}
-
-			waterSensorObjects=waterSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class water sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.waterSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class water sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.waterSensorObject\n")
-			}
-			break
-		case "capability.touchSensor":
-			if (touchSensorObjects == 0) {
-				touchSensorObject0 = metaData['name']
-				this[touchSensorObject0] = new NfcTouch({}, 1)
-			} else if (touchSensorObjects == 1) {
-				touchSensorObject1 = metaData['name']
-				this[touchSensorObject1] = new NfcTouch({}, 1)
-			} else if (touchSensorObjects == 2) {
-				touchSensorObject2 = metaData['name']
-				this[touchSensorObject2] = new NfcTouch({}, 1)
-			}
-
-			touchSensorObjects=touchSensorObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class Touch Sensor!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.touchSensorObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class Touch Sensor!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.touchSensorObject\n")
-			}
-			break
-		case "capability.imageCapture":
-			if (imageCaptureObjects == 0) {
-				imageCaptureObject0 = metaData['name']
-				this[imageCaptureObject0] = new ImageCaptures({}, 1)
-			} else if (imageCaptureObjects == 1) {
-				imageCaptureObject1 = metaData['name']
-				this[imageCaptureObject1] = new ImageCaptures({}, 1)
-			} else if (imageCaptureObjects == 2) {
-				imageCaptureObject2 = metaData['name']
-				this[imageCaptureObject2] = new ImageCaptures({}, 1)
-			}
-
-			imageCaptureObjects=imageCaptureObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class Image Capture!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.imageCaptureObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class Image Capture!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.imageCaptureObject\n")
-			}
-			break
-		case "device.mobilePresence":
-			if (mobilePresenceObjects == 0) {
-				mobilePresenceObject0 = metaData['name']
-				this[mobilePresenceObject0] = new MobilePresences({}, 1)
-			} else if (mobilePresenceObjects == 1) {
-				mobilePresenceObject1 = metaData['name']
-				this[mobilePresenceObject1] = new MobilePresences({}, 1)
-			} else if (mobilePresenceObjects == 2) {
-				mobilePresenceObject2 = metaData['name']
-				this[mobilePresenceObject2] = new MobilePresences({}, 1)
-			}
-
-			mobilePresenceObjects=mobilePresenceObjects+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class mobile presence!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.mobilePresenceObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class mobile presence!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.mobilePresenceObject\n")
-			}
-			break
-		case "device.aeonKeyFob":
-			if (aeonKeyFobObjects == 0) {
-				aeonKeyFobObject0 = metaData['name']
-				this[aeonKeyFobObject0] = new AeonKeyFobs({}, 1)
-			} else if (aeonKeyFobObjects == 1) {
-				aeonKeyFobObject1 = metaData['name']
-				this[aeonKeyFobObject1] = new AeonKeyFobs({}, 1)
-			} else if (aeonKeyFobObjects == 2) {
-				aeonKeyFobObject2 = metaData['name']
-				this[aeonKeyFobObject2] = new AeonKeyFobs({}, 1)
-			}
-
-			aeonKeyFobObjects=aeonKeyFobObjects+1
-
-			settings.put(metaData['name'], metaData['name']) 
-
-			if (App == "App1") {
-				extractedObjectsApp1.append("//Object for class aeon key fob!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp1.append(metaData['name']+" = obj.aeonKeyFobObject\n")		
-			} else {
-				extractedObjectsApp2.append("//Object for class aeon key fob!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+"\n")
-				extractedObjectsConstructorApp2.append(metaData['name']+" = obj.aeonKeyFobObject\n")
-			}
-			break
-		case "mode":
-			def randomVariable = Math.abs(new Random().nextInt() % 3)
-			def modes = ["away", "home", "night"]
-			def userInput = modes[randomVariable]
-
-			if (modeVariables == 0) {
-				mode0 = metaData['name']
-				this[mode0] = userInput
-			} else if (modeVariables == 1) {
-				mode1 = metaData['name']
-				this[mode1] = userInput
-			} else if (modeVariables == 2) {
-				mode2 = metaData['name']
-				this[mode2] = userInput
-			} else if (modeVariables == 3) {
-				mode3 = metaData['name']
-				this[mode3] = userInput
-			} else if (modeVariables == 4) {
-				mode4 = metaData['name']
-				this[mode4] = userInput
-			} else if (modeVariables == 5) {
-				mode5 = metaData['name']
-				this[mode5] = userInput
-			}
-
-			modeVariables=modeVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for mode!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for mode!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		case "decimal":
-			def userInput = Math.abs(new Random().nextInt() % 60) + 40
-			
-			if (decimalVariables == 0) {
-				decimal0 = metaData['name']
-				this[decimal0] = userInput
-			} else if (decimalVariables == 1) {
-				decimal1 = metaData['name']
-				this[decimal1] = userInput
-			} else if (decimalVariables == 2) {
-				decimal2 = metaData['name']
-				this[decimal2] = userInput
-			} else if (decimalVariables == 3) {
-				decimal3 = metaData['name']
-				this[decimal3] = userInput
-			} else if (decimalVariables == 4) {
-				decimal4 = metaData['name']
-				this[decimal4] = userInput
-			} else if (decimalVariables == 5) {
-				decimal5 = metaData['name']
-				this[decimal5] = userInput
-			}
-
-			decimalVariables=decimalVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for decimal number!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for decimal number!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
-			}
-			break
-		case "text":
-			def userInput = "This is just a text!"
-	
-			if (textVariables == 0) {
-				text0 = metaData['name']
-				this[text0] = userInput
-			} else if (textVariables == 1) {
-				text1 = metaData['name']
-				this[text1] = userInput
-			} else if (textVariables == 2) {
-				text2 = metaData['name']
-				this[text2] = userInput
-			} else if (textVariables == 3) {
-				text3 = metaData['name']
-				this[text3] = userInput
-			} else if (textVariables == 4) {
-				text4 = metaData['name']
-				this[text4] = userInput
-			} else if (textVariables == 5) {
-				text5 = metaData['name']
-				this[text5] = userInput
-			}
-
-			textVariables=textVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for text!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for text!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		case "number":
-			def userInput = Math.abs(new Random().nextInt() % 60) + 40
-			
-			if (numberVariables == 0) {
-				number0 = metaData['name']
-				this[number0] = userInput
-			} else if (numberVariables == 1) {
-				number1 = metaData['name']
-				this[number1] = userInput
-			} else if (numberVariables == 2) {
-				number2 = metaData['name']
-				this[number2] = userInput
-			} else if (numberVariables == 3) {
-				number3 = metaData['name']
-				this[number3] = userInput
-			} else if (numberVariables == 4) {
-				number4 = metaData['name']
-				this[number4] = userInput
-			} else if (numberVariables == 5) {
-				number5 = metaData['name']
-				this[number5] = userInput
-			}
-
-			numberVariables=numberVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for number!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for number!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
-			}
-			break
-		case "time":
-			def userInput = "15:00"
-			
-			if (timeVariables == 0) {
-				time0 = metaData['name']
-				this[time0] = userInput
-			} else if (timeVariables == 1) {
-				time1 = metaData['name']
-				this[time1] = userInput
-			} else if (timeVariables == 2) {
-				time2 = metaData['name']
-				this[time2] = userInput
-			} else if (timeVariables == 3) {
-				time3 = metaData['name']
-				this[time3] = userInput
-			} else if (timeVariables == 4) {
-				time4 = metaData['name']
-				this[time4] = userInput
-			} else if (timeVariables == 5) {
-				time5 = metaData['name']
-				this[time5] = userInput
-			}
-
-			timeVariables=timeVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for time!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for time!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		case "enum":
-			if (metaData['options'] != null)
-				modes = metaData['options']
-			else // If it is not named 'options' then it is captured as 'metadata'
-				modes = metaData['metadata']
-			def userInput = modes[0]
-	
-			if (enumVariables == 0) {
-				enum0 = metaData['name']
-				this[enum0] = userInput
-			} else if (enumVariables == 1) {
-				enum1 = metaData['name']
-				this[enum1] = userInput
-			} else if (enumVariables == 2) {
-				enum2 = metaData['name']
-				this[enum2] = userInput
-			} else if (enumVariables == 3) {
-				enum3 = metaData['name']
-				this[enum3] = userInput
-			} else if (enumVariables == 4) {
-				enum4 = metaData['name']
-				this[enum4] = userInput
-			} else if (enumVariables == 5) {
-				enum5 = metaData['name']
-				this[enum5] = userInput
-			}
-
-			enumVariables=enumVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for enum!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for enum!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		case "bool":
-			def userInput = Math.abs(new Random().nextInt() % 2)
-	
-			if (boolVariables == 0) {
-				bool0 = metaData['name']
-				this[bool0] = userInput
-			} else if (boolVariables == 1) {
-				bool1 = metaData['name']
-				this[bool1] = userInput
-			} else if (boolVariables == 2) {
-				bool2 = metaData['name']
-				this[bool2] = userInput
-			} else if (boolVariables == 3) {
-				bool3 = metaData['name']
-				this[bool3] = userInput
-			} else if (boolVariables == 4) {
-				bool4 = metaData['name']
-				this[bool4] = userInput
-			} else if (boolVariables == 5) {
-				bool5 = metaData['name']
-				this[bool5] = userInput
-			}
-
-			boolVariables=boolVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for boolean!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for boolean!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		case "phone":
-			def userInput = 9495379373
-
-			if (phoneVariables == 0) {
-				phone0 = metaData['name']
-				this[phone0] = userInput
-			} else if (phoneVariables == 1) {
-				phone1 = metaData['name']
-				this[phone1] = userInput
-			} else if (phoneVariables == 2) {
-				phone2 = metaData['name']
-				this[phone2] = userInput
-			} else if (phoneVariables == 3) {
-				phone3 = metaData['name']
-				this[phone3] = userInput
-			} else if (phoneVariables == 4) {
-				phone4 = metaData['name']
-				this[phone4] = userInput
-			} else if (phoneVariables == 5) {
-				phone5 = metaData['name']
-				this[phone5] = userInput
-			}
-
-			phoneVariables=phoneVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for phone!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = "+userInput+"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for phone!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = "+userInput+"\n")
-			}
-			break
-		case "contact":
-			def userInput = "AJ"
-	
-			if (contactVariables == 0) {
-				contact0 = metaData['name']
-				this[contact0] = userInput
-			} else if (contactVariables == 1) {
-				contact1 = metaData['name']
-				this[contact1] = userInput
-			} else if (contactVariables == 2) {
-				contact2 = metaData['name']
-				this[contact2] = userInput
-			} else if (contactVariables == 3) {
-				contact3 = metaData['name']
-				this[contact3] = userInput
-			} else if (contactVariables == 4) {
-				contact4 = metaData['name']
-				this[contact4] = userInput
-			} else if (contactVariables == 5) {
-				contact5 = metaData['name']
-				this[contact5] = userInput
-			}
-
-			contactVariables=contactVariables+1
-
-			settings.put(metaData['name'], metaData['name'])
-
-			if (App == "App1") {			
-				extractedObjectsApp1.append("//Global variable for contact!\n")
-				extractedObjectsApp1.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			} else {
-				extractedObjectsApp2.append("//Global variable for contact!\n")
-				extractedObjectsApp2.append("def "+metaData['name']+" = \""+userInput+"\"\n")
-			}
-			break
-		default:
-			break
-	}
-}
-
-def label(LinkedHashMap metaData) {
-	if (metaData.containsKey('title')) {
-		println metaData['title']
-	}
-	if (metaData.containsKey('options')) {
-		println "Options: "+metaData['options']
-	}
-
-	println("//IGNORE--ForMobileUse//")
-}
-
-def mode(LinkedHashMap metaData) {
-	if (metaData.containsKey('title')) {
-		println metaData['title']
-	}
-	if (metaData.containsKey('options')) {
-		println "Options: "+metaData['options']
-	}
-
-	println("//IGNORE--ForMobileUse//")
-}
-
-def href(LinkedHashMap metaData) {
-	println("//IGNORE--some data//")
-}
-
-def href(LinkedHashMap metaData, String name) {
-	println("//IGNORE--some data//")
-}
-/////Input Methods/////
-
-
-/////MethodsForExtraction/////
-def definition(LinkedHashMap metaData) {
-	println("///Just some information///")
-}
-
-def preferences(Closure inputData) {
-	find(inputData) //Run the closure to extract pages/sections/inputMethods
-	if (App == "App1") {			
-		extractedObjectsConstructorApp1.append("//Global variable for settings!\n")
-		extractedObjectsConstructorApp1.append("settings = $settings\n")
-	} else {
-		extractedObjectsConstructorApp2.append("//Global variable for settings!\n")
-		extractedObjectsConstructorApp2.append("settings = $settings\n")
-	}
-}
-
-def page(LinkedHashMap metaData, Closure inputData) {
-	if (metaData.containsKey('name'))
-		println(metaData['name'])
-	if (metaData.containsKey('title'))
-		println(metaData['title'])
-
-	find(inputData) //Run the closure to extract sections/inputMethods
-}
-
-def page(LinkedHashMap metaData) {
-	def nameOfFunction = metaData['name']
-	"$nameOfFunction"() //Call the page	
-}
-
-def dynamicPage(LinkedHashMap metaData, Closure inputData) {
-	if (metaData.containsKey('name'))
-		println(metaData['name'])
-	if (metaData.containsKey('title'))
-		println(metaData['title'])
-
-	find(inputData) //Run the closure to extract sections/inputMethods
-}
-
-def paragraph(String paragraphText) {
-	println(paragraphText)
-}
-
-def section(String title, Closure inputData) {
-	println(title)
-	find(inputData) //Run the closure to extract inputMethods
-}
-
-def section(Closure inputData) {
-	find(inputData) //Run the closure to extract inputMethods
-}
-
-def section(LinkedHashMap metaData, Closure inputData) {
-	find(inputData) //Run the closure to extract inputMethods
-}
-
-def mappings(Closure inputData) {
-	println("//IGNORE--some data//")
-}
-/////MethodsForExtraction/////
-
-
-
-/**
- *  Beacon Control
- *
- *  Copyright 2014 Physical Graph Corporation
- *
- *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
- *  in compliance with the License. You may obtain a copy of the License at:
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
- *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
- *  for the specific language governing permissions and limitations under the License.
- *
- */
-definition(
-	name: "Beacon Control",
-	category: "SmartThings Internal",
-	namespace: "smartthings",
-	author: "SmartThings",
-	description: "Execute a Hello, Home phrase, turn on or off some lights, and/or lock or unlock your door when you enter or leave a monitored region",
-	iconUrl: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol.png",
-	iconX2Url: "https://s3.amazonaws.com/smartapp-icons/MiscHacking/mindcontrol@2x.png"
-)
-
-preferences {
-	page(name: "timeIntervalInput", title: "Only during a certain time") {
-		section {
-			input "starting", "time", title: "Starting", required: false
-			input "ending", "time", title: "Ending", required: false
-		}
-	}
-	
-	page(name: "mainPage")
-}
-
-def mainPage() {
-	dynamicPage(name: "mainPage", install: true, uninstall: true) {
-
-		section("Where do you want to watch?") {
-			input name: "beacons", type: "capability.beacon", title: "Select your beacon(s)", 
-				multiple: true, required: true
-		}
-
-		section("Who do you want to watch for?") {
-			input name: "phones", type: "device.mobilePresence", title: "Select your phone(s)", 
-				multiple: true, required: true
-		}
-
-		section("What do you want to do on arrival?") {
-			input name: "arrivalPhrase", type: "enum", title: "Execute a phrase", 
-				options: listPhrases(), required: false
-			input "arrivalOnSwitches", "capability.switch", title: "Turn on some switches", 
-				multiple: true, required: false
-			input "arrivalOffSwitches", "capability.switch", title: "Turn off some switches", 
-				multiple: true, required: false
-			input "arrivalLocks", "capability.lock", title: "Unlock the door",
-				multiple: true, required: false
-		}
-
-		section("What do you want to do on departure?") {
-			input name: "departPhrase", type: "enum", title: "Execute a phrase", 
-				options: listPhrases(), required: false
-			input "departOnSwitches", "capability.switch", title: "Turn on some switches", 
-				multiple: true, required: false
-			input "departOffSwitches", "capability.switch", title: "Turn off some switches", 
-				multiple: true, required: false
-			input "departLocks", "capability.lock", title: "Lock the door",
-				multiple: true, required: false
-		}
-
-		section("Do you want to be notified?") {
-			input "pushNotification", "bool", title: "Send a push notification"
-			input "phone", "phone", title: "Send a text message", description: "Tap to enter phone number", 
-				required: false
-		}
-
-		section {
-			label title: "Give your automation a name", description: "e.g. Goodnight Home, Wake Up"
-		}
-
-		def timeLabel = timeIntervalLabel()
-		section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
-			href "timeIntervalInput", title: "Only during a certain time", 
-				description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
-
-			input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
-				options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
-
-			input "modes", "mode", title: "Only when mode is", multiple: true, required: false
-		}
-	}
-}
-
-// Lifecycle management
-def installed() {
-	log.debug "<beacon-control> Installed with settings: ${settings}"
-	initialize()
-}
-
-def updated() {
-	log.debug "<beacon-control> Updated with settings: ${settings}"
-	unsubscribe()
-	initialize()
-}
-
-def initialize() {
-	subscribe(beacons, "presence", beaconHandler)
-}
-
-// Event handlers
-def beaconHandler(evt) {
-	log.debug "<beacon-control> beaconHandler: $evt"
-
-	if (allOk) {
-		def data = new groovy.json.JsonSlurper().parseText(evt.data)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> data: $data - phones: " + phones*.deviceNetworkId
-
-		def beaconName = getBeaconName(evt)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> beaconName: $beaconName"
-
-		def phoneName = getPhoneName(data)
-                // removed logging of device names. can be added back for debugging
-		//log.debug "<beacon-control> phoneName: $phoneName"
-		if (phoneName != null) {
-            def action = data.presence == "1" ? "arrived" : "left"
-            def msg = "$phoneName has $action ${action == 'arrived' ? 'at ' : ''}the $beaconName"
-
-            if (action == "arrived") {
-                msg = arriveActions(msg)
-            }
-            else if (action == "left") {
-                msg = departActions(msg)
-            }
-            log.debug "<beacon-control> msg: $msg"
-
-            if (pushNotification || phone) {
-                def options = [
-                    method: (pushNotification && phone) ? "both" : (pushNotification ? "push" : "sms"),
-                    phone: phone
-                ]
-                sendNotification(msg, options)
-            }
-        }
-	}
-}
-
-// Helpers
-private arriveActions(msg) {
-	if (arrivalPhrase || arrivalOnSwitches || arrivalOffSwitches || arrivalLocks) msg += ", so"
-	
-	if (arrivalPhrase) {
-		log.debug "<beacon-control> executing: $arrivalPhrase"
-		executePhrase(arrivalPhrase)
-		msg += " ${prefix('executed')} $arrivalPhrase."
-	}
-	if (arrivalOnSwitches) {
-		log.debug "<beacon-control> turning on: $arrivalOnSwitches"
-		arrivalOnSwitches.on()
-		msg += " ${prefix('turned')} ${list(arrivalOnSwitches)} on."
-	}
-	if (arrivalOffSwitches) {
-		log.debug "<beacon-control> turning off: $arrivalOffSwitches"
-		arrivalOffSwitches.off()
-		msg += " ${prefix('turned')} ${list(arrivalOffSwitches)} off."
-	}
-	if (arrivalLocks) {
-		log.debug "<beacon-control> unlocking: $arrivalLocks"
-		arrivalLocks.unlock()
-		msg += " ${prefix('unlocked')} ${list(arrivalLocks)}."
-	}
-	msg
-}
-
-private departActions(msg) {
-	if (departPhrase || departOnSwitches || departOffSwitches || departLocks) msg += ", so"
-	
-	if (departPhrase) {
-		log.debug "<beacon-control> executing: $departPhrase"
-		executePhrase(departPhrase)
-		msg += " ${prefix('executed')} $departPhrase."
-	}
-	if (departOnSwitches) {
-		log.debug "<beacon-control> turning on: $departOnSwitches"
-		departOnSwitches.on()
-		msg += " ${prefix('turned')} ${list(departOnSwitches)} on."
-	}
-	if (departOffSwitches) {
-		log.debug "<beacon-control> turning off: $departOffSwitches"
-		departOffSwitches.off()
-		msg += " ${prefix('turned')} ${list(departOffSwitches)} off."
-	}
-	if (departLocks) {
-		log.debug "<beacon-control> unlocking: $departLocks"
-		departLocks.lock()
-		msg += " ${prefix('locked')} ${list(departLocks)}."
-	}
-	msg
-}
-
-private prefix(word) {
-	def result
-	def index = settings.prefixIndex == null ? 0 : settings.prefixIndex + 1
-	switch (index) {
-		case 0:
-			result = "I $word"
-			break
-		case 1:
-			result = "I also $word"
-			break
-		case 2:
-			result = "And I $word"
-			break
-		default:
-			result = "And $word"
-			break
-	}
-
-	settings.prefixIndex = index
-	log.trace "prefix($word'): $result"
-	result
-}
-
-private listPhrases() {
-	location.helloHome.getPhrases().label
-}
-
-private executePhrase(phraseName) {
-	if (phraseName) {
-		location.helloHome.execute(phraseName)
-		log.debug "<beacon-control> executed phrase: $phraseName"
-	}
-}
-
-private getBeaconName(evt) {
-	def beaconName = beacons.find { b -> b.id == evt.deviceId }
-	return beaconName
-}
-
-private getPhoneName(data) {    
-	def phoneName = phones.find { phone ->
-		// Work around DNI bug in data
-		def pParts = phone.deviceNetworkId.split('\\|')
-		def dParts = data.dni.split('\\|')
-        pParts[0] == dParts[0]
-	}
-	return phoneName
-}
-
-private hideOptionsSection() {
-	(starting || ending || days || modes) ? false : true
-}
-
-private getAllOk() {
-	modeOk && daysOk && timeOk
-}
-
-private getModeOk() {
-	def result = !modes || modes.contains(location.mode)
-	log.trace "<beacon-control> modeOk = $result"
-	result
-}
-
-private getDaysOk() {
-	def result = true
-	if (days) {
-		def df = new java.text.SimpleDateFormat("EEEE")
-		if (location.timeZone) {
-			df.setTimeZone(location.timeZone)
-		}
-		else {
-			df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
-		}
-		def day = df.format(new Date())
-		result = days.contains(day)
-	}
-	log.trace "<beacon-control> daysOk = $result"
-	result
-}
-
-private getTimeOk() {
-	def result = true
-	if (starting && ending) {
-		def currTime = now()
-		def start = timeToday(starting, location?.timeZone).time
-		def stop = timeToday(ending, location?.timeZone).time
-		result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
-	}
-	log.trace "<beacon-control> timeOk = $result"
-	result
-}
-
-private hhmm(time, fmt = "h:mm a") {
-	def t = timeToday(time, location.timeZone)
-	def f = new java.text.SimpleDateFormat(fmt)
-	f.setTimeZone(location.timeZone ?: timeZone(time))
-	f.format(t)
-}
-
-private timeIntervalLabel() {
-	(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
-}
-
-private list(Object names) {
-	return names[0]
-}
diff --git a/GlobalVariables/GlobalVariablesBothApps.groovy b/GlobalVariables/GlobalVariablesBothApps.groovy
index 998778b..2840bea 100644
--- a/GlobalVariables/GlobalVariablesBothApps.groovy
+++ b/GlobalVariables/GlobalVariablesBothApps.groovy
@@ -8,8 +8,6 @@
 @Field def appObject = new Touched(sendEvent, 0)
 //Create a global list for events
 //@Field def evt = []
-//Global Object for class AtomicState!
-@Field def atomicState = new AtomicState()
 //Global Object for class Touch Sensor!
 @Field def touchSensorObject = new NfcTouch(sendEvent, 1)
 //Global Object for class switch!
diff --git a/GlobalVariables/GlobalVariablesEachApp.groovy b/GlobalVariables/GlobalVariablesEachApp.groovy
index 0e1de0b..8ae34ad 100644
--- a/GlobalVariables/GlobalVariablesEachApp.groovy
+++ b/GlobalVariables/GlobalVariablesEachApp.groovy
@@ -16,3 +16,5 @@ def timersList = []
 def settings
 //Zip code
 def zipCode = 92617
+//atomicState variable
+def atomicState = [version: "1.01"]
diff --git a/GlobalVariables/test.groovy b/GlobalVariables/test.groovy
new file mode 100644
index 0000000..4b73ab8
--- /dev/null
+++ b/GlobalVariables/test.groovy
@@ -0,0 +1,3 @@
+String s = "smoke.detected"
+if (s.contains("smoke"))
+	println(s)
diff --git a/IlluminanceMeasurement/IlluminanceMeasurement.groovy b/IlluminanceMeasurement/IlluminanceMeasurement.groovy
index c73576b..644db1b 100644
--- a/IlluminanceMeasurement/IlluminanceMeasurement.groovy
+++ b/IlluminanceMeasurement/IlluminanceMeasurement.groovy
@@ -30,4 +30,10 @@ public class IlluminanceMeasurement {
 		}
 	}
 
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "illuminance") {
+			return illuminance
+		}
+	}
+
 }
diff --git a/IlluminanceMeasurement/IlluminanceMeasurements.groovy b/IlluminanceMeasurement/IlluminanceMeasurements.groovy
index 4511001..6d4e38d 100644
--- a/IlluminanceMeasurement/IlluminanceMeasurements.groovy
+++ b/IlluminanceMeasurement/IlluminanceMeasurements.groovy
@@ -25,10 +25,10 @@ public class IlluminanceMeasurements {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != illuminanceMeasurements[0].illuminance) {
+		if (eventDataMap["value"].toInteger() != illuminanceMeasurements[0].illuminance) {
+			this.illuminance = eventDataMap["value"].toInteger()
+			this.currentIlluminance = eventDataMap["value"].toInteger()
 			illuminanceMeasurements[0].setValue(eventDataMap["value"])
-			this.illuminance = illuminanceMeasurements[0].illuminance
-			this.currentIlluminance = illuminanceMeasurements[0].illuminance
 			sendEvent(eventDataMap)
 		}
 	}
@@ -46,6 +46,9 @@ public class IlluminanceMeasurements {
 	def find(Closure Input) {
 		illuminanceMeasurements.find(Input)
 	}
+	def sort(Closure Input) {
+		illuminanceMeasurements.sort(Input)
+	}
 	def collect(Closure Input) {
 		illuminanceMeasurements.collect(Input)
 	}
@@ -55,6 +58,10 @@ public class IlluminanceMeasurements {
 		illuminanceMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def latestValue(String deviceFeature) {
+		illuminanceMeasurements[0].latestValue(deviceFeature)//It is called if we have only one device
+	}
+
 	def getAt(int ix) {
 		illuminanceMeasurements[ix]
 	}
diff --git a/ImageCapture/ImageCaptures.groovy b/ImageCapture/ImageCaptures.groovy
index 661e870..691a851 100644
--- a/ImageCapture/ImageCaptures.groovy
+++ b/ImageCapture/ImageCaptures.groovy
@@ -46,21 +46,24 @@ public class ImageCaptures {
 	def find(Closure Input) {
 		imageCaptureSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		imageCaptureSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		imageCaptureSensors.collect(Input)
 	}
 
 	def alarmOn() {
 		if (alarmState != "armed") {
-			imageCaptureSensors[0].alarmOn()
 			this.alarmState = "armed"
+			imageCaptureSensors[0].alarmOn()
 		}
 	}
 
 	def alarmOff() {
 		if (alarmState != "not armed") {
-			imageCaptureSensors[0].alarmOff()
 			this.alarmState = "not armed"
+			imageCaptureSensors[0].alarmOff()
 		}
 	}
 
diff --git a/Location/LocationVar.groovy b/Location/LocationVar.groovy
index d10206b..a87abe9 100644
--- a/Location/LocationVar.groovy
+++ b/Location/LocationVar.groovy
@@ -6,6 +6,7 @@ class LocationVar {
     	private def modes
 	private def timeZone
     	private String mode
+	private String name
     	private List contacts
     	private List phoneNumbers
 	def sendEvent
@@ -21,6 +22,7 @@ class LocationVar {
 		this.phoneNumbers = [9495379373]
 		this.sendEvent = sendEvent
 		this.timeZone = TimeZone.getTimeZone("America/New_York")
+		this.name = "hub0"
     	}
 
 	//By Model Checker
diff --git a/Lock/Lock.groovy b/Lock/Lock.groovy
index 76482b4..0271050 100644
--- a/Lock/Lock.groovy
+++ b/Lock/Lock.groovy
@@ -28,11 +28,13 @@ public class Lock {
 	def lock() {
 		if (lockState != "locked") {
 			println("the door with id:$id is locked!")
-			this.lockLatestValue = this.lockState
+			this.lockLatestValue = "locked"
 			this.lockState = "locked"
 			this.currentLock = "locked"
 			sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
 				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "lock.locked", value: "locked", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -40,11 +42,13 @@ public class Lock {
 		if (lockState != "locked") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the door with id:$id is locked!")
-				this.lockLatestValue = this.lockState
+				this.lockLatestValue = "locked"
 				this.lockState = "locked"
 				this.currentLock = "locked"
 				sendEvent([name: "lock", value: "locked", deviceId: this.id, descriptionText: "",
 					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "lock.locked", value: "locked", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -52,11 +56,15 @@ public class Lock {
 	def unlock() {
 		if (lockState != "unlocked") {
 			println("the door with id:$id is unlocked!")
-			this.lockLatestValue = this.lockState
+			this.lockLatestValue = "unlocked"
 			this.lockState = "unlocked"
 			this.currentLock = "unlocked"
 			sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
 				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "lock.unlocked", value: "unlocked", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -64,11 +72,15 @@ public class Lock {
 		if (lockState != "unlocked") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the door with id:$id is locked!")
-				this.lockLatestValue = this.lockState
-				this.lockState = "locked"
-				this.currentLock = "locked"
+				this.lockLatestValue = "unlocked"
+				this.lockState = "unlocked"
+				this.currentLock = "unlocked"
 				sendEvent([name: "unlock", value: "unlocked", deviceId: this.id, descriptionText: "",
 					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "lock", value: "unlocked", deviceId: this.id, descriptionText: "",
+					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "lock.unlocked", value: "unlocked", deviceId: this.id, descriptionText: "",
+					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])				
 			}
 		}
 	}
@@ -76,7 +88,7 @@ public class Lock {
 	//By Model Checker
 	def setValue(String value) {
 		println("the door with id:$id is $value!")
-		this.lockLatestValue = this.lockState
+		this.lockLatestValue = value
 		this.lockState = value
 		this.currentLock = value
 	}
diff --git a/Lock/Locks.groovy b/Lock/Locks.groovy
index ea75ef3..409058f 100644
--- a/Lock/Locks.groovy
+++ b/Lock/Locks.groovy
@@ -91,6 +91,9 @@ public class Locks{
 	def find(Closure Input) {
 		locks.find(Input)
 	}
+	def sort(Closure Input) {
+		locks.sort(Input)
+	}
 	def collect(Closure Input) {
 		locks.collect(Input)
 	}
diff --git a/Methods/createAccessToken.groovy b/Methods/createAccessToken.groovy
new file mode 100644
index 0000000..1d639f6
--- /dev/null
+++ b/Methods/createAccessToken.groovy
@@ -0,0 +1,5 @@
+/////////////////////////////////////////////////////////////////////
+def createAccessToken() {
+	state.accessToken = "accessToken"
+	return state.accessToken
+}
diff --git a/Methods/eventHandler.groovy b/Methods/eventHandler.groovy
index b838418..ca13fa3 100644
--- a/Methods/eventHandler.groovy
+++ b/Methods/eventHandler.groovy
@@ -13,14 +13,24 @@ def eventHandler(LinkedHashMap eventDataMap) {
 	for (int i = 0;i < app2.eventList.size();i++) {
 		if (app2.eventList[i] == name) {
 			def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-			app2.functionList[i](event)
+			if (app2.functionList[i] instanceof String) {
+				String toCall = app2.functionList[i]
+				app2."$toCall"(event)
+			}
+			else
+				app2.functionList[i](event)
 		}
 	}
 
 	for (int i = 0;i < app1.eventList.size();i++) {
 		if (app1.eventList[i] == name) {
 			def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-			app1.functionList[i](event)
+			if (app1.functionList[i] instanceof String) {
+				String toCall = app1.functionList[i]
+				app1."$toCall"(event)
+			}
+			else
+				app1.functionList[i](event)
 		}
 	}
 }
diff --git a/Methods/runOnce.groovy b/Methods/runOnce.groovy
new file mode 100644
index 0000000..335cc19
--- /dev/null
+++ b/Methods/runOnce.groovy
@@ -0,0 +1,4 @@
+/////////////////////////////////////////////////////////////////////
+def runOnce(Date date, Closure methodToCall) {
+	methodTocall()
+}
diff --git a/Methods/sendNotificationToContacts.groovy b/Methods/sendNotificationToContacts.groovy
index 165d0a4..06563c0 100644
--- a/Methods/sendNotificationToContacts.groovy
+++ b/Methods/sendNotificationToContacts.groovy
@@ -9,3 +9,13 @@ def sendNotificationToContacts(String text, String recipients) {
 		}
 	}
 }
+
+def sendNotificationToContacts(String text, String recipients, LinkedHashMap metaData) {
+	for (int i = 0;i < recipients.size();i++) {
+		for (int j = 0;j < location.contacts.size();j++) {
+			if (recipients[i] == location.contacts[j]) {
+				println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
+			}
+		}
+	}
+}
diff --git a/Methods/setLocationMode.groovy b/Methods/setLocationMode.groovy
index d2dade1..aa7424b 100644
--- a/Methods/setLocationMode.groovy
+++ b/Methods/setLocationMode.groovy
@@ -1,5 +1,8 @@
 /////////////////////////////////////////////////////////////////////
 def setLocationMode(String mode) {
-	location.mode = mode
+	location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
+			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+	location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
+			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 }
 
diff --git a/Methods/subscribe.groovy b/Methods/subscribe.groovy
index 74f7047..730b76a 100644
--- a/Methods/subscribe.groovy
+++ b/Methods/subscribe.groovy
@@ -17,6 +17,12 @@ def subscribe(Object obj, String event, Closure FunctionToCall) {
 	eventList.add(event)
 	functionList.add(FunctionToCall)
 }
+////subscribe(obj, event, nameOfFunc)
+def subscribe(Object obj, String event, String nameOfFunction) {
+	objectList.add(obj)
+	eventList.add(event)
+	functionList.add(nameOfFunction)
+}
 ////subscribe(obj, event, func, data)
 def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
 	objectList.add(obj)	
diff --git a/Methods/unschedule.groovy b/Methods/unschedule.groovy
index 322d805..7f6ca1f 100644
--- a/Methods/unschedule.groovy
+++ b/Methods/unschedule.groovy
@@ -9,6 +9,17 @@ def unschedule(Closure functionToUnschedule) {
 	}
 }
 
+def unschedule(String nameOfFunctionToUnschedule) {
+	for (int i = 0;i < timersFuncList.size();i++) {
+		if (timersFuncList[i] instanceof String) {
+			if (timersFuncList[i] == nameOfFunctionToUnschedule) {
+				if (timersList != null)
+					timersList[i].cancel()
+			}
+		}
+	}
+}
+
 
 def unschedule() {
 	for (int i = 0;i < timersFuncList.size();i++) {
diff --git a/MobilePresence/MobilePresences.groovy b/MobilePresence/MobilePresences.groovy
index e264cae..a462b9f 100644
--- a/MobilePresence/MobilePresences.groovy
+++ b/MobilePresence/MobilePresences.groovy
@@ -36,6 +36,9 @@ public class MobilePresences {
 	def find(Closure Input) {
 		mobilePresences.find(Input)
 	}
+	def sort(Closure Input) {
+		mobilePresences.sort(Input)
+	}
 	def collect(Closure Input) {
 		mobilePresences.collect(Input)
 	}
diff --git a/MotionSensor/MotionSensor.groovy b/MotionSensor/MotionSensor.groovy
index 825fe33..79fbf9b 100644
--- a/MotionSensor/MotionSensor.groovy
+++ b/MotionSensor/MotionSensor.groovy
@@ -22,8 +22,8 @@ public class MotionSensor {
 	}
 
 	def setValue(String value) {
-		this.motionLatestValue = motion
 		println("the motion sensor with id:$id is triggered to $value!")
+		this.motionLatestValue = value
 		this.motion = value
 		this.currentMotion = value
 		this.states.add(value)
diff --git a/MotionSensor/MotionSensors.groovy b/MotionSensor/MotionSensors.groovy
index 8516713..340e124 100644
--- a/MotionSensor/MotionSensors.groovy
+++ b/MotionSensor/MotionSensors.groovy
@@ -38,10 +38,10 @@ public class MotionSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != motionSensors[0].motion) {
+			this.motionLatestValue = eventDataMap["value"]
+			this.motion = eventDataMap["value"]
+			this.currentMotion = eventDataMap["value"]
 			motionSensors[0].setValue(eventDataMap["value"])
-			this.motionLatestValue = motionSensors[0].motionLatestValue
-			this.motion = motionSensors[0].motion
-			this.currentMotion = motionSensors[0].motion
 			sendEvent(eventDataMap)
 		}
 	}
@@ -59,6 +59,9 @@ public class MotionSensors {
 	def find(Closure Input) {
 		motionSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		motionSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		motionSensors.collect(Input)
 	}
diff --git a/MusicPlayer/MusicPlayer.groovy b/MusicPlayer/MusicPlayer.groovy
index 675f47a..05faf93 100644
--- a/MusicPlayer/MusicPlayer.groovy
+++ b/MusicPlayer/MusicPlayer.groovy
@@ -4,6 +4,7 @@ import Timer.SimulatedTimer
 
 
 public class MusicPlayer {
+	def sendEvent
 	private String id
 	private String label
 	private String displayName
@@ -14,7 +15,8 @@ public class MusicPlayer {
 	private String trackData
 	private String trackDescription
 	
-	MusicPlayer(String id, String label, String displayName, int level, String mute, String status, int trackNumber, String trackData, String trackDescription) {
+	MusicPlayer(Closure sendEvent, String id, String label, String displayName, int level, String mute, String status, int trackNumber, String trackData, String trackDescription) {
+		this.sendEvent = sendEvent
 		this.id = id
 		this.label = label
 		this.displayName = displayName
@@ -51,7 +53,9 @@ public class MusicPlayer {
 		if (mute != "muted") {
 			println("the music player with id:$id is muted!")
 			this.mute = "muted"
-			sendEvent([name: "mute", value: "mute", deviceId: this.id, descriptionText: "",
+			sendEvent([name: "mute", value: "muted", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "mute.muted", value: "muted", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
@@ -63,6 +67,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 		sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
 			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -75,6 +81,8 @@ public class MusicPlayer {
 			this.status = "paused"
 			sendEvent([name: "status", value: "paused", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.paused", value: "paused", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 	def play() {
@@ -83,6 +91,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 	def playTrack(String trackToPlay) {
@@ -92,6 +102,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 		sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
 			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -107,6 +119,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 		sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
 			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -123,6 +137,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 	def setLevel(int level) {
@@ -140,6 +156,8 @@ public class MusicPlayer {
 			this.status = "playing"
 			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 		sendEvent([name: "trackDescription", value: "someDescriptions", deviceId: this.id, descriptionText: "",
 			   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -152,6 +170,18 @@ public class MusicPlayer {
 			this.status = "stopped"
 			sendEvent([name: "status", value: "stopped", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.stopped", value: "stopped", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		}
+	}
+	def playText(String text) {
+		println("the music player with id:$id is playing the text:$text!")
+		if (status != "playing") {
+			this.status = "playing"
+			sendEvent([name: "status", value: "playing", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "status.playing", value: "playing", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -160,4 +190,10 @@ public class MusicPlayer {
 			return status
 		}
 	}
+
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "musicPlayer") {
+			return status
+		}
+	}
 }
diff --git a/MusicPlayer/MusicPlayers.groovy b/MusicPlayer/MusicPlayers.groovy
index 63a213b..d423e5c 100644
--- a/MusicPlayer/MusicPlayers.groovy
+++ b/MusicPlayer/MusicPlayers.groovy
@@ -43,39 +43,39 @@ public class MusicPlayers {
 			this.status = "playing"
 		}
 
-		musicPlayers.add(new MusicPlayer(id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
+		musicPlayers.add(new MusicPlayer(sendEvent, id, label, displayName, this.level, this.mute, this.status, this.trackNumber, this.trackData, this.trackDescription))
 	}
 
 	//By model checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["name"] == "status") {
 			if (eventDataMap["value"] != musicPlayers[0].status) {
+				this.status = eventDataMap["value"]
 				musicPlayers[0].setValue(eventDataMap["value"], "status")
-				this.status = musicPlayers[0].status
 				sendEvent(eventDataMap)
 			}	
 		} else if (eventDataMap["name"] == "level") {
-			if (eventDataMap["value"] != musicPlayers[0].level) {
+			if (eventDataMap["value"].toInteger() != musicPlayers[0].level) {
+				this.level = eventDataMap["value"].toInteger()
 				musicPlayers[0].setValue(eventDataMap["value"], "level")
-				this.level = musicPlayers[0].level
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "trackDescription") {
 			if (eventDataMap["value"] != musicPlayers[0].trackDescription) {
+				this.trackDescription = eventDataMap["value"]
 				musicPlayers[0].setValue(eventDataMap["value"], "trackDescription")
-				this.trackDescription = musicPlayers[0].trackDescription
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "trackData") {
 			if (eventDataMap["value"] != musicPlayers[0].trackData) {
-				musicPlayers[0].setValue(eventDataMap["value"], "trackData")
-				this.trackData = musicPlayers[0].trackData
+				this.trackData = eventDataMap["value"]
+				musicPlayers[0].setValue(eventDataMap["value"], "trackData")				
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "mute") {
 			if (eventDataMap["value"] != musicPlayers[0].mute) {
+				this.mute = eventDataMap["value"]
 				musicPlayers[0].setValue(eventDataMap["value"], "mute")
-				this.mute = musicPlayers[0].mute
 				sendEvent(eventDataMap)
 			}
 		}
@@ -94,6 +94,9 @@ public class MusicPlayers {
 	def find(Closure Input) {
 		musicPlayers.find(Input)
 	}
+	def sort(Closure Input) {
+		musicPlayers.sort(Input)
+	}
 	def collect(Closure Input) {
 		musicPlayers.collect(Input)
 	}
@@ -101,76 +104,85 @@ public class MusicPlayers {
 	//methods
 	def mute() {
 		if (mute != "muted") {
-			musicPlayers[0].mute()
 			this.mute = "muted"
+			musicPlayers[0].mute()
 		}
 	}
 	def nextTrack() {
-		musicPlayers[0].nextTrack()
 		if (status != "playing") {
 			this.status = "playing"
 		}
-		this.trackNumber = musicPlayers[0].trackNumber
+		this.trackNumber = this.trackNumber+1
+		musicPlayers[0].nextTrack()
 	}
 	def pause() {
 		if (status != "paused") {
-			musicPlayers[0].pause()
 			this.status = "paused"
+			musicPlayers[0].pause()			
 		}
 	}
 	def play() {
 		if (status != "playing") {
-			musicPlayers[0].play()
 			this.status = "playing"
+			musicPlayers[0].play()
 		}
 	}
 	def playTrack(String trackToPlay) {
-		musicPlayers[0].playTrack(trackToPlay)
 		if (status != "playing") {
 			this.status = "playing"
 		}
-		this.trackNumber = musicPlayers[0].trackNumber
+		musicPlayers[0].playTrack(trackToPlay)
 	}
 	def previousTrack() {
-		musicPlayers[0].previousTrack()
 		if (status != "playing") {
 			this.status = "playing"
 		}
-		this.trackNumber = musicPlayers[0].trackNumber
+		if (this.trackNumber != 1)
+			this.trackNumber = this.trackNumber-1
+		musicPlayers[0].previousTrack()
 	}
 	def restoreTrack(String trackToRestore) {
 		musicPlayers[0].restoreTrack(trackToRestore)
 	}
 	def resumeTrack(String trackToResume) {
-		musicPlayers[0].resumeTrack(trackToResume)
 		if (status != "playing") {
 			this.status = "playing"
 		}
+		musicPlayers[0].resumeTrack(trackToResume)
 	}
 	def setLevel(int level) {
-		if (level != this.level) {		
+		if (level != this.level) {
+			this.level = level	
 			musicPlayers[0].setLevel(level)
-			this.level = level
 		}
 	}
 	def setTrack(String trackToSet) {
-		musicPlayers[0].setTrack(trackToSet)
 		if (status != "playing") {
 			this.status = "playing"
 		}
-		this.trackNumber = musicPlayers[0].trackNumber
+		musicPlayers[0].setTrack(trackToSet)
 	}
 	def stop() {
 		if (status != "stopped") {
-			musicPlayers[0].stop()
 			this.status = "stopped"
+			musicPlayers[0].stop()
 		}
 	}
+	def playText(String text) {
+		if (status != "playing") {
+			this.status = "playing"
+		}
+		musicPlayers[0].playText(text)
+	}
 
 	def currentValue(String deviceFeature) {
 		musicPlayers[0].currentValue(deviceFeature)
 	}
 
+	def latestValue(String deviceFeature) {
+		musicPlayers[0].latestValue(deviceFeature)
+	}
+
 	def getAt(int ix) {
 		musicPlayers[ix]
 	}
diff --git a/PowerMeter/PowerMeter.groovy b/PowerMeter/PowerMeter.groovy
index 212d5fa..a0915ea 100644
--- a/PowerMeter/PowerMeter.groovy
+++ b/PowerMeter/PowerMeter.groovy
@@ -29,4 +29,10 @@ public class PowerMeter {
 		}
 	}
 
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "power") {
+			return power
+		}
+	}
+
 }
diff --git a/PowerMeter/PowerMeters.groovy b/PowerMeter/PowerMeters.groovy
index b452ec8..fe400ff 100644
--- a/PowerMeter/PowerMeters.groovy
+++ b/PowerMeter/PowerMeters.groovy
@@ -25,10 +25,10 @@ public class PowerMeters {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != powerMeters[0].power) {
+		if (eventDataMap["value"].toInteger() != powerMeters[0].power) {
+			this.power = eventDataMap["value"].toInteger()
+			this.currentPower = eventDataMap["value"].toInteger()
 			powerMeters[0].setValue(eventDataMap["value"])
-			this.power = powerMeters[0].power
-			this.currentPower = powerMeters[0].currentPower
 			sendEvent(eventDataMap)
 		}
 	}
@@ -46,6 +46,9 @@ public class PowerMeters {
 	def find(Closure Input) {
 		powerMeters.find(Input)
 	}
+	def sort(Closure Input) {
+		powerMeters.sort(Input)
+	}
 	def collect(Closure Input) {
 		powerMeters.collect(Input)
 	}
@@ -55,6 +58,10 @@ public class PowerMeters {
 		powerMeters[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def latestValue(String deviceFeature) {
+		powerMeters[0].latestValue(deviceFeature)//It is called if we have only one device
+	}
+
 	def getAt(int ix) {
 		powerMeters[ix]
 	}
diff --git a/PresenceSensor/PresenceSensor.groovy b/PresenceSensor/PresenceSensor.groovy
index 5f15a6f..c1553fb 100644
--- a/PresenceSensor/PresenceSensor.groovy
+++ b/PresenceSensor/PresenceSensor.groovy
@@ -20,8 +20,8 @@ public class PresenceSensor {
 	}
 
 	def setValue(String value) {
-		this.presenceLatestValue = presence
 		println("the presence sensor with id:$id is triggered to $value!")
+		this.presenceLatestValue = value
 		this.presence = value
 		this.currentPresence = value
 	}
diff --git a/PresenceSensor/PresenceSensors.groovy b/PresenceSensor/PresenceSensors.groovy
index cb13242..bec4edb 100644
--- a/PresenceSensor/PresenceSensors.groovy
+++ b/PresenceSensor/PresenceSensors.groovy
@@ -38,10 +38,10 @@ public class PresenceSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != presenceSensors[0].presence) {
+			this.presenceLatestValue = eventDataMap["value"]
+			this.presence = eventDataMap["value"]
+			this.currentPresence = eventDataMap["value"]
 			presenceSensors[0].setValue(eventDataMap["value"])
-			this.presenceLatestValue = presenceSensors[0].presenceLatestValue
-			this.presence = presenceSensors[0].presence
-			this.currentPresence = presenceSensors[0].presence
 			sendEvent(eventDataMap)
 		}
 	}
@@ -59,6 +59,9 @@ public class PresenceSensors {
 	def find(Closure Input) {
 		presenceSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		presenceSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		presenceSensors.collect(Input)
 	}
diff --git a/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy b/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
index 083bd8f..c9ad722 100644
--- a/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
+++ b/RelativeHumidityMeasurement/RelativeHumidityMeasurement.groovy
@@ -29,4 +29,9 @@ public class RelativeHumidityMeasurement {
 		}
 	}
 
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "humidity") {
+			return humidity
+		}
+	}
 }
diff --git a/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy b/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
index bb5390a..da416c1 100644
--- a/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
+++ b/RelativeHumidityMeasurement/RelativeHumidityMeasurements.groovy
@@ -25,10 +25,10 @@ public class RelativeHumidityMeasurements {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != humidityMeasurements[0].humidity) {
-			humidityMeasurements[0].setValue(eventDataMap["value"])
-			this.humidity = humidityMeasurements[0].humidity
-			this.currentHumidity = humidityMeasurements[0].currentHumidity		
+		if (eventDataMap["value"].toInteger() != humidityMeasurements[0].humidity) {
+			this.humidity = eventDataMap["value"].toInteger()
+			this.currentHumidity = eventDataMap["value"].toInteger()
+			humidityMeasurements[0].setValue(eventDataMap["value"])	
 			sendEvent(eventDataMap)
 		}
 	}
@@ -46,6 +46,9 @@ public class RelativeHumidityMeasurements {
 	def find(Closure Input) {
 		humidityMeasurements.find(Input)
 	}
+	def sort(Closure Input) {
+		humidityMeasurements.sort(Input)
+	}
 	def collect(Closure Input) {
 		humidityMeasurements.collect(Input)
 	}
@@ -55,6 +58,10 @@ public class RelativeHumidityMeasurements {
 		humidityMeasurements[0].currentValue(deviceFeature)//It is called if we have only one device
 	}
 
+	def latestValue(String deviceFeature) {
+		humidityMeasurements[0].latestValue(deviceFeature)//It is called if we have only one device
+	}
+
 	def getAt(int ix) {
 		humidityMeasurements[ix]
 	}
diff --git a/RelaySwitch/RelaySwitch.groovy b/RelaySwitch/RelaySwitch.groovy
index b418477..137d7ad 100644
--- a/RelaySwitch/RelaySwitch.groovy
+++ b/RelaySwitch/RelaySwitch.groovy
@@ -28,11 +28,13 @@ public class RelaySwitch {
 	def on() {
 		if (switchState != "on") {
 			println("the relay switch with id:$id is on!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "on"
 			this.switchState = "on"
 			this.currentSwitch = "on"
 			sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
-				  displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "on"]])
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -40,11 +42,13 @@ public class RelaySwitch {
 		if (switchState != "on") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the relay switch with id:$id is on!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "on"
 				this.switchState = "on"
 				this.currentSwitch = "on"
 				sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
 					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+				  	  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -52,11 +56,13 @@ public class RelaySwitch {
 	def off() {
 		if (switchState != "off") {
 			println("the relay switch with id:$id is off!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "off"
 			this.switchState = "off"
 			this.currentSwitch = "off"
 			sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+				  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -64,11 +70,13 @@ public class RelaySwitch {
 		if (switchState != "off") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the relay switch with id:$id is off!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "off"
 				this.switchState = "off"
 				this.currentSwitch = "off"
 				sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 					  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+				 	  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -76,7 +84,7 @@ public class RelaySwitch {
 	//By Model Checker
 	def setValue(String value) {
 		println("the relay switch with id:$id is $value!")
-		this.switchLatestValue = this.switchState
+		this.switchLatestValue = value
 		this.switchState = value
 		this.currentSwitch = value
 	}
diff --git a/RelaySwitch/RelaySwitches.groovy b/RelaySwitch/RelaySwitches.groovy
index afb3ace..4a3df4f 100644
--- a/RelaySwitch/RelaySwitches.groovy
+++ b/RelaySwitch/RelaySwitches.groovy
@@ -38,6 +38,9 @@ public class RelaySwitches {
 	def find(Closure Input) {
 		relaySwitches.find(Input)
 	}
+	def sort(Closure Input) {
+		relaySwitches.sort(Input)
+	}
 	def collect(Closure Input) {
 		relaySwitches.collect(Input)
 	}
@@ -45,40 +48,40 @@ public class RelaySwitches {
 	//By Apps
 	def on() {
 		if (switchState != "on") {
-			relaySwitches[0].on()
-			switchLatestValue = switchState
+			switchLatestValue = "on"
 			switchState = "on"
 			currentSwitch = "on"
+			relaySwitches[0].on()
 		}
 	}
 
 	def on(LinkedHashMap metaData) {
 		if (switchState != "on") {
 			def task = timers.runAfter(metaData["delay"]) {
-				relaySwitches[0].on()
-				switchLatestValue = switchState
+				switchLatestValue = "on"
 				switchState = "on"
 				currentSwitch = "on"
+				relaySwitches[0].on()
 			}
 		}
 	}
 
 	def off() {
 		if (switchState != "off") {
-			relaySwitches[0].off()
-			switchLatestValue = switchState
+			switchLatestValue = "off"
 			switchState = "off"
 			currentSwitch = "off"
+			relaySwitches[0].off()
 		}
 	}
 
 	def off(LinkedHashMap metaData) {
 		if (switchState != "off") {
 			def task = timers.runAfter(metaData["delay"]) {
-				relaySwitches[0].off()
-				switchLatestValue = switchState
+				switchLatestValue = "off"
 				switchState = "off"
 				currentSwitch = "off"
+				relaySwitches[0].off()
 			}
 		}
 	}
@@ -86,9 +89,9 @@ public class RelaySwitches {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != relaySwitches[0].switchState) {
+			this.switchState = eventDataMap["value"]
+			this.switchLatestValue = eventDataMap["value"]
 			relaySwitches[0].setValue(eventDataMap["value"])
-			this.switchState = relaySwitches[0].switchState
-			this.switchLatestValue = relaySwitches[0].switchLatestValue
 			sendEvent(eventDataMap)
 		}
 	}
diff --git a/Runner.py b/Runner.py
index d72844d..6f8bd4d 100644
--- a/Runner.py
+++ b/Runner.py
@@ -29,6 +29,8 @@ runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
 timeToday = open("Methods/"+"timeToday.groovy", "r")
 sendNotification = open("Methods/"+"sendNotification.groovy", "r")
 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
+createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
+runOnce = open("Methods/"+"runOnce.groovy", "r")
 App1 = open("Extractor/"+"App1/App1.groovy", "r")
 extractedObjectsApp1 = open("Extractor/"+"App1/extractedObjectsApp1.groovy", "r")
 extractedObjectsConstructorApp1 = open("Extractor/"+"App1/extractedObjectsConstructorApp1.groovy", "r")
@@ -109,7 +111,6 @@ Out.write("import Valve.Valves\n")
 Out.write("import MobilePresence.MobilePresence\n")
 Out.write("import MobilePresence.MobilePresences\n")
 Out.write("import Event.Event\n")
-Out.write("import AtomicState.AtomicState\n")
 Out.write("import Timer.SimulatedTimer\n")
 Out.write("\n")
 Out.write("//JPF's Verify API\n")
@@ -128,7 +129,6 @@ Out.write("class App1 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("\tdef app\n")
-Out.write("\tdef atomicState\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App1\n")
 for line in extractedObjectsApp1:
@@ -142,7 +142,6 @@ Out.write("\tApp1(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
 Out.write("\t\tapp = obj.appObject\n")
-Out.write("\t\tatomicState = obj.atomicState\n")
 for line in extractedObjectsConstructorApp1:
 	Out.write("\t\t"+line)
 Out.write("\t}\n")
@@ -183,6 +182,10 @@ for line in sendNotification:
 	Out.write("\t"+line)
 for line in canSchedule:
 	Out.write("\t"+line)
+for line in createAccessToken:
+	Out.write("\t"+line)
+for line in runOnce:
+	Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App1:
@@ -214,6 +217,8 @@ runEvery15Minutes = open("Methods/"+"runEvery15Minutes.groovy", "r")
 timeToday = open("Methods/"+"timeToday.groovy", "r")
 sendNotification = open("Methods/"+"sendNotification.groovy", "r")
 canSchedule = open("Methods/"+"canSchedule.groovy", "r")
+createAccessToken = open("Methods/"+"createAccessToken.groovy", "r")
+runOnce = open("Methods/"+"runOnce.groovy", "r")
 App2 = open("Extractor/"+"App2/App2.groovy", "r")
 extractedObjectsApp2 = open("Extractor/"+"App2/extractedObjectsApp2.groovy", "r")
 extractedObjectsConstructorApp2 = open("Extractor/"+"App2/extractedObjectsConstructorApp2.groovy", "r")
@@ -224,7 +229,6 @@ Out.write("class App2 {\n")
 Out.write("\tdef reference\n")
 Out.write("\tdef location\n")
 Out.write("\tdef app\n")
-Out.write("\tdef atomicState\n")
 Out.write("\n")
 Out.write("\t//Extracted objects for App2\n")
 for line in extractedObjectsApp2:
@@ -238,7 +242,6 @@ Out.write("\tApp2(Object obj) {\n")
 Out.write("\t\treference = obj\n")
 Out.write("\t\tlocation = obj.locationObject\n")
 Out.write("\t\tapp = obj.appObject\n")
-Out.write("\t\tatomicState = obj.atomicState\n")
 for line in extractedObjectsConstructorApp2:
 	Out.write("\t\t"+line)
 Out.write("\t}\n")
@@ -279,6 +282,10 @@ for line in sendNotification:
 	Out.write("\t"+line)
 for line in canSchedule:
 	Out.write("\t"+line)
+for line in createAccessToken:
+	Out.write("\t"+line)
+for line in runOnce:
+	Out.write("\t"+line)
 Out.write("\n")
 Start = 0
 for line in App2:
diff --git a/SleepSensor/SleepSensors.groovy b/SleepSensor/SleepSensors.groovy
index 269a419..884053c 100644
--- a/SleepSensor/SleepSensors.groovy
+++ b/SleepSensor/SleepSensors.groovy
@@ -25,8 +25,8 @@ public class SleepSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != sleepSensors[0].sleeping) {
+			this.sleeping = eventDataMap["value"]
 			sleepSensors[0].setValue(eventDataMap["value"])
-			this.sleeping = sleepSensors[0].sleeping
 			sendEvent(eventDataMap)
 		}
 	}
@@ -44,6 +44,9 @@ public class SleepSensors {
 	def find(Closure Input) {
 		sleepSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		sleepSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		sleepSensors.collect(Input)
 	}
diff --git a/SmokeDetector/SmokeDetector.groovy b/SmokeDetector/SmokeDetector.groovy
index 3182cc3..07b6764 100644
--- a/SmokeDetector/SmokeDetector.groovy
+++ b/SmokeDetector/SmokeDetector.groovy
@@ -9,33 +9,63 @@ public class SmokeDetector {
 	private String smoke
 	private String currentSmokeValue
 	private String smokeLatestValue
+	private String carbonMonoxide
+	private String currentCarbonMonoxideValue
+	private String carbonMonoxideLatestValue
+	private int battery
+	private int batteryLatestValue
 
-	SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue) {
+	SmokeDetector(String id, String label, String displayName, String smoke, String smokeLatestValue, String carbonMonoxide, String carbonMonoxideLatestValue, int battery) {
 		this.id = id
 		this.label = label
 		this.displayName = displayName
 		this.smoke = smoke
 		this.currentSmokeValue = smoke
 		this.smokeLatestValue = smokeLatestValue
+		this.carbonMonoxide = carbonMonoxide
+		this.currentCarbonMonoxideValue = currentCarbonMonoxideValue
+		this.carbonMonoxideLatestValue = carbonMonoxideLatestValue
+		this.battery = battery
+		this.batteryLatestValue = battery
 	}
 
-	def setValue(String value) {
-		this.smokeLatestValue = smoke
-		println("the smoke detector with id:$id is triggered to $value!")
-		this.smoke = value
-		this.currentSmokeValue = value
+	def setValue(String value, String name) {
+		if (name.contains("smoke")) {
+			println("the smoke value of smoke detector with id:$id is triggered to $value!")
+			this.smokeLatestValue = value
+			this.smoke = value
+			this.currentSmokeValue = value
+		} else if (name.contains("carbonMonoxide")) {
+			println("the carbonMonoxide value of smoke detector with id:$id is triggered to $value!")
+			this.carbonMonoxideLatestValue = value
+			this.carbonMonoxide = value
+			this.currentCarbonMonoxideValue = value
+		} else if (name.contains("battery")) {
+			println("the battery value of smoke detector with id:$id is triggered to $value!")
+			this.batteryLatestValue = value.toInteger()
+			this.battery = value.toInteger()
+		}
+		
 	}
 
 	
 	def currentValue(String deviceFeature) {
 		if (deviceFeature == "smoke") {
 			return currentSmokeValue
+		} else if (deviceFeature == "carbonMonoxide") {
+			return currentCarbonMonoxideValue
+		} else if (deviceFeature == "battery") {
+			return battery
 		}
 	}
 
 	def latestValue(String deviceFeature) {
 		if (deviceFeature == "smoke") {
 			return smokeLatestValue
+		} else if (deviceFeature == "carbonMonoxide") {
+			return carbonMonoxideLatestValue
+		} else if (deviceFeature == "battery") {
+			return batteryLatestValue
 		}
 	}
 }
diff --git a/SmokeDetector/SmokeDetectors.groovy b/SmokeDetector/SmokeDetectors.groovy
index e9d5da2..d2a9290 100644
--- a/SmokeDetector/SmokeDetectors.groovy
+++ b/SmokeDetector/SmokeDetectors.groovy
@@ -17,6 +17,11 @@ public class SmokeDetectors {
 	private String smoke = "clear"
 	private String currentSmokeValue = "clear"
 	private String smokeLatestValue = "clear"
+	private String carbonMonoxide = "clear"
+	private String currentCarbonMonoxideValue = "clear"
+	private String carbonMonoxideLatestValue = "clear"
+	private int battery = 50
+	private int batteryLatestValue = 50
 
 		
 	SmokeDetectors(Closure sendEvent, int deviceNumbers) {
@@ -24,28 +29,62 @@ public class SmokeDetectors {
 		this.deviceNumbers = deviceNumbers
 		this.smokeDetectors = []
 
-		def init = Verify.getInt(0,2)
-		if (init == 0) {
+		def initBattery = Verify.getIntFromList(30, 50, 70)
+		this.battery = initBattery
+		this.batteryLatestValue = initBattery
+
+		def initSmoke = Verify.getInt(0,2)
+		if (initSmoke == 0) {
 			this.currentSmokeValue = "clear"
 			this.smokeLatestValue = "clear"
-		} else if (init == 1) {
+		} else if (initSmoke == 1) {
 			this.currentSmokeValue = "detected"
 			this.smokeLatestValue = "detected"
 		} else {
 			this.currentSmokeValue = "tested"
 			this.smokeLatestValue = "tested"		
 		}
-		smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue))
+
+		def initCarbonMonoxide = Verify.getInt(0,2)
+		if (initCarbonMonoxide == 0) {
+			this.currentCarbonMonoxideValue = "clear"
+			this.carbonMonoxideLatestValue = "clear"
+		} else if (initCarbonMonoxide == 1) {
+			this.currentCarbonMonoxideValue = "detected"
+			this.carbonMonoxideLatestValue = "detected"
+		} else {
+			this.currentCarbonMonoxideValue = "tested"
+			this.carbonMonoxideLatestValue = "tested"		
+		}
+		smokeDetectors.add(new SmokeDetector(id, label, displayName, this.currentSmokeValue, this.smokeLatestValue, this.currentCarbonMonoxideValue,
+                                                     this.carbonMonoxideLatestValue, this.battery))
 	}
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
-			smokeDetectors[0].setValue(eventDataMap["value"])
-			this.smokeLatestValue = smokeDetectors[0].smokeLatestValue
-			this.smoke = smokeDetectors[0].currentSmokeValue
-			this.currentSmokeValue = smokeDetectors[0].currentSmokeValue
-			sendEvent(eventDataMap)
+		if (eventDataMap["name"].contains("smoke")) {
+			if (eventDataMap["value"] != smokeDetectors[0].currentSmokeValue) {
+				this.smokeLatestValue = eventDataMap["value"]
+				this.smoke = eventDataMap["value"]
+				this.currentSmokeValue = eventDataMap["value"]
+				smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+				sendEvent(eventDataMap)
+			}
+		} else if (eventDataMap["name"].contains("carbonMonoxide")) {
+			if (eventDataMap["value"] != smokeDetectors[0].currentCarbonMonoxideValue) {
+				this.carbonMonoxideLatestValue = eventDataMap["value"]
+				this.carbonMonoxide = eventDataMap["value"]
+				this.currentCarbonMonoxideValue = eventDataMap["value"]
+				smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+				sendEvent(eventDataMap)
+			}
+		} else if (eventDataMap["name"].contains("battery")) {
+			if (eventDataMap["value"].toInteger() != smokeDetectors[0].battery) {
+				this.battery = eventDataMap["value"].toInteger()
+				this.batteryLatestValue = eventDataMap["value"].toInteger()
+				smokeDetectors[0].setValue(eventDataMap["value"], eventDataMap["name"])
+				sendEvent(eventDataMap)
+			}
 		}
 	}
 
@@ -62,6 +101,9 @@ public class SmokeDetectors {
 	def find(Closure Input) {
 		smokeDetectors.find(Input)
 	}
+	def sort(Closure Input) {
+		smokeDetectors.sort(Input)
+	}
 	def collect(Closure Input) {
 		smokeDetectors.collect(Input)
 	}
diff --git a/SpeechSynthesis/SpeechSynthesises.groovy b/SpeechSynthesis/SpeechSynthesises.groovy
index 2ef8cec..df2528e 100644
--- a/SpeechSynthesis/SpeechSynthesises.groovy
+++ b/SpeechSynthesis/SpeechSynthesises.groovy
@@ -41,14 +41,17 @@ public class SpeechSynthesises {
 	def find(Closure Input) {
 		speechSynthesises.find(Input)
 	}
+	def sort(Closure Input) {
+		speechSynthesises.sort(Input)
+	}
 	def collect(Closure Input) {
 		speechSynthesises.collect(Input)
 	}
 
 	def setLevel(int level) {
 		if (level != this.level) {
-			speechSynthesises[0].setLevel(level)
 			this.level = level
+			speechSynthesises[0].setLevel(level)
 		}
 	}
 
diff --git a/StepSensor/StepSensors.groovy b/StepSensor/StepSensors.groovy
index 8f0f165..ea5fd3d 100644
--- a/StepSensor/StepSensors.groovy
+++ b/StepSensor/StepSensors.groovy
@@ -26,15 +26,15 @@ public class StepSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["name"] == "steps") {
-			if (eventDataMap["value"] != stepSensors[0].steps) {
+			if (eventDataMap["value"].toInteger() != stepSensors[0].steps) {
+				this.steps = eventDataMap["value"].toInteger()
 				stepSensors[0].setValue(eventDataMap["value"], "steps")
-				this.steps = stepSensors[0].steps
 				sendEvent(eventDataMap)
 			}
-		} else if (eventDataMap["value"] == "goal") {
-			if (eventDataMap["value"] != stepSensors[0].goal) {
+		} else if (eventDataMap["name"] == "goal") {
+			if (eventDataMap["value"].toInteger() != stepSensors[0].goal) {
+				this.goal = eventDataMap["value"].toInteger()
 				stepSensors[0].setValue(eventDataMap["value"], "goal")
-				this.goal = stepSensors[0].goal
 				sendEvent(eventDataMap)
 			}
 		}
@@ -53,6 +53,9 @@ public class StepSensors {
 	def find(Closure Input) {
 		stepSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		stepSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		stepSensors.collect(Input)
 	}
diff --git a/Switch/Switch.groovy b/Switch/Switch.groovy
index b924d21..aa3b2c5 100644
--- a/Switch/Switch.groovy
+++ b/Switch/Switch.groovy
@@ -31,7 +31,7 @@ public class Switch {
 		if (this.currentLevel != level) {
 			println("the switch with id:$id is setted to level $level!")
 			this.currentLevel = level
-			sendEvent([name: "level", value: "40", deviceId: this.id, descriptionText: "",
+			sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
@@ -39,11 +39,13 @@ public class Switch {
 	def on() {
 		if (this.switchState != "on") {
 			println("the switch with id:$id is on!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "on"
 			this.switchState = "on"
 			this.currentSwitch = "on"
 			sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -51,11 +53,13 @@ public class Switch {
 		if (this.switchState != "on") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the switch with id:$id is on!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "on"
 				this.switchState = "on"
 				this.currentSwitch = "on"
 				sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -63,11 +67,13 @@ public class Switch {
 	def off() {
 		if (this.switchState != "off") {
 			println("the switch with id:$id is off!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "off"
 			this.switchState = "off"
 			this.currentSwitch = "off"
 			sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -75,11 +81,13 @@ public class Switch {
 		if (this.switchState != "off") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the switch with id:$id is off!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "off"
 				this.switchState = "off"
 				this.currentSwitch = "off"
 				sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -87,7 +95,7 @@ public class Switch {
 	//By Model Checker
 	def setValue(String value) {
 		println("the switch with id:$id is $value!")
-		this.switchLatestValue = this.switchState
+		this.switchLatestValue = value
 		this.switchState = value
 		this.currentSwitch = value
 	}
diff --git a/Switch/Switches.groovy b/Switch/Switches.groovy
index 5a4ef48..44a275c 100644
--- a/Switch/Switches.groovy
+++ b/Switch/Switches.groovy
@@ -55,54 +55,57 @@ public class Switches {
 	def find(Closure Input) {
 		switches.find(Input)
 	}
+	def sort(Closure Input) {
+		switches.sort(Input)
+	}
 	def collect(Closure Input) {
 		switches.collect(Input)
 	}
 
 	//By Apps
 	def setLevel(int level) {
-		switches[0].setLevel(level)
 		currentLevel = level
+		switches[0].setLevel(level)
 	}
 
 	def on() {
-		switches[0].on()
-		switchLatestValue = switchState
+		switchLatestValue = "on"
 		switchState = "on"
 		currentSwitch = "on"
+		switches[0].on()
 	}
 
 	def on(LinkedHashMap metaData) {
 		def task = timers.runAfter(metaData["delay"]) {
-			switches[0].on()
-			switchLatestValue = switchState
+			switchLatestValue = "on"
 			switchState = "on"
 			currentSwitch = "on"
+			switches[0].on()
 		}
 	}
 
 	def off() {
-		switches[0].off()
-		switchLatestValue = switchState
+		switchLatestValue = "off"
 		switchState = "off"
 		currentSwitch = "off"
+		switches[0].off()
 	}
 
 	def off(LinkedHashMap metaData) {
 		def task = timers.runAfter(metaData["delay"]) {
-			switches[0].off()
-			switchLatestValue = switchState
+			switchLatestValue = "off"
 			switchState = "off"
 			currentSwitch = "off"
+			switches[0].off()
 		}
 	}
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != switches[0].switchState) {
+			this.switchState = eventDataMap["value"]
+			this.switchLatestValue = eventDataMap["value"]
 			switches[0].setValue(eventDataMap["value"])
-			this.switchState = switches[0].switchState
-			this.switchLatestValue = switches[0].switchLatestValue
 			sendEvent(eventDataMap)
 		}
 	}
diff --git a/SwitchLevel/SwitchLevel.groovy b/SwitchLevel/SwitchLevel.groovy
index 4b7acbf..ff83a50 100644
--- a/SwitchLevel/SwitchLevel.groovy
+++ b/SwitchLevel/SwitchLevel.groovy
@@ -34,7 +34,7 @@ public class SwitchLevel {
 			println("the switch with id:$id is setted to level $level!")
 			this.level = level
 			this.rate = level
-			sendEvent([name: "level", value: "50", deviceId: this.id, descriptionText: "",
+			sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
 				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
@@ -42,11 +42,13 @@ public class SwitchLevel {
 	def on() {
 		if (this.switchState != "on") {
 			println("the switch with id:$id is on!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "on"
 			this.switchState = "on"
 			this.currentSwitch = "on"
 			sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -54,11 +56,13 @@ public class SwitchLevel {
 		if (this.switchState != "on") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the switch with id:$id is on!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "on"
 				this.switchState = "on"
 				this.currentSwitch = "on"
 				sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
+			    	    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -66,11 +70,13 @@ public class SwitchLevel {
 	def off() {
 		if (this.switchState != "off") {
 			println("the switch with id:$id is off!")
-			this.switchLatestValue = this.switchState
+			this.switchLatestValue = "off"
 			this.switchState = "off"
 			this.currentSwitch = "off"
 			sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+			    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -78,11 +84,13 @@ public class SwitchLevel {
 		if (this.switchState != "off") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the switch with id:$id is off!")
-				this.switchLatestValue = this.switchState
+				this.switchLatestValue = "off"
 				this.switchState = "off"
 				this.currentSwitch = "off"
 				sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
 				    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
+			    	    displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
diff --git a/SwitchLevel/SwitchLevels.groovy b/SwitchLevel/SwitchLevels.groovy
index 35c4ad9..daa025b 100644
--- a/SwitchLevel/SwitchLevels.groovy
+++ b/SwitchLevel/SwitchLevels.groovy
@@ -40,6 +40,9 @@ public class SwitchLevels {
 	def find(Closure Input) {
 		switchLevels.find(Input)
 	}
+	def sort(Closure Input) {
+		switchLevels.sort(Input)
+	}
 	def collect(Closure Input) {
 		switchLevels.collect(Input)
 	}
@@ -54,43 +57,43 @@ public class SwitchLevels {
 	}
 
 	def on() {
-		switchLevels[0].on()
-		switchLatestValue = switchState
+		switchLatestValue = "on"
 		switchState = "on"
 		currentSwitch = "on"
+		switchLevels[0].on()
 	}
 
 	def on(LinkedHashMap metaData) {
 		def task = timers.runAfter(metaData["delay"]) {
-			switchLevels[0].on()
-			switchLatestValue = switchState
+			switchLatestValue = "on"
 			switchState = "on"
 			currentSwitch = "on"
+			switchLevels[0].on()
 		}
 	}
 
 	def off() {
-		switchLevels[0].off()
-		switchLatestValue = switchState
+		switchLatestValue = "off"
 		switchState = "off"
 		currentSwitch = "off"
+		switchLevels[0].off()
 	}
 
 	def off(LinkedHashMap metaData) {
 		def task = timers.runAfter(metaData["delay"]) {
-			switchLevels[0].off()
-			switchLatestValue = switchState
+			switchLatestValue = "off"
 			switchState = "off"
 			currentSwitch = "off"
+			switchLevels[0].off()
 		}
 	}
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != switchLevels[0].level) {
+		if (eventDataMap["value"].toInteger() != switchLevels[0].level) {
+			this.level = eventDataMap["value"].toInteger()
+			this.rate = eventDataMap["value"].toInteger()
 			switchLevels[0].setValue(eventDataMap["value"])
-			this.level = switchLevels[0].level
-			this.rate = switchLevels[0].level
 			sendEvent(eventDataMap)
 		}
 	}
diff --git a/TemperatureMeasurement/TemperatureMeasurement.groovy b/TemperatureMeasurement/TemperatureMeasurement.groovy
index fcee39a..afcb768 100644
--- a/TemperatureMeasurement/TemperatureMeasurement.groovy
+++ b/TemperatureMeasurement/TemperatureMeasurement.groovy
@@ -7,18 +7,21 @@ public class TemperatureMeasurement {
 	private String label
 	private String displayName
 	private int temperature
+	private int currentTemperature
 
 	TemperatureMeasurement(String id, String label, String displayName, int temperature) {
 		this.id = id
 		this.label = label
 		this.displayName = displayName
 		this.temperature = temperature
+		this.currentTemperature = temperature
 	}
 
 	//By Model Checker
 	def setValue(String value) {
 		println("the temperature is changed to $value!")
 		this.temperature = value.toInteger()
+		this.currentTemperature = value.toInteger()
 	}
 
 }
diff --git a/TemperatureMeasurement/TemperatureMeasurements.groovy b/TemperatureMeasurement/TemperatureMeasurements.groovy
index 95ed91f..3f3c634 100644
--- a/TemperatureMeasurement/TemperatureMeasurements.groovy
+++ b/TemperatureMeasurement/TemperatureMeasurements.groovy
@@ -12,6 +12,7 @@ public class TemperatureMeasurements {
 	private String label = "temperatureMeasurement0"
 	private String displayName = "temperatureMeasurement0"
 	private int temperature = 50
+	private int currentTemperature = 50
 
 	
 
@@ -26,9 +27,10 @@ public class TemperatureMeasurements {
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
-		if (eventDataMap["value"] != temperatureMeasurements[0].temperature) {
+		if (eventDataMap["value"].toInteger() != temperatureMeasurements[0].temperature) {
+			this.temperature = eventDataMap["value"].toInteger()
+			this.currentTemperature = eventDataMap["value"].toInteger()
 			temperatureMeasurements[0].setValue(eventDataMap["value"])
-			this.temperature = temperatureMeasurements[0].temperature
 			sendEvent(eventDataMap)
 		}
 	}
@@ -46,6 +48,9 @@ public class TemperatureMeasurements {
 	def find(Closure Input) {
 		temperatureMeasurements.find(Input)
 	}
+	def sort(Closure Input) {
+		temperatureMeasurements.sort(Input)
+	}
 	def collect(Closure Input) {
 		temperatureMeasurements.collect(Input)
 	}
diff --git a/Thermostat/Thermostat.groovy b/Thermostat/Thermostat.groovy
index bd9ede1..b3f68b4 100644
--- a/Thermostat/Thermostat.groovy
+++ b/Thermostat/Thermostat.groovy
@@ -7,11 +7,15 @@ public class Thermostat {
 	private String label
 	private String displayName
 	private int temperature
+	private int currentTemperature
 	private int currentCoolingSetpoint
 	private int currentHeatingSetpoint
 	private int coolingSetpoint
+	private int latestCoolingSetPoint
 	private int thermostatSetpoint
+	private int latestThermostatSetPoint
 	private int heatingSetpoint
+	private int latestHeatingSetPoint
 	private List coolingSetpointRange
 	private List thermostatSetpointRange
 	private List heatingSetpointRange
@@ -22,6 +26,9 @@ public class Thermostat {
 	private String thermostatMode
 	private String currentThermostatMode
 	private String climateName
+	private String thermostatLatestMode
+	private String thermostatLatestOperatingState
+	private String thermostatLatestFanMode
 	def sendEvent
 	def timers
 
@@ -29,11 +36,13 @@ public class Thermostat {
 	Thermostat(Closure sendEvent, String id, String label, String displayName, int temperature, int currentCoolingSetpoint, int currentHeatingSetpoint, int coolingSetpoint, 
                    int thermostatSetpoint, int heatingSetpoint, List coolingSetpointRange, List thermostatSetpointRange, List heatingSetpointRange, 
                    List supportedThermostatFanModes, List supportedThermostatModes, String thermostatOperatingState, String thermostatFanMode, String thermostatMode,
-		   String climateName) {
+		   String climateName, String thermostatLatestMode, String thermostatLatestOperatingState, String thermostatLatestFanMode, int latestCoolingSetPoint,
+		   int latestThermostatSetPoint, int latestHeatingSetPoint) {
 		this.id = id
 		this.label = label
 		this.sendEvent = sendEvent
 		this.temperature = temperature
+		this.currentTemperature = currentTemperature
 		this.currentCoolingSetpoint = currentCoolingSetpoint
 		this.currentHeatingSetpoint = currentHeatingSetpoint
 		this.coolingSetpoint = coolingSetpoint
@@ -49,12 +58,19 @@ public class Thermostat {
 		this.thermostatMode = thermostatMode
 		this.currentThermostatMode = thermostatMode
 		this.climateName = climateName
+		this.thermostatLatestMode = thermostatLatestMode
+		this.thermostatLatestOperatingState = thermostatLatestOperatingState
+		this.thermostatLatestFanMode = thermostatLatestFanMode
+		this.latestHeatingSetPoint = latestHeatingSetPoint
+		this.latestThermostatSetPoint = latestThermostatSetPoint
+		this.latestCoolingSetPoint = latestCoolingSetPoint
 	}
 
 
 	//By Apps
 	def setCoolingSetpoint(int coolingSetpoint) {
 		if (this.coolingSetpoint != coolingSetpoint) {
+			this.latestCoolingSetPoint = coolingSetpoint
 			this.coolingSetpoint = coolingSetpoint
 			this.currentCoolingSetpoint = currentCoolingSetpoint
 			println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
@@ -63,8 +79,13 @@ public class Thermostat {
 		}
 	}
 
+	def setCoolingSetpoint(String coolingSetpoint) {
+		setCoolingSetpoint(coolingSetpoint.toInteger())
+	}
+
 	def setHeatingSetpoint(int heatingSetpoint) {
 		if (this.heatingSetpoint != heatingSetpoint) {
+			this.latestHeatingSetPoint = heatingSetpoint
 			this.heatingSetpoint = heatingSetpoint
 			this.currentHeatingSetpoint = currentHeatingSetpoint
 			println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
@@ -73,12 +94,17 @@ public class Thermostat {
 		}
 	}
 
+	def setHeatingSetpoint(String heatingSetpoint) {
+		setHeatingSetpoint(heatingSetpoint.toInteger())
+	}
+
 	def setSchedule() {
 		//Not implemented yet
 	}
 
 	def setThermostatFanMode(String thermostatFanMode) {
 		if (this.thermostatFanMode != thermostatFanMode) {
+			this.thermostatLatestFanMode = thermostatFanMode
 			this.thermostatFanMode = thermostatFanMode
 			println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
 			sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
@@ -88,6 +114,7 @@ public class Thermostat {
 
 	def setThermostatMode(String thermostatMode) {
 		if (this.thermostatMode != thermostatMode) {
+			this.thermostatLatestMode =thermostatMode
 			this.thermostatMode = thermostatMode
 			this.currentThermostatMode = currentThermostatMode
 			println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
@@ -98,6 +125,7 @@ public class Thermostat {
 
 	def cool() {
 		if (this.thermostatMode != "cool") {
+			this.thermostatLatestMode = "cool"
 			this.thermostatMode = "cool"
 			this.currentThermostatMode = "cool"
 			println("Mode of the thermostat with id:$id is changed to cool!")
@@ -108,6 +136,7 @@ public class Thermostat {
 
 	def heat() {
 		if (this.thermostatMode != "heat") {
+			this.thermostatLatestMode = "heat"
 			this.thermostatMode = "heat"
 			this.currentThermostatMode = "heat"
 			println("Mode of the thermostat with id:$id is changed to heat!")
@@ -118,6 +147,7 @@ public class Thermostat {
 
 	def auto() {
 		if (this.thermostatMode != "auto") {
+			this.thermostatLatestMode = "auto"
 			this.thermostatMode = "auto"
 			this.currentThermostatMode = "auto"
 			println("Mode of the thermostat with id:$id is changed to auto!")
@@ -128,6 +158,7 @@ public class Thermostat {
 
 	def off() {
 		if (this.thermostatMode != "off") {
+			this.thermostatLatestMode = "off"
 			this.thermostatMode = "off"
 			this.currentThermostatMode = "off"
 			println("Mode of the thermostat with id:$id is changed to off!")
@@ -151,33 +182,74 @@ public class Thermostat {
 			this.heatingSetpoint = heatingSetpoint
 			this.currentHeatingSetpoint = currentHeatingSetpoint
 			println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+			sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
 	//By Model Checker
 	def setValue(String value, String name) {
-		if ((name == "temperature") && (value != this.temperature)) {
+		if ((name == "temperature") && (value.toInteger() != this.temperature)) {
 			println("the temperature is $value!")
 			this.temperature = value.toInteger()
-		} else if ((name == "heatingSetpoint") && (value != this.heatingSetpoint)) {
+			this.currentTemperature = value.toInteger()
+		} else if ((name == "heatingSetpoint") && (value.toInteger() != this.heatingSetpoint)) {
 			println("the heating set point of the thermostat with id:$id is $value!")
+			this.latestHeatingSetPoint = value.toInteger()
 			this.heatingSetpoint = value.toInteger()
-		} else if ((name == "coolingSetpoint") && (value != this.coolingSetpoint)) {
+		} else if ((name == "coolingSetpoint") && (value.toInteger() != this.coolingSetpoint)) {
 			println("the cooling set point of the thermostat with id:$id is $value!")
+			this.latestCoolingSetPoint = value.toInteger()
 			this.coolingSetpoint = value.toInteger()
-		} else if ((name == "thermostatSetpoint") && (value != this.thermostatSetpoint)) {
+		} else if ((name == "thermostatSetpoint") && (value.toInteger() != this.thermostatSetpoint)) {
 			println("the set point of the thermostat with id:$id is $value!")
+			this.latestThermostatSetPoint = value.toInteger()
 			this.thermostatSetpoint = value.toInteger()
 		} else if ((name == "thermostatMode") && (value != this.thermostatMode)) {
 			println("the mode of the thermostat with id:$id is $value!")
+			this.thermostatLatestMode = value
 			this.thermostatMode = value
 		} else if ((name == "thermostatFanMode") && (value != this.thermostatFanMode)) {
 			println("the fan mode of the thermostat with id:$id is $value!")
+			this.thermostatLatestFanMode = value
 			this.thermostatFanMode = value
 		} else if ((name == "thermostatOperatingState") && (value != this.thermostatOperatingState)) {
 			println("the operating state of the thermostat with id:$id is $value!")
+			this.thermostatLatestOperatingState = value
 			this.thermostatOperatingState = value
 		}
 	}
 
+	def currentValue(String deviceFeature) {
+		if (deviceFeature == "thermostatMode")
+			return thermostatMode
+		else if (deviceFeature == "thermostatOperatingState")
+			return thermostatOperatingState
+		else if (deviceFeature == "thermostatFanMode")
+			return thermostatFanMode
+		else if (deviceFeature == "heatingSetpoint")
+			return heatingSetpoint
+		else if (deviceFeature == "coolingSetpoint")
+			return coolingSetpoint
+		else if (deviceFeature == "thermostatSetpoint")
+			return thermostatSetpoint
+	}
+
+	def latestValue(String deviceFeature) {
+		if (deviceFeature == "thermostatMode")
+			return thermostatLatestMode
+		else if (deviceFeature == "thermostatOperatingState")
+			return thermostatLatestOperatingState
+		else if (deviceFeature == "thermostatFanMode")
+			return thermostatLatestFanMode
+		else if (deviceFeature == "heatingSetpoint")
+			return latestHeatingSetPoint
+		else if (deviceFeature == "coolingSetpoint")
+			return latestCoolingSetPoint
+		else if (deviceFeature == "thermostatSetpoint")
+			return latestThermostatSetPoint
+	}
+
 }
diff --git a/Thermostat/Thermostats.groovy b/Thermostat/Thermostats.groovy
index 19f5d6f..d8f7ada 100644
--- a/Thermostat/Thermostats.groovy
+++ b/Thermostat/Thermostats.groovy
@@ -16,6 +16,7 @@ public class Thermostats{
 	private String label = "thermostat0"
 	private String displayName = "thermostat0"
 	private int temperature = 66
+	private int currentTemperature = 66
 	private int currentCoolingSetpoint = 70
 	private int currentHeatingSetpoint = 50
 	private int coolingSetpoint = 70
@@ -31,6 +32,13 @@ public class Thermostats{
 	private String thermostatMode = "auto"
 	private String currentThermostatMode = "auto"
 	private String climateName = ""
+	private String thermostatLatestMode = "auto"
+	private String thermostatLatestOperatingState = "cooling"
+	private String thermostatLatestFanMode = "auto"
+	private int latestCoolingSetPoint = 70
+	private int latestThermostatSetPoint = 60
+	private int latestHeatingSetPoint = 50
+
 
 	Thermostats(Closure sendEvent, int deviceNumbers) {
 		this.sendEvent = sendEvent
@@ -40,6 +48,7 @@ public class Thermostats{
 
 		def initTemperature = Verify.getIntFromList(60, 66, 70)
 		this.temperature = initTemperature
+		this.currentTemperature = initTemperature
 		
 		def initCoolingSetpoint = Verify.getIntFromList(70, 80, 90)
 		this.currentCoolingSetpoint = initCoolingSetpoint
@@ -55,38 +64,50 @@ public class Thermostats{
 		def initFanMode = Verify.getInt(0,4)
 		if (initFanMode == 0) {
 			this.thermostatFanMode = "auto"
+			this.thermostatLatestFanMode = "auto"
 		} else if (initFanMode == 1) {
 			this.thermostatFanMode = "fanCirculate"
+			this.thermostatLatestFanMode = "fanCirculate"
 		} else if (initFanMode == 2) {
 			this.thermostatFanMode = "circulate"
+			this.thermostatLatestFanMode = "circulate"
 		} else if (initFanMode == 3) {
 			this.thermostatFanMode = "fanOn"
+			this.thermostatLatestFanMode = "fanOn"
 		} else {
 			this.thermostatFanMode = "on"
+			this.thermostatLatestFanMode = "on"
 		}
 
 		def initMode = Verify.getInt(0,4)
 		if (initMode == 0) {
 			this.thermostatMode = "auto"
 			this.currentThermostatMode = "auto"
+			this.thermostatLatestMode = "auto"
 		} else if (initMode == 1) {
 			this.thermostatMode = "cool"
 			this.currentThermostatMode = "cool"
+			this.thermostatLatestMode = "cool"
 		} else if (initMode == 2) {
 			this.thermostatMode = "emergencyHeat"
 			this.currentThermostatMode = "emergencyHeat"
+			this.thermostatLatestMode = "emergencyHeat"
 		} else if (initMode == 3) {
 			this.thermostatMode = "heat"
 			this.currentThermostatMode = "heat"
+			this.thermostatLatestMode = "heat"
 		} else {
 			this.thermostatMode = "off"
 			this.currentThermostatMode = "off"
+			this.thermostatLatestMode = "off"
 		}
 
 		thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint, 
                                                this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
                                                this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
-                                               this.thermostatOperatingState, this.thermostatFanMode,  this.thermostatMode, this.climateName))
+                                               this.thermostatOperatingState, this.thermostatFanMode,  this.thermostatMode, this.climateName, 
+					       this.thermostatLatestMode, this.thermostatLatestOperatingState, this.thermostatLatestFanMode, this.latestCoolingSetPoint,
+		   			       this.latestThermostatSetPoint, this.latestHeatingSetPoint))
 	}
 
 	//Methods for closures
@@ -102,6 +123,9 @@ public class Thermostats{
 	def find(Closure Input) {
 		thermostats.find(Input)
 	}
+	def sort(Closure Input) {
+		thermostats.sort(Input)
+	}
 	def collect(Closure Input) {
 		thermostats.collect(Input)
 	}
@@ -109,136 +133,167 @@ public class Thermostats{
 	//By Apps
 	def setCoolingSetpoint(int coolingSetpoint) {
 		if (coolingSetpoint != this.coolingSetpoint) {
-			thermostats[0].setCoolingSetpoint(coolingSetpoint)
+			this.latestCoolingSetPoint = coolingSetpoint
 			this.currentCoolingSetpoint = coolingSetpoint
 			this.coolingSetpoint = coolingSetpoint
+			thermostats[0].setCoolingSetpoint(coolingSetpoint)
 		}
 	}
 
+	def setCoolingSetpoint(String coolingSetpoint) {
+		setCoolingSetpoint(coolingSetpoint.toInteger())
+	}
+
 	def setHeatingSetpoint(int heatingSetpoint) {
 		if (heatingSetpoint != this.heatingSetpoint) {
-			thermostats[0].setHeatingSetpoint(heatingSetpoint)
+			this.latestHeatingSetPoint = heatingSetpoint
 			this.currentHeatingSetpoint = heatingSetpoint
 			this.heatingSetpoint = heatingSetpoint
+			thermostats[0].setHeatingSetpoint(heatingSetpoint)
 		}
 	}
 
+	def setHeatingSetpoint(String heatingSetpoint) {
+		setHeatingSetpoint(heatingSetpoint.toInteger())
+	}
+
 	def setSchedule() {
 		//Not implemented yet
 	}
 
 	def setThermostatFanMode(String thermostatFanMode) {
 		if (thermostatFanMode != this.thermostatFanMode) {
-			thermostats[0].setThermostatFanMode(thermostatFanMode)
+			this.thermostatLatestFanMode = thermostatFanMode
 			this.thermostatFanMode = thermostatFanMode
+			thermostats[0].setThermostatFanMode(thermostatFanMode)
 		}
 	}
 
 	def setThermostatMode(String thermostatMode) {
 		if (thermostatMode != this.thermostatMode) {
-			thermostats[0].setThermostatMode(thermostatMode)
+			this.thermostatLatestMode = thermostatMode
 			this.thermostatMode = thermostatMode
 			this.currentThermostatMode = currentThermostatMode
+			thermostats[0].setThermostatMode(thermostatMode)
 		}
 	}
 
 	def cool() {
 		if (thermostatMode != "cool") {
-			thermostats[0].cool()
+			this.thermostatLatestMode = "cool"
 			this.thermostatMode = "cool"
 			this.currentThermostatMode = "cool"
+			thermostats[0].cool()
 		}
 	}
 
 	def heat() {
 		if (thermostatMode != "heat") {
-			thermostats[0].heat()
+			this.thermostatLatestMode = "heat"
 			this.thermostatMode = "heat"
 			this.currentThermostatMode = "heat"
+			thermostats[0].heat()
 		}
 	}
 
 	def auto() {
 		if (thermostatMode != "auto") {
-			thermostats[0].auto()
+			this.thermostatLatestMode = "auto"
 			this.thermostatMode = "auto"
 			this.currentThermostatMode = "auto"
+			thermostats[0].auto()
 		}
 	}
 
 	def off() {
 		if (thermostatMode != "off") {
-			thermostats[0].off()
+			this.thermostatLatestMode = "off"
 			this.thermostatMode = "off"
 			this.currentThermostatMode = "off"
+			thermostats[0].off()
 		}
 	}
 
 	def setClimate(String info, String givenClimateName) {
 		if (givenClimateName != climateName) {
-			thermostats[0].setClimate(info, givenClimateName)
 			this.climateName = givenClimateName
+			thermostats[0].setClimate(info, givenClimateName)
 		}
 	}
 
 	def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
 		if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
-			thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
 			this.currentCoolingSetpoint = coolingSetpoint
 			this.coolingSetpoint = coolingSetpoint
 			this.currentHeatingSetpoint = heatingSetpoint
 			this.heatingSetpoint = heatingSetpoint
+			thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
 		}
 	}
 
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["name"] == "temperature") {
-			if (eventDataMap["value"] != thermostats[0].temperature) {
+			if (eventDataMap["value"].toInteger() != thermostats[0].temperature) {
+				this.temperature = eventDataMap["value"].toInteger()
+				this.currentTemperature = eventDataMap["value"].toInteger()
 				thermostats[0].setValue(eventDataMap["value"], "temperature")
-				this.temperature = thermostats[0].temperature
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "heatingSetpoint") {
-			if (eventDataMap["value"] != thermostats[0].heatingSetpoint) {
+			if (eventDataMap["value"].toInteger() != thermostats[0].heatingSetpoint) {
+				this.latestHeatingSetpoint = eventDataMap["value"].toInteger()
+				this.heatingSetpoint = eventDataMap["value"].toInteger()
 				thermostats[0].setValue(eventDataMap["value"], "heatingSetpoint")
-				this.heatingSetpoint = thermostats[0].heatingSetpoint
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "coolingSetpoint") {
-			if (eventDataMap["value"] != thermostats[0].coolingSetpoint) {
+			if (eventDataMap["value"].toInteger() != thermostats[0].coolingSetpoint) {
+				this.latestCoolingSetPoint = eventDataMap["value"].toInteger()
+				this.coolingSetpoint = eventDataMap["value"].toInteger()
 				thermostats[0].setValue(eventDataMap["value"], "coolingSetpoint")
-				this.coolingSetpoint = thermostats[0].coolingSetpoint
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "thermostatSetpoint") {
-			if (eventDataMap["value"] != thermostats[0].thermostatSetpoint) {
+			if (eventDataMap["value"].toInteger() != thermostats[0].thermostatSetpoint) {
+				this.latestThermostatSetpoint = eventDataMap["value"].toInteger()
+				this.thermostatSetpoint = eventDataMap["value"].toInteger()
 				thermostats[0].setValue(eventDataMap["value"], "thermostatSetpoint")
-				this.thermostatSetpoint = thermostats[0].thermostatSetpoint
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "thermostatMode") {
 			if (eventDataMap["value"] != thermostats[0].thermostatMode) {
+				this.thermostatLatestMode = eventDataMap["value"]
+				this.thermostatMode = eventDataMap["value"]
+				this.currentThermostatMode = eventDataMap["value"]
 				thermostats[0].setValue(eventDataMap["value"], "thermostatMode")
-				this.thermostatMode = thermostats[0].thermostatMode
-				this.currentThermostatMode = thermostats[0].currentThermostatMode
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "thermostatFanMode") {
 			if (eventDataMap["value"] != thermostats[0].thermostatFanMode) {
+				this.thermostatLatestFanMode = eventDataMap["value"]
+				this.thermostatFanMode = eventDataMap["value"]
 				thermostats[0].setValue(eventDataMap["value"], "thermostatFanMode")
-				this.thermostatFanMode = thermostats[0].thermostatFanMode
 				sendEvent(eventDataMap)
 			}
 		} else if (eventDataMap["name"] == "thermostatOperatingState") {
 			if (eventDataMap["value"] != thermostats[0].thermostatOperatingState) {
+				this.thermostatLatestOperatingState = eventDataMap["value"]
+				this.thermostatOperatingState = eventDataMap["value"]
 				thermostats[0].setValue(eventDataMap["value"], "thermostatOperatingState")
-				this.thermostatOperatingState = thermostats[0].thermostatOperatingState
 				sendEvent(eventDataMap)
 			}
 		}
 	}
 
+	def currentValue(String deviceFeature) {
+		thermostats[0].currentValue(deviceFeature)
+	}
+
+	def latestValue(String deviceFeature) {
+		thermostats[0].latestValue(deviceFeature)
+	}
+
 	def getAt(int ix) {
 		thermostats[ix]
 	}
diff --git a/Timer/SimulatedTimer.groovy b/Timer/SimulatedTimer.groovy
index cf123be..96b356e 100644
--- a/Timer/SimulatedTimer.groovy
+++ b/Timer/SimulatedTimer.groovy
@@ -22,6 +22,19 @@ public class SimulatedTimer {
 		closure()
 	}
 
+	def runAfter(long delay, Closure closure) {
+		/*thread = new Thread() {
+	
+			@Override
+			public void run() {
+				Thread.sleep(delay)
+				closure()
+			}
+		}.start()
+		return thread*/
+		closure()
+	}
+
 	def cancel() {
 		//if (thread != null)
 		//	thread.stop()
diff --git a/Valve/Valve.groovy b/Valve/Valve.groovy
index 4aaf5b3..75efd8a 100644
--- a/Valve/Valve.groovy
+++ b/Valve/Valve.groovy
@@ -26,10 +26,12 @@ public class Valve {
 	def open() {
 		if (valve != "open") {
 			println("the valve with id:$id is open!")
-			this.valveLatestValue = this.valve
+			this.valveLatestValue = "open"
 			this.valve = "open"
 			sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
 			           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
+				           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -37,10 +39,12 @@ public class Valve {
 		if (valve != "open") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the valve with id:$id is open!")
-				this.valveLatestValue = this.valve
+				this.valveLatestValue = "open"
 				this.valve = "open"
 				sendEvent([name: "contact", value: "open", deviceId: this.id, descriptionText: "",
 				           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "contact.open", value: "open", deviceId: this.id, descriptionText: "",
+				           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -48,10 +52,12 @@ public class Valve {
 	def close() {
 		if (valve != "closed") {
 			println("the valve with id:$id is closed!")
-			this.valveLatestValue = this.valve
+			this.valveLatestValue = "closed"
 			this.valve = "closed"
 			sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
 			           displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
+				            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 		}
 	}
 
@@ -59,10 +65,12 @@ public class Valve {
 		if (valve != "closed") {
 			def task = timers.runAfter(metaData["delay"]) {
 				println("the valve with id:$id is closed!")
-				this.valveLatestValue = this.valve
+				this.valveLatestValue = "closed"
 				this.valve = "closed"
 				sendEvent([name: "contact", value: "closed", deviceId: this.id, descriptionText: "",
 				            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+				sendEvent([name: "contact.closed", value: "closed", deviceId: this.id, descriptionText: "",
+				            displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			}
 		}
 	}
@@ -70,7 +78,7 @@ public class Valve {
 	//By Model Checker
 	def setValue(String value) {
 		println("the valve with id:$id is $value!")
-		this.valveLatestValue = this.valve
+		this.valveLatestValue = value
 		this.valve = value
 	}
 	
diff --git a/Valve/Valves.groovy b/Valve/Valves.groovy
index 7e8b220..e5d0559 100644
--- a/Valve/Valves.groovy
+++ b/Valve/Valves.groovy
@@ -37,32 +37,45 @@ public class Valves {
 	def find(Closure Input) {
 		valves.find(Input)
 	}
+	def sort(Closure Input) {
+		valves.sort(Input)
+	}
 	def collect(Closure Input) {
 		valves.collect(Input)
 	}
 
 	//By Apps
 	def open() {
-		if (valve != "open")
+		if (valve != "open") {
+			this.valve = "open"
+			this.valveLatestValue = "open"
 			valves[0].open()
+		}
 	}
 
 	def open(LinkedHashMap metaData) {
 		if (valve != "open") {
 			def task = timers.runAfter(metaData["delay"]) {
+				this.valve = "open"
+				this.valveLatestValue = "open"
 				valves[0].open()
 			}
 		}
 	}
 
 	def close() {
-		if (valve != "closed")
+		if (valve != "closed") {
+			this.valve = "closed"
+			this.valveLatestValue = "closed"			
 			valves[0].close()
+		}
 	}
 
 	def close(LinkedHashMap metaData) {
 		if (valve != "closed") {
 			def task = timers.runAfter(metaData["delay"]) {
+				this.valve = "closed"
+				this.valveLatestValue = "closed"
 				valves[0].close()
 			}
 		}
@@ -71,8 +84,8 @@ public class Valves {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != valves[0].valve) {
+			this.valve = eventDataMap["value"]
 			valves[0].setValue(eventDataMap["value"])
-			this.valve = valves[0].valve
 		}
 	}
 
diff --git a/Variables and events for each device b/Variables and events for each device
index 7933983..66e3f51 100644
--- a/Variables and events for each device	
+++ b/Variables and events for each device	
@@ -27,6 +27,10 @@ contactObject.setValue([name: "contact", value: "open", deviceId: "contactSensor
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 contactObject.setValue([name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "tamper.tampered", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "tamper.tampered", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -88,6 +92,10 @@ motionSensorObject.setValue([name: "motion", value: "active", deviceId: "motionS
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 motionSensorObject.setValue([name: "motion", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+motionSensorObject.setValue([name: "motion.active", value: "active", deviceId: "motionSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+motionSensorObject.setValue([name: "motion.inactive", value: "inactive", deviceId: "motionSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -146,11 +154,17 @@ smokeDetectorObject.setValue([name: "smoke", value: "detected", deviceId: "smoke
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 smokeDetectorObject.setValue([name: "smoke", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-smokeDetectorObject.setValue([name: "carbonMonoxide", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+smokeDetectorObject.setValue([name: "smoke.clear", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "smoke.detected", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-smokeDetectorObject.setValue([name: "carbonMonoxide", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+smokeDetectorObject.setValue([name: "smoke.tested", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-smokeDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
+smokeDetectorObject.setValue([name: "carbonMonoxide.clear", value: "clear", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "carbonMonoxide.detected", value: "detected", deviceId: "smokeDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+smokeDetectorObject.setValue([name: "carbonMonoxide.tested", value: "tested", deviceId: "smokeDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 smokeDetectorObject.setValue([name: "battery", value: "5"/*A number between 0 to 100 as a charge*/, deviceId: "smokeDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
@@ -241,7 +255,7 @@ displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "
 
 //For appTouch:
 /*events*/
-appObject.setValue([name: "Touched", value: "touched", deviceId: "touchedSensorID0", descriptionText: "",
+appObject.setValue([name: "Touched", value: "touched", deviceId: "appID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
@@ -279,6 +293,10 @@ accelerationSensorObject.setValue([name: "acceleration", value: "active", device
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 accelerationSensorObject.setValue([name: "acceleration", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+accelerationSensorObject.setValue([name: "acceleration.active", value: "active", deviceId: "accelerationSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+accelerationSensorObject.setValue([name: "acceleration.inactive", value: "inactive", deviceId: "accelerationSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
@@ -317,6 +335,12 @@ carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "detected"
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide", value: "tested", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide.clear", value: "clear", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide.detected", value: "detected", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+carbonMonoxideDetectorObject.setValue([name: "carbonMonoxide.tested", value: "tested", deviceId: "carbonMonoxideDetectorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /*events*/
 //
 -------------------------------------------------------------------------------
@@ -333,6 +357,14 @@ colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "level", value: "50", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch", value: "on", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch", value: "off", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "colorTemperature", value: "50", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /*events*/
 //
 -------------------------------------------------------------------------------
@@ -464,6 +496,10 @@ waterSensorObject.setValue([name: "water", value: "dry", deviceId: "waterSensorI
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 waterSensorObject.setValue([name: "water", value: "wet", deviceId: "waterSensorID0", descriptionText: "",
 displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+waterSensorObject.setValue([name: "water.dry", value: "dry", deviceId: "waterSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+waterSensorObject.setValue([name: "water.wet", value: "wet", deviceId: "waterSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 /////
 /*events*/
 //
diff --git a/WaterSensor/WaterSensors.groovy b/WaterSensor/WaterSensors.groovy
index 10a4cfd..0e7357b 100644
--- a/WaterSensor/WaterSensors.groovy
+++ b/WaterSensor/WaterSensors.groovy
@@ -25,8 +25,8 @@ public class WaterSensors {
 	//By Model Checker
 	def setValue(LinkedHashMap eventDataMap) {
 		if (eventDataMap["value"] != waterSensors[0].water) {
+			this.water = eventDataMap["value"]
 			waterSensors[0].setValue(eventDataMap["value"])
-			this.water = waterSensors[0].water
 			sendEvent(eventDataMap)
 		}
 	}
@@ -44,6 +44,9 @@ public class WaterSensors {
 	def find(Closure Input) {
 		waterSensors.find(Input)
 	}
+	def sort(Closure Input) {
+		waterSensors.sort(Input)
+	}
 	def collect(Closure Input) {
 		waterSensors.collect(Input)
 	}
diff --git a/appTouch/Touched.groovy b/appTouch/Touched.groovy
index e4310fe..1d9e57f 100644
--- a/appTouch/Touched.groovy
+++ b/appTouch/Touched.groovy
@@ -3,13 +3,15 @@ package appTouch
 
 public class Touched{
 	def sendEvent
+	private String id
 	private int isTouched
 	private String label
 
 	Touched(Closure sendEvent, int isTouched) {
 		this.sendEvent = sendEvent
 		this.isTouched = isTouched
-		this.label = "App"
+		this.label = "app0"
+		this.id = "appID0"
 	}
 
 	//By Model Checker
diff --git a/eventSimulator/colorChangeEvent.groovy b/eventSimulator/colorChangeEvent.groovy
new file mode 100644
index 0000000..5ed3b4f
--- /dev/null
+++ b/eventSimulator/colorChangeEvent.groovy
@@ -0,0 +1,2 @@
+			colorControlObject.setValue([name: "color", value: "red", deviceId: "colorControlID0", descriptionText: "",
+					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/colorChangedEvent.groovy b/eventSimulator/colorChangedEvent.groovy
deleted file mode 100644
index 5ed3b4f..0000000
--- a/eventSimulator/colorChangedEvent.groovy
+++ /dev/null
@@ -1,2 +0,0 @@
-			colorControlObject.setValue([name: "color", value: "red", deviceId: "colorControlID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/eventSimulator.groovy b/eventSimulator/eventSimulator.groovy
index 82cbd6a..0a04773 100644
--- a/eventSimulator/eventSimulator.groovy
+++ b/eventSimulator/eventSimulator.groovy
@@ -1,31 +1,29 @@
 while(true) {
-	def eventNumber = Verify.getInt(0,4)
+	def eventNumber = Verify.getInt(0,5)
 	switch(eventNumber) {
 		case 0:
-			lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			def event = Verify.getInt(0,1)
+			if (event == 0) {
+					switchObject.setValue([name: "switch", value: "on", deviceId: "switchID0", descriptionText: "",
+							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			} else {
+					switchObject.setValue([name: "switch", value: "off", deviceId: "switchID0", descriptionText: "",
+							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+			}
 			break
 		case 1:
-			lockObject.setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			break
 		case 2:
-			contactObject.setValue([name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+			colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", descriptionText: "",
 					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			break
 		case 3:
-			contactObject.setValue([name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+			colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
 					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 			break
 		case 4:
-			def event = Verify.getInt(0,1)
-			if (event == 0) {
-					presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
-							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
-			} else {
-					presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
-							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
-			}
+			break
+		case 5:
 			break
 	}
 }
diff --git a/eventSimulator/hueChangeEvent.groovy b/eventSimulator/hueChangeEvent.groovy
new file mode 100644
index 0000000..b5d20d2
--- /dev/null
+++ b/eventSimulator/hueChangeEvent.groovy
@@ -0,0 +1,2 @@
+			colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", descriptionText: "",
+					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/hueChangedEvent.groovy b/eventSimulator/hueChangedEvent.groovy
deleted file mode 100644
index b5d20d2..0000000
--- a/eventSimulator/hueChangedEvent.groovy
+++ /dev/null
@@ -1,2 +0,0 @@
-			colorControlObject.setValue([name: "hue", value: "50", deviceId: "colorControlID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/saturationChangeEvent.groovy b/eventSimulator/saturationChangeEvent.groovy
new file mode 100644
index 0000000..5327de2
--- /dev/null
+++ b/eventSimulator/saturationChangeEvent.groovy
@@ -0,0 +1,2 @@
+			colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
+					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/eventSimulator/saturationChangedEvent.groovy b/eventSimulator/saturationChangedEvent.groovy
deleted file mode 100644
index 5327de2..0000000
--- a/eventSimulator/saturationChangedEvent.groovy
+++ /dev/null
@@ -1,2 +0,0 @@
-			colorControlObject.setValue([name: "saturation", value: "50", deviceId: "colorControlID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
diff --git a/main.groovy b/main.groovy
index a1474f1..953f33f 100644
--- a/main.groovy
+++ b/main.groovy
@@ -70,7 +70,6 @@ import Valve.Valves
 import MobilePresence.MobilePresence
 import MobilePresence.MobilePresences
 import Event.Event
-import AtomicState.AtomicState
 import Timer.SimulatedTimer
 
 //JPF's Verify API
@@ -92,14 +91,24 @@ def eventHandler(LinkedHashMap eventDataMap) {
 	for (int i = 0;i < app2.eventList.size();i++) {
 		if (app2.eventList[i] == name) {
 			def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-			app2.functionList[i](event)
+			if (app2.functionList[i] instanceof String) {
+				String toCall = app2.functionList[i]
+				app2."$toCall"(event)
+			}
+			else
+				app2.functionList[i](event)
 		}
 	}
 
 	for (int i = 0;i < app1.eventList.size();i++) {
 		if (app1.eventList[i] == name) {
 			def event = new Event(value, name, deviceId, descriptionText, displayed, linkText, linkText, isStateChange, unit, data)
-			app1.functionList[i](event)
+			if (app1.functionList[i] instanceof String) {
+				String toCall = app1.functionList[i]
+				app1."$toCall"(event)
+			}
+			else
+				app1.functionList[i](event)
 		}
 	}
 }
@@ -115,8 +124,6 @@ def eventHandler(LinkedHashMap eventDataMap) {
 @Field def appObject = new Touched(sendEvent, 0)
 //Create a global list for events
 //@Field def evt = []
-//Global Object for class AtomicState!
-@Field def atomicState = new AtomicState()
 //Global Object for class Touch Sensor!
 @Field def touchSensorObject = new NfcTouch(sendEvent, 1)
 //Global Object for class switch!
@@ -185,45 +192,51 @@ class App1 {
 	def reference
 	def location
 	def app
-	def atomicState
 
 	//Extracted objects for App1
-	//Object for class lock!
-	def lock1
-	//Object for class contactSensor!
-	def contact
-	//Global variable for number!
-	def minutesLater = 70
-	//Global variable for number!
-	def secondsLater = 93
-	//Global variable for contact!
-	def recipients = "AJ"
-	//Global variable for phone!
-	def phoneNumber = 9495379373
+	//Object for class color control!
+	def master
+	//Object for class color control!
+	def slaves
+	//Global variable for boolean!
+	def randomYes = "1"
 
 	//Extracted objects for functions for App1
 	//Global Object for functions in subscribe method!
+	def mainPage = this.&mainPage
+	//Global Object for functions in subscribe method!
 	def installed = this.&installed
 	//Global Object for functions in subscribe method!
 	def updated = this.&updated
 	//Global Object for functions in subscribe method!
-	def initialize = this.&initialize
+	def init = this.&init
+	//Global Object for functions in subscribe method!
+	def onOffHandler = this.&onOffHandler
+	//Global Object for functions in subscribe method!
+	def colorHandler = this.&colorHandler
+	//Global Object for functions in subscribe method!
+	def getRandomColorMaster = this.&getRandomColorMaster
+	//Global Object for functions in subscribe method!
+	def tempHandler = this.&tempHandler
+	//Global Object for functions in subscribe method!
+	def textAppName = this.&textAppName
+	//Global Object for functions in subscribe method!
+	def textVersion = this.&textVersion
 	//Global Object for functions in subscribe method!
-	def lockDoor = this.&lockDoor
+	def textCopyright = this.&textCopyright
 	//Global Object for functions in subscribe method!
-	def unlockDoor = this.&unlockDoor
+	def textLicense = this.&textLicense
 	//Global Object for functions in subscribe method!
-	def doorHandler = this.&doorHandler
+	def textHelp = this.&textHelp
 
 	App1(Object obj) {
 		reference = obj
 		location = obj.locationObject
 		app = obj.appObject
-		atomicState = obj.atomicState
-		lock1 = obj.lockObject
-		contact = obj.contactObject
+		master = obj.colorControlObject
+		slaves = obj.colorControlObject
 		//Global variable for settings!
-		settings = [app:app, lock1:lock1, contact:contact, minutesLater:minutesLater, secondsLater:secondsLater, recipients:recipients, phoneNumber:phoneNumber]
+		settings = [app: app, master: master, slaves: slaves, randomYes: randomYes, END: "END"]
 	}
 	//Global variables for each app
 	//Global variable for state[mode]
@@ -244,11 +257,16 @@ class App1 {
 	def settings
 	//Zip code
 	def zipCode = 92617
+	//atomicState variable
+	def atomicState = [version: "1.01"]
 
 	//Methods
 	/////////////////////////////////////////////////////////////////////
 	def setLocationMode(String mode) {
-		location.mode = mode
+		location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 	}
 	
 	/////////////////////////////////////////////////////////////////////
@@ -270,6 +288,12 @@ class App1 {
 		eventList.add(event)
 		functionList.add(FunctionToCall)
 	}
+	////subscribe(obj, event, nameOfFunc)
+	def subscribe(Object obj, String event, String nameOfFunction) {
+		objectList.add(obj)
+		eventList.add(event)
+		functionList.add(nameOfFunction)
+	}
 	////subscribe(obj, event, func, data)
 	def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
 		objectList.add(obj)	
@@ -315,6 +339,17 @@ class App1 {
 		}
 	}
 	
+	def unschedule(String nameOfFunctionToUnschedule) {
+		for (int i = 0;i < timersFuncList.size();i++) {
+			if (timersFuncList[i] instanceof String) {
+				if (timersFuncList[i] == nameOfFunctionToUnschedule) {
+					if (timersList != null)
+						timersList[i].cancel()
+				}
+			}
+		}
+	}
+	
 	
 	def unschedule() {
 		for (int i = 0;i < timersFuncList.size();i++) {
@@ -333,6 +368,16 @@ class App1 {
 			}
 		}
 	}
+	
+	def sendNotificationToContacts(String text, String recipients, LinkedHashMap metaData) {
+		for (int i = 0;i < recipients.size();i++) {
+			for (int j = 0;j < location.contacts.size();j++) {
+				if (recipients[i] == location.contacts[j]) {
+					println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
+				}
+			}
+		}
+	}
 	/////////////////////////////////////////////////////////////////////
 	////sendSms(phone, text)
 	def sendSms(long phoneNumber, String text) {
@@ -435,92 +480,161 @@ class App1 {
 	def canSchedule() {
 		return true
 	}
+	/////////////////////////////////////////////////////////////////////
+	def createAccessToken() {
+		state.accessToken = "accessToken"
+		return state.accessToken
+	}
+	/////////////////////////////////////////////////////////////////////
+	def runOnce(Date date, Closure methodToCall) {
+		methodTocall()
+	}
 
-	def installed(){
-	    initialize()
+	def mainPage() {
+		section("Master Light") {
+			input "master", "capability.colorControl", title: "Colored Light", required: true
+		}
+		section("Lights that follow the master settings") {
+			input "slaves", "capability.colorControl", title: "Colored Lights",  multiple: true, required: true, submitOnChange: true
+		}
+	    	section([mobileOnly:true], "Options") {
+			input "randomYes", "bool",title: "When Master Turned On, Randomize Color", defaultValue: false
+			href "pageAbout", title: "About ${textAppName()}", description: "Tap to get application version, license and instructions"
+	        }
+		
+		dynamicPage(name: "mainPage", title: "", install: true, uninstall: false) {
+		def masterInList = slaves?.id?.find{it==master?.id}
+	        if (masterInList) {
+	        	section ("**WARNING**"){
+	            		paragraph "You have included the Master Light in the Slave Group. This will cause a loop in execution. Please remove this device from the Slave Group.", image: "https://raw.githubusercontent.com/MichaelStruck/SmartThingsPublic/master/img/caution.png"
+	            	}
+	        }
+	        
+		page(name: "pageAbout", title: "About ${textAppName()}", uninstall: true) {
+				section {
+					paragraph "${textVersion()}\n${textCopyright()}\n\n${textLicense()}\n"
+				}
+				section("Instructions") {
+					paragraph textHelp()
+				}
+				section("Tap button below to remove application"){
+				}
+			}
+			
+		}
+	}
+	
+	def installed() {   
+		init() 
 	}
 	
 	def updated(){
-	    unsubscribe()
-	    unschedule()
-	    initialize()
+		unsubscribe()
+	    init()
+	}
+	
+	def init() {
+	    subscribe(master, "switch", onOffHandler)
+	    subscribe(master, "level", colorHandler)
+	    subscribe(master, "hue", colorHandler)
+	    subscribe(master, "saturation", colorHandler)
+	    subscribe(master, "colorTemperature", tempHandler)
+	}
+	//-----------------------------------
+	def onOffHandler(evt){
+		if (slaves && master) {
+			if (!slaves?.id.find{it==master?.id}){
+			if (master?.currentValue("switch") == "on"){
+			    if (randomYes) getRandomColorMaster()
+					else slaves?.on()
+			}
+			else {
+			    slaves?.off()  
+			}
+			}
+		}
 	}
 	
-	def initialize(){
-	    log.debug "Settings: ${settings}"
-	    subscribe(lock1, "lock", doorHandler, [filterEvents: false])
-	    subscribe(lock1, "unlock", doorHandler, [filterEvents: false])  
-	    subscribe(contact, "contact.open", doorHandler)
-	    subscribe(contact, "contact.closed", doorHandler)
+	def colorHandler(evt) {
+		if (slaves && master) {
+			if (!slaves?.id?.find{it==master?.id} && master?.currentValue("switch") == "on"){
+				log.debug "Changing Slave units H,S,L"
+			def dimLevel = master?.currentValue("level")
+			def hueLevel = master?.currentValue("hue")
+			def saturationLevel = master.currentValue("saturation")
+				def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
+			slaves?.setColor(newValue)
+			try {
+				log.debug "Changing Slave color temp"
+				def tempLevel = master?.currentValue("colorTemperature")
+				slaves?.setColorTemperature(tempLevel)
+			}
+				catch (e){
+				log.debug "Color temp for master --"
+			}
+			}
+		}
 	}
 	
-	def lockDoor(){
-	    log.debug "Locking the door."
-	    lock1.lock()
-	    if(location.contactBookEnabled) {
-	        if ( recipients ) {
-	            log.debug ( "Sending Push Notification..." ) 
-	            sendNotificationToContacts( "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!", recipients)
-	        }
-	    }
-	    if (phoneNumber) {
-	        log.debug("Sending text message...")
-	        sendSms( phoneNumber, "${lock1} locked after ${contact} was closed for ${minutesLater} minutes!")
-	    }
+	def getRandomColorMaster(){
+	    def hueLevel = Math.floor(Math.random() *1000)
+	    def saturationLevel = Math.floor(Math.random() * 100)
+	    def dimLevel = master?.currentValue("level")
+		def newValue = [hue: hueLevel, saturation: saturationLevel, level: dimLevel as Integer]
+	    log.debug hueLevel
+	    log.debug saturationLevel
+	    master.setColor(newValue)
+	    slaves?.setColor(newValue)   
+	}
+	
+	def tempHandler(evt){
+		if (slaves && master) {
+		    if (!slaves?.id?.find{it==master?.id} && master?.currentValue("switch") == "on"){
+			if (evt.value != "--") {
+			    log.debug "Changing Slave color temp based on Master change"
+			    def tempLevel = master.currentValue("colorTemperature")
+			    slaves?.setColorTemperature(tempLevel)
+			}
+			}
+		}
 	}
 	
-	def unlockDoor(){
-	    log.debug "Unlocking the door."
-	    lock1.unlock()
-	    if(location.contactBookEnabled) {
-	        if ( recipients ) {
-	            log.debug ( "Sending Push Notification..." ) 
-	            sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!", recipients)
-	        }
-	    }
-	    if ( phoneNumber ) {
-	        log.debug("Sending text message...")
-	        sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened for ${secondsLater} seconds!")
-	    }
+	//Version/Copyright/Information/Help
+	
+	private def textAppName() {
+		def text = "Color Coordinator"
+	}	
+	
+	private def textVersion() {
+	    def text = "Version 1.1.1 (12/13/2016)"
 	}
 	
-	def doorHandler(evt){
-	    if ((contact.latestValue("contact") == "open") && (evt.value == "locked")) { // If the door is open and a person locks the door then...  
-	        //def delay = (secondsLater) // runIn uses seconds
-	        runIn( secondsLater, unlockDoor )   // ...schedule (in minutes) to unlock...  We don't want the door to be closed while the lock is engaged. 
-	    }
-	    else if ((contact.latestValue("contact") == "open") && (evt.value == "unlocked")) { // If the door is open and a person unlocks it then...
-	        unschedule( unlockDoor ) // ...we don't need to unlock it later.
-	    }
-	    else if ((contact.latestValue("contact") == "closed") && (evt.value == "locked")) { // If the door is closed and a person manually locks it then...
-	        unschedule( lockDoor ) // ...we don't need to lock it later.
-	    }   
-	    else if ((contact.latestValue("contact") == "closed") && (evt.value == "unlocked")) { // If the door is closed and a person unlocks it then...
-	       //def delay = (minutesLater * 60) // runIn uses seconds
-	        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-	    }
-	    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "open")) { // If a person opens an unlocked door...
-	        unschedule( lockDoor ) // ...we don't need to lock it later.
-	    }
-	    else if ((lock1.latestValue("lock") == "unlocked") && (evt.value == "closed")) { // If a person closes an unlocked door...
-	        //def delay = (minutesLater * 60) // runIn uses seconds
-	        runIn( (minutesLater * 60), lockDoor ) // ...schedule (in minutes) to lock.
-	    }
-	    else { //Opening or Closing door when locked (in case you have a handle lock)
-	        log.debug "Unlocking the door."
-	        lock1.unlock()
-	        if(location.contactBookEnabled) {
-	            if ( recipients ) {
-	                log.debug ( "Sending Push Notification..." ) 
-	                sendNotificationToContacts( "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!", recipients)
-	            }
-	        }
-	        if ( phoneNumber ) {
-	            log.debug("Sending text message...")
-	            sendSms( phoneNumber, "${lock1} unlocked after ${contact} was opened or closed when ${lock1} was locked!")
-	        }
-	    }
+	private def textCopyright() {
+	    def text = "Copyright © 2016 Michael Struck"
+	}
+	
+	private def textLicense() {
+	    def text =
+			"Licensed under the Apache License, Version 2.0 (the 'License'); "+
+			"you may not use this file except in compliance with the License. "+
+			"You may obtain a copy of the License at"+
+			"\n\n"+
+			"    http://www.apache.org/licenses/LICENSE-2.0"+
+			"\n\n"+
+			"Unless required by applicable law or agreed to in writing, software "+
+			"distributed under the License is distributed on an 'AS IS' BASIS, "+
+			"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. "+
+			"See the License for the specific language governing permissions and "+
+			"limitations under the License."
+	}
+	
+	private def textHelp() {
+		def text =
+	    	"This application will allow you to control the settings of multiple colored lights with one control. " +
+	        "Simply choose a master control light, and then choose the lights that will follow the settings of the master, "+
+	        "including on/off conditions, hue, saturation, level and color temperature. Also includes a random color feature."
 	}
+	
 }
 
 
@@ -529,99 +643,45 @@ class App2 {
 	def reference
 	def location
 	def app
-	def atomicState
 
 	//Extracted objects for App2
+	//Object for class contactSensor!
+	def deviceContactSensor
 	//Global variable for time!
-	def starting = "15:00"
-	//Global variable for time!
-	def ending = "15:00"
-	//Object for class beacon sensor!
-	def beacons
-	//Object for class mobile presence!
-	def phones
-	//Global variable for enum!
-	def arrivalPhrase = "Good Night!"
-	//Object for class switch!
-	def arrivalOnSwitches
-	//Object for class switch!
-	def arrivalOffSwitches
-	//Object for class lock!
-	def arrivalLocks
-	//Global variable for enum!
-	def departPhrase = "Good Night!"
-	//Object for class switch!
-	def departOnSwitches
-	//Object for class switch!
-	def departOffSwitches
-	//Object for class lock!
-	def departLocks
-	//Global variable for boolean!
-	def pushNotification = "0"
-	//Global variable for phone!
-	def phone = 9495379373
-	//Global variable for enum!
-	def days = "Monday"
-	//Global variable for mode!
-	def modes = "night"
+	def reminderTime = "15:00"
+	//Object for class color control!
+	def deviceLight
 
 	//Extracted objects for functions for App2
 	//Global Object for functions in subscribe method!
-	def mainPage = this.&mainPage
-	//Global Object for functions in subscribe method!
 	def installed = this.&installed
 	//Global Object for functions in subscribe method!
 	def updated = this.&updated
 	//Global Object for functions in subscribe method!
 	def initialize = this.&initialize
 	//Global Object for functions in subscribe method!
-	def beaconHandler = this.&beaconHandler
-	//Global Object for functions in subscribe method!
-	def arriveActions = this.&arriveActions
-	//Global Object for functions in subscribe method!
-	def departActions = this.&departActions
-	//Global Object for functions in subscribe method!
-	def prefix = this.&prefix
-	//Global Object for functions in subscribe method!
-	def listPhrases = this.&listPhrases
-	//Global Object for functions in subscribe method!
-	def executePhrase = this.&executePhrase
+	def contactHandler = this.&contactHandler
 	//Global Object for functions in subscribe method!
-	def getBeaconName = this.&getBeaconName
+	def checkOpenDrawInPast = this.&checkOpenDrawInPast
 	//Global Object for functions in subscribe method!
-	def getPhoneName = this.&getPhoneName
+	def checkOpenDrawAfterReminder = this.&checkOpenDrawAfterReminder
 	//Global Object for functions in subscribe method!
-	def hideOptionsSection = this.&hideOptionsSection
+	def sendNotification = this.&sendNotification
 	//Global Object for functions in subscribe method!
-	def getAllOk = this.&getAllOk
+	def isOpened = this.&isOpened
 	//Global Object for functions in subscribe method!
-	def getModeOk = this.&getModeOk
+	def setLEDNotification = this.&setLEDNotification
 	//Global Object for functions in subscribe method!
-	def getDaysOk = this.&getDaysOk
-	//Global Object for functions in subscribe method!
-	def getTimeOk = this.&getTimeOk
-	//Global Object for functions in subscribe method!
-	def hhmm = this.&hhmm
-	//Global Object for functions in subscribe method!
-	def timeIntervalLabel = this.&timeIntervalLabel
-	//Global Object for functions in subscribe method!
-	def list = this.&list
+	def resetLEDNotification = this.&resetLEDNotification
 
 	App2(Object obj) {
 		reference = obj
 		location = obj.locationObject
 		app = obj.appObject
-		atomicState = obj.atomicState
-		beacons = obj.beaconSensorObject
-		phones = obj.mobilePresenceObject
-		arrivalOnSwitches = obj.switchObject
-		arrivalOffSwitches = obj.switchObject
-		arrivalLocks = obj.lockObject
-		departOnSwitches = obj.switchObject
-		departOffSwitches = obj.switchObject
-		departLocks = obj.lockObject
+		deviceContactSensor = obj.contactObject
+		deviceLight = obj.colorControlObject
 		//Global variable for settings!
-		settings = [app:app, starting:starting, ending:ending, beacons:beacons, phones:phones, arrivalPhrase:arrivalPhrase, arrivalOnSwitches:arrivalOnSwitches, arrivalOffSwitches:arrivalOffSwitches, arrivalLocks:arrivalLocks, departPhrase:departPhrase, departOnSwitches:departOnSwitches, departOffSwitches:departOffSwitches, departLocks:departLocks, pushNotification:pushNotification, phone:phone, days:days, modes:modes]
+		settings = [app: app, deviceContactSensor: deviceContactSensor, reminderTime: reminderTime, deviceLight: deviceLight, END: "END"]
 	}
 	//Global variables for each app
 	//Global variable for state[mode]
@@ -642,11 +702,16 @@ class App2 {
 	def settings
 	//Zip code
 	def zipCode = 92617
+	//atomicState variable
+	def atomicState = [version: "1.01"]
 
 	//Methods
 	/////////////////////////////////////////////////////////////////////
 	def setLocationMode(String mode) {
-		location.mode = mode
+		location.setValue([name: "Location", value: "$mode", deviceId: "locationID0", descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+		location.setValue([name: "mode", value: "$mode", deviceId: "locationID0", descriptionText: "",
+				   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
 	}
 	
 	/////////////////////////////////////////////////////////////////////
@@ -668,6 +733,12 @@ class App2 {
 		eventList.add(event)
 		functionList.add(FunctionToCall)
 	}
+	////subscribe(obj, event, nameOfFunc)
+	def subscribe(Object obj, String event, String nameOfFunction) {
+		objectList.add(obj)
+		eventList.add(event)
+		functionList.add(nameOfFunction)
+	}
 	////subscribe(obj, event, func, data)
 	def subscribe(Object obj, String event, Closure FunctionToCall, LinkedHashMap metaData) {
 		objectList.add(obj)	
@@ -713,6 +784,17 @@ class App2 {
 		}
 	}
 	
+	def unschedule(String nameOfFunctionToUnschedule) {
+		for (int i = 0;i < timersFuncList.size();i++) {
+			if (timersFuncList[i] instanceof String) {
+				if (timersFuncList[i] == nameOfFunctionToUnschedule) {
+					if (timersList != null)
+						timersList[i].cancel()
+				}
+			}
+		}
+	}
+	
 	
 	def unschedule() {
 		for (int i = 0;i < timersFuncList.size();i++) {
@@ -731,6 +813,16 @@ class App2 {
 			}
 		}
 	}
+	
+	def sendNotificationToContacts(String text, String recipients, LinkedHashMap metaData) {
+		for (int i = 0;i < recipients.size();i++) {
+			for (int j = 0;j < location.contacts.size();j++) {
+				if (recipients[i] == location.contacts[j]) {
+					println("Sending \""+text+"\" to "+location.phoneNumbers[j].toString())
+				}
+			}
+		}
+	}
 	/////////////////////////////////////////////////////////////////////
 	////sendSms(phone, text)
 	def sendSms(long phoneNumber, String text) {
@@ -833,329 +925,183 @@ class App2 {
 	def canSchedule() {
 		return true
 	}
-
-	def mainPage() {
-		dynamicPage(name: "mainPage", install: true, uninstall: true) {
-	
-			section("Where do you want to watch?") {
-				input name: "beacons", type: "capability.beacon", title: "Select your beacon(s)", 
-					multiple: true, required: true
-			}
-	
-			section("Who do you want to watch for?") {
-				input name: "phones", type: "device.mobilePresence", title: "Select your phone(s)", 
-					multiple: true, required: true
-			}
-	
-			section("What do you want to do on arrival?") {
-				input name: "arrivalPhrase", type: "enum", title: "Execute a phrase", 
-					options: listPhrases(), required: false
-				input "arrivalOnSwitches", "capability.switch", title: "Turn on some switches", 
-					multiple: true, required: false
-				input "arrivalOffSwitches", "capability.switch", title: "Turn off some switches", 
-					multiple: true, required: false
-				input "arrivalLocks", "capability.lock", title: "Unlock the door",
-					multiple: true, required: false
-			}
-	
-			section("What do you want to do on departure?") {
-				input name: "departPhrase", type: "enum", title: "Execute a phrase", 
-					options: listPhrases(), required: false
-				input "departOnSwitches", "capability.switch", title: "Turn on some switches", 
-					multiple: true, required: false
-				input "departOffSwitches", "capability.switch", title: "Turn off some switches", 
-					multiple: true, required: false
-				input "departLocks", "capability.lock", title: "Lock the door",
-					multiple: true, required: false
-			}
-	
-			section("Do you want to be notified?") {
-				input "pushNotification", "bool", title: "Send a push notification"
-				input "phone", "phone", title: "Send a text message", description: "Tap to enter phone number", 
-					required: false
-			}
-	
-			section {
-				label title: "Give your automation a name", description: "e.g. Goodnight Home, Wake Up"
-			}
-	
-			def timeLabel = timeIntervalLabel()
-			section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
-				href "timeIntervalInput", title: "Only during a certain time", 
-					description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : "incomplete"
-	
-				input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
-					options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
-	
-				input "modes", "mode", title: "Only when mode is", multiple: true, required: false
-			}
-		}
+	/////////////////////////////////////////////////////////////////////
+	def createAccessToken() {
+		state.accessToken = "accessToken"
+		return state.accessToken
 	}
-	
-	// Lifecycle management
+	/////////////////////////////////////////////////////////////////////
+	def runOnce(Date date, Closure methodToCall) {
+		methodTocall()
+	}
+
 	def installed() {
-		log.debug "<beacon-control> Installed with settings: ${settings}"
+		log.debug "Installed with settings: ${settings}"
+		
 		initialize()
 	}
 	
 	def updated() {
-		log.debug "<beacon-control> Updated with settings: ${settings}"
+		log.debug "Updated with settings: ${settings}"
+	
 		unsubscribe()
+	        
 		initialize()
 	}
 	
 	def initialize() {
-		subscribe(beacons, "presence", beaconHandler)
-	}
-	
-	// Event handlers
-	def beaconHandler(evt) {
-		log.debug "<beacon-control> beaconHandler: $evt"
-	
-		if (allOk) {
-			def data = new groovy.json.JsonSlurper().parseText(evt.data)
-	                // removed logging of device names. can be added back for debugging
-			//log.debug "<beacon-control> data: $data - phones: " + phones*.deviceNetworkId
-	
-			def beaconName = getBeaconName(evt)
-	                // removed logging of device names. can be added back for debugging
-			//log.debug "<beacon-control> beaconName: $beaconName"
-	
-			def phoneName = getPhoneName(data)
-	                // removed logging of device names. can be added back for debugging
-			//log.debug "<beacon-control> phoneName: $phoneName"
-			if (phoneName != null) {
-	            def action = data.presence == "1" ? "arrived" : "left"
-	            def msg = "$phoneName has $action ${action == 'arrived' ? 'at ' : ''}the $beaconName"
-	
-	            if (action == "arrived") {
-	                msg = arriveActions(msg)
-	            }
-	            else if (action == "left") {
-	                msg = departActions(msg)
-	            }
-	            log.debug "<beacon-control> msg: $msg"
 	
-	            if (pushNotification || phone) {
-	                def options = [
-	                    method: (pushNotification && phone) ? "both" : (pushNotification ? "push" : "sms"),
-	                    phone: phone
-	                ]
-	                sendNotification(msg, options)
-	            }
+	    // will stop LED notification incase it was set by med reminder
+	    subscribe(deviceContactSensor, "contact", contactHandler)
+	
+	    // how many minutes to look in the past from the reminder time, for an open draw
+	    state.minutesToCheckOpenDraw = 60
+	    
+	    // is true when LED notification is set after exceeding 10 minutes past reminder time
+	    state.ledNotificationTriggered = false
+	    
+	    // Set a timer to run once a day to notify if draw wasn't opened yet
+	    schedule(reminderTime, checkOpenDrawInPast)
+	   
+	}
+	
+	// Should turn off any LED notification on OPEN state
+	def contactHandler(evt){
+		if (evt.value == "open") {
+	        // if LED notification triggered, reset it.
+	        log.debug "Cabinet opened"
+	        if (state.ledNotificationTriggered) {
+	            resetLEDNotification()
 	        }
 		}
 	}
 	
-	// Helpers
-	private arriveActions(msg) {
-		if (arrivalPhrase || arrivalOnSwitches || arrivalOffSwitches || arrivalLocks) msg += ", so"
-		
-		if (arrivalPhrase) {
-			log.debug "<beacon-control> executing: $arrivalPhrase"
-			executePhrase(arrivalPhrase)
-			msg += " ${prefix('executed')} $arrivalPhrase."
-		}
-		if (arrivalOnSwitches) {
-			log.debug "<beacon-control> turning on: $arrivalOnSwitches"
-			arrivalOnSwitches.on()
-			msg += " ${prefix('turned')} ${list(arrivalOnSwitches)} on."
-		}
-		if (arrivalOffSwitches) {
-			log.debug "<beacon-control> turning off: $arrivalOffSwitches"
-			arrivalOffSwitches.off()
-			msg += " ${prefix('turned')} ${list(arrivalOffSwitches)} off."
-		}
-		if (arrivalLocks) {
-			log.debug "<beacon-control> unlocking: $arrivalLocks"
-			arrivalLocks.unlock()
-			msg += " ${prefix('unlocked')} ${list(arrivalLocks)}."
-		}
-		msg
-	}
-	
-	private departActions(msg) {
-		if (departPhrase || departOnSwitches || departOffSwitches || departLocks) msg += ", so"
-		
-		if (departPhrase) {
-			log.debug "<beacon-control> executing: $departPhrase"
-			executePhrase(departPhrase)
-			msg += " ${prefix('executed')} $departPhrase."
-		}
-		if (departOnSwitches) {
-			log.debug "<beacon-control> turning on: $departOnSwitches"
-			departOnSwitches.on()
-			msg += " ${prefix('turned')} ${list(departOnSwitches)} on."
-		}
-		if (departOffSwitches) {
-			log.debug "<beacon-control> turning off: $departOffSwitches"
-			departOffSwitches.off()
-			msg += " ${prefix('turned')} ${list(departOffSwitches)} off."
-		}
-		if (departLocks) {
-			log.debug "<beacon-control> unlocking: $departLocks"
-			departLocks.lock()
-			msg += " ${prefix('locked')} ${list(departLocks)}."
-		}
-		msg
-	}
-	
-	private prefix(word) {
-		def result
-		def index = settings.prefixIndex == null ? 0 : settings.prefixIndex + 1
-		switch (index) {
-			case 0:
-				result = "I $word"
-				break
-			case 1:
-				result = "I also $word"
-				break
-			case 2:
-				result = "And I $word"
-				break
-			default:
-				result = "And $word"
-				break
-		}
-	
-		settings.prefixIndex = index
-		log.trace "prefix($word'): $result"
-		result
-	}
-	
-	private listPhrases() {
-		location.helloHome.getPhrases().label
-	}
-	
-	private executePhrase(phraseName) {
-		if (phraseName) {
-			location.helloHome.execute(phraseName)
-			log.debug "<beacon-control> executed phrase: $phraseName"
-		}
-	}
-	
-	private getBeaconName(evt) {
-		def beaconName = beacons.find { b -> b.id == evt.deviceId }
-		return beaconName
+	// If the draw was NOT opened within 60 minutes of the timer send notification out.
+	def checkOpenDrawInPast(){
+		log.debug "Checking past 60 minutes of activity from $reminderTime"
+	    
+	    // check activity of sensor for past 60 minutes for any OPENED status
+	    def cabinetOpened = isOpened(state.minutesToCheckOpenDraw)
+		log.debug "Cabinet found opened: $cabinetOpened"
+	    
+	    // if it's opened, then do nothing and assume they took their meds
+	    if (!cabinetOpened) {    
+	    	sendNotification("Hi, please remember to take your meds in the cabinet")
+	       
+	       // if no open activity, send out notification and set new reminder    
+	        def reminderTimePlus10 = new Date(now() + (10 * 60000))
+	
+	        // needs to be scheduled if draw wasn't already opened
+	        runOnce(reminderTimePlus10, checkOpenDrawAfterReminder)
+	    }
 	}
 	
-	private getPhoneName(data) {    
-		def phoneName = phones.find { phone ->
-			// Work around DNI bug in data
-			def pParts = phone.deviceNetworkId.split('\\|')
-			def dParts = data.dni.split('\\|')
-	        pParts[0] == dParts[0]
+	// If the draw was NOT opened after 10 minutes past reminder, use LED notification
+	def checkOpenDrawAfterReminder(){
+		log.debug "Checking additional 10 minutes of activity from $reminderTime"
+	    
+	    // check activity of sensor for past 10 minutes for any OPENED status
+	    def cabinetOpened = isOpened(10)    
+	    
+	   	log.debug "Cabinet found opened: $cabinetOpened"
+	        
+	    // if no open activity, blink lights
+	    if (!cabinetOpened) {
+	    	log.debug "Set LED to Notification color"
+	        setLEDNotification()
+	    }
+	    
+	}
+	
+	// Helper function for sending out an app notification
+	def sendNotification(msg){
+	        log.debug "Message Sent: $msg"
+	        sendPush(msg)
+	}
+	
+	// Check if the sensor has been opened since the minutes entered
+	// Return true if opened found, else false.
+	def isOpened(minutes){
+	    // query last X minutes of activity log    
+	    def previousDateTime = new Date(now() - (minutes * 60000))
+	    
+	    // capture all events recorded
+	    def evts = deviceContactSensor.eventsSince(previousDateTime)   
+	    def cabinetOpened = false
+	    if (evts.size() > 0) {
+	        evts.each{
+	            if(it.value == "open") {
+	                cabinetOpened = true 
+	            }
+	        }
 		}
-		return phoneName
+	    
+	    return cabinetOpened
 	}
 	
-	private hideOptionsSection() {
-		(starting || ending || days || modes) ? false : true
-	}
-	
-	private getAllOk() {
-		modeOk && daysOk && timeOk
-	}
+	// Saves current color and sets the light to RED
+	def setLEDNotification(){
 	
-	private getModeOk() {
-		def result = !modes || modes.contains(location.mode)
-		log.trace "<beacon-control> modeOk = $result"
-		result
-	}
+		state.ledNotificationTriggered = true
+	    
+		// turn light back off when reset is called if it was originally off
+	 	state.ledState = deviceLight.currentValue("switch")
 	
-	private getDaysOk() {
-		def result = true
-		if (days) {
-			def df = new java.text.SimpleDateFormat("EEEE")
-			if (location.timeZone) {
-				df.setTimeZone(location.timeZone)
-			}
-			else {
-				df.setTimeZone(TimeZone.getTimeZone("America/New_York"))
-			}
-			def day = df.format(new Date())
-			result = days.contains(day)
-		}
-		log.trace "<beacon-control> daysOk = $result"
-		result
-	}
+		// set light to RED and store original color until stopped    
+	    state.origColor = deviceLight.currentValue("hue")
+	    deviceLight.on()
+	    deviceLight.setHue(100)
+	    
+	    log.debug "LED set to RED. Original color stored: $state.origColor"
 	
-	private getTimeOk() {
-		def result = true
-		if (starting && ending) {
-			def currTime = now()
-			def start = timeToday(starting, location?.timeZone).time
-			def stop = timeToday(ending, location?.timeZone).time
-			result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
-		}
-		log.trace "<beacon-control> timeOk = $result"
-		result
 	}
 	
-	private hhmm(time, fmt = "h:mm a") {
-		def t = timeToday(time, location.timeZone)
-		def f = new java.text.SimpleDateFormat(fmt)
-		f.setTimeZone(location.timeZone ?: timeZone(time))
-		f.format(t)
-	}
+	// Sets the color back to the original saved color
+	def resetLEDNotification(){
 	
-	private timeIntervalLabel() {
-		(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""
-	}
+		state.ledNotificationTriggered = false
+	    
+	    // return color to original
+	    log.debug "Reset LED color to: $state.origColor"
+	    if (state.origColor != null) {
+	    	deviceLight.setHue(state.origColor)
+	    }
+	    
+	    // if the light was turned on just for the notification, turn it back off now
+	    if (state.ledState == "off") {
+	    	deviceLight.off()
+	    }
 	
-	private list(Object names) {
-		return names[0]
 	}
 }
 
 @Field def app1
 @Field def app2
-def initOrder = Verify.getBoolean()
-if (initOrder) {
-	app1 = new App1(this)
-	app2 = new App2(this)
-} else {
-	app2 = new App2(this)
-	app1 = new App1(this)
-}
 
-def installOrder = Verify.getBoolean()
-if (installOrder) {
-	app1.installed()
-	app2.installed()
-} else {
-	app2.installed()
-	app1.installed()
-}
+app1 = new App1(this)
+app2 = new App2(this)
 
-while(true) {
-	def eventNumber = Verify.getInt(0,4)
-	switch(eventNumber) {
-		case 0:
-			lockObject.setValue([name: "lock", value: "locked", deviceId: "lockID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-			break
-		case 1:
-			lockObject.setValue([name: "unlock", value: "unlocked ", deviceId: "lockID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-			break
-		case 2:
-			contactObject.setValue([name: "contact.open", value: "open", deviceId: "contactSensorID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-			break
-		case 3:
-			contactObject.setValue([name: "contact.closed", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
-					displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-			break
-		case 4:
-			def event = Verify.getInt(0,1)
-			if (event == 0) {
-					presenceSensorObject.setValue([name: "presence", value: "present", deviceId: "presenceSensorID0", descriptionText: "",
-							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"1","dni":"mobile0"}'])
-			} else {
-					presenceSensorObject.setValue([name: "presence", value: "not present", deviceId: "presenceSensorID0", descriptionText: "",
-							displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"presence":"0","dni":"mobile0"}'])
-			}
-			break
-	}
-}
+app1.installed()
+app2.installed()
+
+contactObject.setValue([name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "contact", value: "closed", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+contactObject.setValue([name: "contact", value: "open", deviceId: "contactSensorID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+
+colorControlObject.setValue([name: "hue", value: "32", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "saturation", value: "32", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "level", value: "32", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch", value: "on", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch", value: "off", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "switch", value: "on", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+colorControlObject.setValue([name: "colorTemperature", value: "32", deviceId: "colorControlID0", descriptionText: "",
+displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])