Setting for Apduino

a.	Sensors 
Sensor0 = Magnetic open/close sensor 
Sensor0 configuration:
Sensor Type	DIGITAL_SENSOR	
Rx Pin	D30	
Poll Frequency	1000	

b.	Actuators
Actuator0 = SainSmart 2-Channel 5V Relay Module

Actuator0 configuration:
Actuator Type	DIGITAL_ACTUATOR	
Pin	D22	
Initial Value	1	

c.	Variables
Variable0 = Used for counting second when sensor0 is open and variable1 > 15 (means the door is open more than 15 minutes ago after 8 PM).
Variable1 = Used for counting minutes after 8PM if sensor0 is open.

d.	Rules

Rule0 – Used for verify variable0 value. If it is higher than 4 (4 second s left after variable1 reached 15), then it switches on actuator0 (the relay). – “The button is pushed.” 
Rule0 configuration:
Evaluation Function	RF_METRO	
Sensor	Ignore	
Test Value`	1000	
Condition Expression	(V0=4)	
Action Target	TARGET_ACTUATOR	
Actuator	A0	
True Action	RULE_ACT_FUNC_SET_ON	
False Action	RULE_ACT_FUNC_NOOP	

Rule1– Used for verify variable0 value. If it is higher than 6 (6 second s left after variable1 reached 15), then it switches off actuator0 (the relay). – “Pressed button released after 2 seconds.”
Rule1 configuration:
Evaluation Function	RF_METRO	
Sensor	Ignore	
Test Value`	1000	
Condition Expression	(V0=6)	
Action Target	TARGET_ACTUATOR	
Actuator	A0	
True Action	RULE_ACT_FUNC_SET_OFF	
False Action	RULE_ACT_FUNC_NOOP	

Rule2 – Used for verify variable1 value and sensor0 in every second. If sensor0 is open and variable1 > 15 (means garage door is open longer than 15 minutes after 8PM), then increment the variable0 by 1. 
Rule2 configuration:
Evaluation Function	RF_METRO	
Sensor	Ignore	
Test Value`	1000	
Condition Expression	((S0=0)&(V1>15))	
Action Target	TARGET_VARIABLE	
Actuator	V0	
True Action	RULE_ACT_FUNC_INC	
False Action	RULE_ACT_FUNC_NOOP	

Rule3 – Reset variable0 after it reached 30 (In 20 seconds the garage door goes from open position to close, so 30 seconds reset time is enough).
Rule3 configuration:
Evaluation Function	RF_METRO	
Sensor	Ignore	
Test Value`	10000	
Condition Expression	V0>30	
Action Target	TARGET_VARIABLE	
Actuator	V0	
True Action	RULE_ACT_FUNC_RESET	
False Action	RULE_ACT_FUNC_NOOP	

Rule4 – Increment variable1 in every minute by 1, if current time is between 8PM and 6AM and sensor0 is open.
Rule4 configuration:
Evaluation Function	RF_SCHEDULED	
Sensor	Ignore	
Cron-Like Spec	* 20,21,22,23,0,1,2,3,4,5 * * *	
Condition Expression	(S0=0)	
Action Target	TARGET_VARIABLE	
Actuator	V1	
True Action	RULE_ACT_FUNC_INC	
False Action	RULE_ACT_FUNC_NOOP	

Rule5 – Reset variable1 if sensor0 =1 (means the door is closed).
Rule5 configuration:
Evaluation Function	RF_EVALUATE	
Sensor	Ignore	
Test Value`	0	
Condition Expression	(S0=1)	
Action Target	TARGET_VARIABLE	
Actuator	V1	
True Action	RULE_ACT_FUNC_RESET	
False Action	RULE_ACT_FUNC_NOOP