Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added ClimateControl.drl for manager demo

Rich Turnere70ef259b28a
diff --git a/manager/server/src/main/resources/demo/rules/ClimateControlDemoRules.drl b/manager/server/src/main/resources/demo/rules/ClimateControlDemoRules.drl
new file mode 100644
index 000000000..c7c829a96
--- /dev/null
+++ b/manager/server/src/main/resources/demo/rules/ClimateControlDemoRules.drl
@@ -0,0 +1,1226 @@
+package org.openremote.agent.test.rules;
+
+import java.util.concurrent.*;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.io.*;
+import org.openremote.agent.sensor.*;
+
+global org.openremote.agent.command.Commands commands;
+global org.openremote.agent.rules.RulePersistence persistence;
+global org.openremote.agent.rules.RuleUtil util;
+global com.fasterxml.jackson.databind.ObjectMapper JSON;
+global java.util.logging.Logger LOG;
+
+declare SensorState
+ @role(event)
+end
+
+rule "-PSB: Init"
+salience 10
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", persistence.readData("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE","--:--"));
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc", "OFF");
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.inc", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.dec", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.inc", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.dec", "OFF");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP",persistence.readData("SETTINGS_COMFORT_TARGET_TEMP","20.0\u00B0"));
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.dec","OFF");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP","19.5\u00B0");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.dec","OFF");
+ commands.execute("NEXT_EVENT",persistence.readData("NEXT_EVENT","-")); // Possible values are "-", "Departure", "Arrive"
+ commands.execute("PRESENCE_LAST_DETECTED_TIME","-"); // hh:mm
+ commands.execute("PRESENCE_DETECTED_LATCHED","No"); // Latches for 15mins
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", "0");
+ commands.execute("ACTUATOR_TARGET_TEMP", "16");
+ commands.execute("WINDOW_STATE","Closed");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+ commands.execute("HEATING_DISABLED", "No");
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "You're doing great!");
+ commands.execute("VACATION_DAYS.inc", "OFF");
+ commands.execute("VACATION_DAYS.dec", "OFF");
+ commands.execute("VACATION_DAYS", persistence.readData("VACATION_DAYS", "0"));
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVE",persistence.readData("LEGACY_UI_ECO_SCORE_CUMULATIVE", "0"));
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVE_SLIDER", persistence.readData("LEGACY_UI_ECO_SCORE_CUMULATIVE_SLIDER", "0"));
+ commands.execute("ACTUAL_TIME_ARRIVAL", persistence.readData("ACTUAL_TIME_ARRIVAL","-"));
+ commands.execute("ACTUAL_TIME_DEPARTURE", persistence.readData("ACTUAL_TIME_DEPARTURE","-"));
+ commands.execute("LEGACY_UI_ROOM_NAME",persistence.readData("LEGACY_UI_ROOM_NAME", "OpenRemote"));
+ commands.execute("LEGACY_UI_BACKGROUND_IMAGE_ARRIVAL", "on");
+ commands.execute("LEGACY_UI_BACKGROUND_IMAGE_DEPARTURE", "off");
+end
+
+rule "-PSB: Init ETA when empty"
+salience 9
+when
+ SensorState(sensorName matches "UI_ESTIMATED_TIME_ARRIVAL.*", $s: sensorName, value=="")
+then
+ commands.execute($s, persistence.readData($s, "09:00"));
+end
+
+rule "-PSB: Init ETD when empty"
+salience 8
+when
+ SensorState(sensorName matches "UI_ESTIMATED_TIME_DEPARTURE.*", $s: sensorName, value=="")
+then
+ commands.execute($s, persistence.readData($s, "17:00"));
+end
+
+rule "--Show timers"
+salience 10
+// timer(int:100)
+when
+ SensorState(sensorName=="TIME_CURRENT_DAY_OF_WEEK", $a:value!="N/A")
+ SensorState(sensorName=="TIME_DAY_OF_MONTH", $b:value!="N/A")
+ SensorState(sensorName=="TIME_HH:MM:SS", $d:value!="N/A")
+ SensorState(sensorName=="TIME_MONTH_IN_YEAR", $c:value!="N/A")
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK", value!="N/A")
+then
+ LOG.info("Sensor clock is: "+$a+" "+$b+" "+$c+" "+$d);
+ LOG.info("Drools SessionClock() is: "+(new java.util.Date(drools.getWorkingMemory().getSessionClock().getCurrentTime())).toString());
+end
+
+rule "-PSB: LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE Inc"
+ timer(int:300ms) // debounce & protect double click
+when
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $v: value)
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc" , value == "ON")
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", util.shiftTime($v.toString(), 5));
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc", "off");
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec", "OFF");
+end
+
+rule "-PSB: UI_ESTIMATED_TIME_ARRIVAL Inc"
+ timer(int:300ms) // debounce & protect double click
+when
+ SensorState(sensorName == "UI_ESTIMATED_TIME_ARRIVAL", $v: value)
+ SensorState(sensorName == "UI_ESTIMATED_TIME_ARRIVAL.inc" , value == "ON")
+then
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL", util.shiftTime($v.toString(), 5));
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.inc", "off");
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.dec", "OFF");
+end
+
+rule "-PSB: UI_ESTIMATED_TIME_DEPARTURE Inc"
+ timer(int:300ms) // debounce & protect double click
+when
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE", $v: value)
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE.inc" , value == "ON")
+then
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", util.shiftTime($v.toString(), 5));
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.inc", "off");
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.dec", "OFF");
+end
+
+rule "-PSB: LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE Dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $v: value)
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec" , value == "ON")
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", util.shiftTime($v.toString(), -15));
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc", "OFF");
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec", "off");
+end
+
+rule "-PSB: UI_ESTIMATED_TIME_ARRIVAL Dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "UI_ESTIMATED_TIME_ARRIVAL", $v: value)
+ SensorState(sensorName == "UI_ESTIMATED_TIME_ARRIVAL.dec" , value == "ON")
+then
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL", util.shiftTime($v.toString(), -15));
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.inc", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL.dec", "off");
+end
+
+rule "-PSB: UI_ESTIMATED_TIME_DEPARTURE Dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE", $v: value)
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE.dec" , value == "ON")
+then
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", util.shiftTime($v.toString(), -15));
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.inc", "OFF");
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE.dec", "off");
+end
+
+rule "PSB: MANUAL_SCHEDULE_CHANGE_COUNT_ change counter"
+ timer(int: 30s) // Wait 30s to mark user's schedule change
+when
+(
+ SensorState($s:sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc" , value == "off") ||
+ SensorState($s:sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec" , value == "off") ||
+ SensorState($s:sensorName == "UI_ESTIMATED_TIME_ARRIVAL.inc" , value == "off") ||
+ SensorState($s:sensorName == "UI_ESTIMATED_TIME_ARRIVAL.dec" , value == "off") ||
+ SensorState($s:sensorName == "UI_ESTIMATED_TIME_DEPARTURE.inc" , value == "off") ||
+ SensorState($s:sensorName == "UI_ESTIMATED_TIME_DEPARTURE.dec" , value == "off")
+)
+then
+ // off - changed by user
+ // OFF - idle state after restart
+ commands.execute($s, "OFF");
+ int cnt = 0;
+ try{
+ cnt = Integer.parseInt(persistence.readData("MANUAL_SCHEDULE_CHANGE_COUNT_0","0"));
+ }finally{
+ cnt += 1;
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_0", cnt);
+ }
+end
+
+rule "PSB: set departure time on manual LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE change"
+ salience 10
+ timer(int: 300ms)
+when
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $v: value)
+(
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.inc" , value == "ON") ||
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE.dec" , value == "ON") ||
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE.inc", value == "ON") ||
+ SensorState(sensorName == "UI_ESTIMATED_TIME_DEPARTURE.dec", value == "ON")
+)
+ SensorState(sensorName == "NEXT_EVENT", value == "-")
+then
+ commands.execute("NEXT_EVENT", "Departure");
+end
+
+rule "PSB: SETTINGS_COMFORT_TARGET_TEMP inc"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP", $v: value, eval(util.parseDouble(value) < 24))
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP.inc" , value == "ON")
+then
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.inc","off");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.dec","OFF");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
+end
+
+rule "PSB: SETTINGS_COMFORT_TARGET_TEMP dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP", $v: value, eval(util.parseDouble(value) > 18))
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP.dec" , value == "ON")
+then
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.dec","off");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
+end
+
+rule "PSB: SETTINGS_COMFORT_TARGET_TEMP INC/dec" // needed when change on the boundary
+ salience -10
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP.inc" , value == "ON")
+then
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.inc","off");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.dec","OFF");
+end
+
+rule "PSB: SETTINGS_COMFORT_TARGET_TEMP inc/DEC" // needed when change on the boundary
+ salience -10
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SETTINGS_COMFORT_TARGET_TEMP.dec" , value == "ON")
+then
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("SETTINGS_COMFORT_TARGET_TEMP.dec","off");
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP inc"
+ timer(int:300ms)
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP", $v: value, eval(util.parseDouble(value) <26))
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.inc" , value == "ON")
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.inc","off");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.dec","OFF"); // Do not increase change counter
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP", $v: value, eval(util.parseDouble(value) > 16)) // Lower temp limit
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.dec" , value == "ON")
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.dec","off");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP INC/dec" // needed when on the boundary and in summer
+ salience -10
+ timer(int:300ms)
+when
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.inc" , value == "ON")
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.inc","off");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.dec","OFF");
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP inc/DEC" // needed when on the boundary and in summer
+ salience -10
+ timer(int:300ms)
+when
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.dec" , value == "ON")
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.inc","OFF");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP.dec","off");
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP change counter"
+ timer(int: 30s) // Wait 30s to mark user's temperature change
+when
+(
+ SensorState($s:sensorName == "CURRENT_COMFORT_TARGET_TEMP.inc" , value == "off") ||
+ SensorState($s:sensorName == "CURRENT_COMFORT_TARGET_TEMP.dec" , value == "off") ||
+ SensorState($s:sensorName == "SETTINGS_COMFORT_TARGET_TEMP.inc" , value == "off") ||
+ SensorState($s:sensorName == "SETTINGS_COMFORT_TARGET_TEMP.dec" , value == "off")
+)
+then
+ // off - changed by user
+ // OFF - idle state after restart
+ commands.execute($s, "OFF");
+ int cnt = 0;
+ try{
+ cnt = Integer.parseInt(persistence.readData("MANUAL_SET_TEMP_COUNT_PER_WEEK_0","0"));
+ }finally{
+ cnt += 1;
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_0", cnt);
+ }
+end
+
+rule "PSB: CURRENT_COMFORT_TARGET_TEMP change summer"
+salience 10
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="Yes")
+(
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.inc" , $s: sensorName, value == "ON") ||
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.dec", $s: sensorName, value == "ON")
+)
+then
+ commands.execute($s, "OFF");
+end
+
+rule "PSB: set departure on manual TEMPERATURE change after expected attendance"
+salience 10
+ timer(int:300ms)
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName == "LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $et: value)
+(
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.inc" , value == "ON") ||
+ SensorState(sensorName == "CURRENT_COMFORT_TARGET_TEMP.dec" , value == "ON")
+)
+ SensorState(sensorName == "NEXT_EVENT", value == "-")
+then
+ // Set departure time when temp manually adjusted after leave
+ commands.execute("NEXT_EVENT", "Departure");
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", util.shiftTime($et.toString(), 60));
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", util.shiftTime($et.toString(), 60));
+end
+
+rule "-PSB: Move ETA to ET at midnight"
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK", $e:value)
+ SensorState(sensorName=="TIME_HH:MM:SS",$h:value,eval(util.parseTimestamp(value) >= util.parseTimestamp("00:02"))) // Wait 2 minutes to be sure that $e is OK
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_ARRIVAL."+$e), eval(util.parseTimestamp(value) > util.parseTimestamp($h)), $va:value)
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $vd: value)
+ SensorState(sensorName=="NEXT_EVENT", value=="-")
+ SensorState(sensorName=="VACATION_DAYS", eval(Integer.parseInt(value.toString())==0))
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $va.toString());
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL", $va.toString());
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", $vd.toString());
+ commands.execute("NEXT_EVENT", "Arrive");
+end
+
+rule "-Move ETA ETD for current day"
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK", $e:value)
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_ARRIVAL."+$e), $va:value)
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $vd: value)
+then
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL", $va.toString());
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", $vd.toString());
+end
+
+rule "-PSB: reset ACTUAL_TIME_ARRIVAL"
+when
+ SensorState(sensorName=="NEXT_EVENT", value=="Arrive")
+then
+ commands.execute("ACTUAL_TIME_ARRIVAL","-");
+end
+
+rule "-PSB: reset ACTUAL_TIME_DEPARTURE"
+when
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL",value=="-")
+then
+ commands.execute("ACTUAL_TIME_DEPARTURE","-");
+end
+
+rule "PSB: decrease vacation counter at midnight"
+when
+ $timer: SensorState(sensorName=="TIME_HH:MM:SS", value!="N/A", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
+ SensorState(sensorName=="VACATION_DAYS", $v: value, eval(Integer.parseInt(value.toString())>0), this before [2m] $timer)
+then
+ commands.execute("VACATION_DAYS", Integer.parseInt($v.toString())-1);
+end
+
+rule "PSB: reset action at midnight"
+when
+ SensorState(sensorName=="TIME_HH:MM:SS", value!="N/A", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", "-");
+ commands.execute("NEXT_EVENT", "-");
+end
+
+rule "-PSB: Move ETD to ET at arrive init"
+// This one is needed for cases when system is restart after arrive time
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK",$e:value)
+ SensorState(sensorName=="TIME_HH:MM:SS",$h:value)
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_ARRIVAL."+$e), eval(util.parseTimestamp(value) <= util.parseTimestamp($h)), eval(value.toString().length()==5))
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $vd:value, eval(value.toString().length()==5))
+// SensorState(sensorName=="NEXT_EVENT", value=="-")
+ SensorState(sensorName=="LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", value == "--:--")
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $vd.toString());
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE", $vd.toString());
+ commands.execute("NEXT_EVENT", "Departure");
+end
+
+rule "-PSB: Move ETD to ET at arrive"
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK",$e:value)
+ SensorState(sensorName=="TIME_HH:MM:SS",$h:value)
+ SensorState(sensorName=="NEXT_EVENT", value=="Arrive")
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $vd:value)
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", value != "-", value != "--:--", value != "status")
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
+ SensorState(sensorName=="VACATION_DAYS", eval(Integer.parseInt(value.toString())==0))
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $vd.toString());
+ commands.execute("NEXT_EVENT", "Departure");
+end
+
+rule "PSB: actual arrival time earlier when temperature increased and person detected"
+timer(int: 10s) // Prevent glitch at midnight reset
+when
+ // Before attendance schedule
+ SensorState(sensorName=="TIME_HH:MM:SS",$h:value)
+ SensorState(sensorName=="NEXT_EVENT", value=="Arrive")
+ // Temperature increased manually (higher than ECO)
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $vc: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble(value) > java.lang.Math.max(util.parseDouble($vc)-5.0, 16.0)))
+ // Person detected
+ SensorState(sensorName=="PRESENCE_AS_INTEGER", value == "1")
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL",value=="-")
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", $h.toString().substring(0,5));
+end
+
+rule "PSB: fetch actual arrival time"
+when
+ SensorState(sensorName=="TIME_HH:MM:SS", $h:value)
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL", value == "-")
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure")
+ SensorState(sensorName=="PRESENCE_AS_INTEGER", value=="1")
+then
+ commands.execute("ACTUAL_TIME_ARRIVAL", $h.toString().substring(0,5));
+end
+
+rule "PSB: fetch earlier actual arrival time up to 30 min v02"
+when
+ SensorState(sensorName=="TIME_HH:MM:SS", $h:value, eval(util.parseTimestamp(value) >= util.parseTimestamp("04:30"))) // Earliest time of arrival is 4:30 AM
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL", value == "-")
+ SensorState(sensorName=="NEXT_EVENT", value=="Arrive")
+ SensorState(sensorName=="PRESENCE_AS_INTEGER", value=="1")
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", value != "-", value != "--:--")
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
+then
+ commands.execute("ACTUAL_TIME_ARRIVAL", $h.toString().substring(0,5));
+end
+
+rule "PSB: Move - to ET at end of work"
+timer(int: 1s) // avoid racing
+when
+ SensorState(sensorName=="TIME_HH:MM:SS",$h:value)
+ SensorState(sensorName=="UI_ESTIMATED_TIME_DEPARTURE", value != "-", value != "--:--")
+ SensorState(sensorName=="UI_ESTIMATED_TIME_DEPARTURE", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure")
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", "-");
+ commands.execute("NEXT_EVENT", "-");
+end
+
+rule "PSB: Move - to ET on vacation"
+when
+ SensorState(sensorName=="VACATION_DAYS", eval(Integer.parseInt(value.toString())>0))
+then
+ commands.execute("LEGACY_UI_ESTIMATED_TIME_ARRIVAL_DEPARTURE", "-");
+ commands.execute("NEXT_EVENT", "-");
+end
+
+rule "PSB: fetch actual departure time"
+when
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL", value != "-")
+ SensorState(sensorName=="ACTUAL_TIME_DEPARTURE", value == "-")
+ SensorState(sensorName=="NEXT_EVENT", value=="-")
+ SensorState(sensorName=="PRESENCE_LAST_DETECTED_TIME", $v:value, eval(value.toString().length()>4))
+then
+ commands.execute("ACTUAL_TIME_DEPARTURE", $v.toString().substring(0,5));
+ commands.execute("PRESENCE_LAST_DETECTED_TIME","-");
+end
+
+rule "PSB: fetch later departure time"
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK",$e:value)
+ SensorState(sensorName=="NEXT_EVENT", value=="-")
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $vd:value)
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL", value != "-")
+ SensorState(sensorName=="ACTUAL_TIME_DEPARTURE", value != "-")
+ SensorState(sensorName=="PRESENCE_LAST_DETECTED_TIME", $v:value, eval(value.toString().length()>4),
+ eval(util.parseTimestamp(value)<=util.parseTimestamp(util.shiftTime($vd,15))), // Till 15 min after scheduled departure
+ eval(util.parseTimestamp(value)<=util.parseTimestamp("23:55"))) // Till 23:55 - does not wrap on midnight
+ SensorState(sensorName=="VACATION_DAYS", eval(Integer.parseInt(value.toString())==0))
+then
+ commands.execute("ACTUAL_TIME_DEPARTURE", $v.toString().substring(0,5));
+ commands.execute("PRESENCE_LAST_DETECTED_TIME","-");
+end
+
+rule "PSB: adjust estimated times at midnight"
+when
+ SensorState(sensorName=="TIME_DAY_NAME_IN_WEEK", $e: value)
+ $timer: SensorState(sensorName=="TIME_HH:MM:SS", value!="N/A", eval(value.toString().substring(0,5).equals("23:58"))) // more reliable than timer(cron: )
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_DEPARTURE."+$e), $ved:value, this before [1m] $timer) // Loop cut
+ SensorState(sensorName matches ("UI_ESTIMATED_TIME_ARRIVAL."+$e), $vea:value, this before [1m] $timer)
+ SensorState(sensorName=="ACTUAL_TIME_DEPARTURE", $vd:value, value!="-")
+ SensorState(sensorName=="ACTUAL_TIME_ARRIVAL", $va:value, value!="-")
+ SensorState(sensorName=="VACATION_DAYS", eval(Integer.parseInt(value.toString())==0))
+then
+ Double alpha = 2.0/(3+1); // 3 stays for 3 days exponential average
+ long nt = (long) (alpha*util.parseTimestamp($va) + (1-alpha)*util.parseTimestamp($vea));
+ commands.execute("UI_ESTIMATED_TIME_ARRIVAL."+$e.toString(), util.formatTimestamp(nt));
+ LOG.fine("EA="+$vea.toString()+" AA="+$va.toString()+" NA="+ util.formatTimestamp(nt));
+ nt = (long) (alpha*util.parseTimestamp($vd) + (1-alpha)*util.parseTimestamp($ved));
+ commands.execute("UI_ESTIMATED_TIME_DEPARTURE."+$e.toString(), util.formatTimestamp(nt));
+ LOG.fine("ED="+$ved.toString()+" AD="+$vd.toString()+" ND="+ util.formatTimestamp(nt));
+end
+
+rule "--PSB: move sense"
+when
+ SensorState($s:sensorName=="SENSOR_PRESENCE", value=="on")
+ SensorState(sensorName=="TIME_HH:MM:SS", $h:value)
+then
+ LOG.info("Move sense on "+$s+" @"+$h);
+ commands.execute("PRESENCE_LAST_DETECTED_TIME", $h.toString());
+end
+
+rule "--pir echo"
+when
+ SensorState(sensorName=="SENSOR_PRESENCE", $v:value)
+ SensorState(sensorName=="TIME_HH:MM:SS", $h:value)
+then
+ LOG.info("PIR state "+$v.toString()+" @"+$h);
+end
+
+rule "-PSB: person sense"
+when
+ SensorState($s:sensorName=="SENSOR_PRESENCE", value=="on")
+ SensorState(sensorName=="PRESENCE_AS_INTEGER", value!="1")
+then
+ commands.execute("PRESENCE_AS_INTEGER", "1");
+end
+
+rule "-PSB: no person sense"
+timer(int: 2s)
+when
+ SensorState(sensorName=="SENSOR_PRESENCE", value!="on")
+ SensorState(sensorName=="PRESENCE_AS_INTEGER", value!="0")
+then
+ commands.execute("PRESENCE_AS_INTEGER", "0");
+end
+
+rule "-PSB: window open sense"
+when
+ SensorState(sensorName=="SENSOR_WINDOW", value=="on")
+then
+ commands.execute("WINDOW_STATE","Open");
+end
+
+rule "-PSB: window closed sense"
+when
+ SensorState(sensorName=="SENSOR_WINDOW", value=="off")
+then
+ commands.execute("WINDOW_STATE","Closed");
+end
+
+rule "--FS outside temperature sense"
+when
+ SensorState(sensorName=="SENSOR_OUTSIDE_TEMP", $v: value)
+then
+ commands.execute("UI_OUTSIDE_TEMP", $v.toString() );
+ LOG.fine("Fake outside temperature: "+$v.toString() );
+end
+
+rule "--FS inside temperature sense"
+when
+ SensorState(sensorName=="SENSOR_INSIDE_TEMP", $v: value)
+then
+ LOG.fine("Fake inside temperature: "+ $v.toString() );
+ commands.execute("UI_INSIDE_TEMP", $v.toString() );
+end
+
+rule "PSB: Presence"
+when
+ SensorState(sensorName == "PRESENCE_AS_INTEGER", value == "1")
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure") // within expected attendance schedule
+then
+ commands.execute("PRESENCE_DETECTED_LATCHED","Yes");
+end
+
+rule "PSB: Absence when 30 min no movement"
+timer(int: 30m)
+when
+ SensorState(sensorName == "PRESENCE_AS_INTEGER", value == "0")
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure") // within expected attendance schedule
+then
+ commands.execute("PRESENCE_DETECTED_LATCHED","No");
+end
+
+rule "PSB: Absence after 15 min v02"
+timer(int: 15m)
+when
+ SensorState(sensorName == "PRESENCE_AS_INTEGER", value == "0")
+then
+ commands.execute("PRESENCE_DETECTED_LATCHED","No");
+end
+
+rule "-PSB: Absence after scheduled presence time"
+when
+ SensorState(sensorName=="NEXT_EVENT", value!="Departure") // outsidse expected attendance schedule
+then
+ commands.execute("PRESENCE_DETECTED_LATCHED","No");
+end
+
+rule "-PSB: heating ECO"
+when
+(
+ SensorState(sensorName=="NEXT_EVENT", value!="Departure") || // outsidse expected attendance schedule
+ SensorState(sensorName=="HEATING_DISABLED", value=="Yes")
+)
+then
+ commands.execute("HEATING_MODE","ECO");
+end
+
+rule "-PSB: heating Stand-by from ECO"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure") // within expected attendance schedule
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value == "ECO")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $vc: value)
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", $vc.toString());
+ commands.execute("HEATING_MODE", "Stand-by");
+end
+
+rule "-PSB: heating Stand-by from ECO preheating 30 min v02"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="NEXT_EVENT", value=="Arrive") // within expected attendance schedule
+ SensorState(sensorName=="HEATING_MODE", value == "ECO")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $vc: value)
+
+ SensorState(sensorName=="TIME_HH:MM:SS", $h:value, eval(util.parseTimestamp(value) >= util.parseTimestamp("04:30"))) // Earliest time of arrival is 4:30 AM
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", value != "-", value != "--:--")
+ SensorState(sensorName=="UI_ESTIMATED_TIME_ARRIVAL", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
+then
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", $vc.toString());
+ commands.execute("HEATING_MODE", "Stand-by");
+end
+
+rule "-PSB: heating Stand-by from Comfort"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="NEXT_EVENT", value=="Departure") // within expected attendance schedule
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value == "Comfort")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $vc: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", value==$vc) // Only when no manual temperature increase
+then
+ commands.execute("HEATING_MODE","Stand-by");
+end
+
+rule "-PSB: heating Comfort on presence"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $v: value)
+then
+ commands.execute("HEATING_MODE","Comfort");
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", $v.toString());
+end
+
+rule "-PSB: heating Comfort on temperature increase"
+timer(int: 1s) // debounce
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $vc: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble(value) > util.parseDouble($vc)))
+ SensorState(sensorName=="HEATING_MODE", value != "Comfort")
+then
+ commands.execute("HEATING_MODE","Comfort");
+end
+
+rule "-PSB: heating setpoint ECO"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value=="ECO")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $v: value)
+then
+ String s = $v.toString();
+ Double t;
+ try{
+ t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-5); // 5 degrees below comfort
+ } catch (NumberFormatException e){
+ t = 16.0;
+ }
+ commands.execute("ACTUATOR_TARGET_TEMP", String.format("%.1f",t));
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", String.format("%.1f\u00B0",t));
+end
+
+rule "-PSB: heating setpoint ECO summer"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="Yes")
+ SensorState(sensorName=="HEATING_MODE", value=="ECO")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $v: value)
+then
+ String s = $v.toString();
+ Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-5); // 5 degrees below comfort
+ commands.execute("ACTUATOR_TARGET_TEMP", String.format("%.1f",t));
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", "-");
+end
+
+rule "-PSB: heating setpoint Stand-by"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value=="Stand-by")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $v: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", value==$v) // When temperature changed manually keep it till ECO
+then
+ String s = $v.toString();
+ Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-1); // 1 degree below comfort
+ commands.execute("ACTUATOR_TARGET_TEMP", String.format("%.1f",t));
+ commands.execute("CURRENT_COMFORT_TARGET_TEMP", s); // But the user is not aware as on display there is comfort
+end
+
+rule "-PSB: heating setpoint Comfort"
+timer(int: 1s) // avoid race between "HEATING_MODE" & "CURRENT_COMFORT_TARGET_TEMP"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value=="Comfort")
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", $v: value) // set by rule "PSB: heating Comfort" to SETTINGS_COMFORT_TARGET_TEMP or manually
+then
+ String s = $v.toString();
+ Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1)));
+ commands.execute("ACTUATOR_TARGET_TEMP", String.format("%.1f",t));
+end
+
+rule "-PSB: energy efficiency 1"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "0.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 2"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "0.5");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+// v02
+rule "-PSB: energy efficiency 2-1 v02"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) < 23)) // Comfort, Comfort-, Comfort--
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $t: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "0.5");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 2-2 v02"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "0.5");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 2-3 v02"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) < 23), eval(Double.parseDouble(value.toString()) >= 18)) // Comfort, Comfort-, Comfort--, not eco
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+// v02
+
+rule "-PSB: energy efficiency 3"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 4"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open") // Added because otherwise it overrules efficiency 11
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 5"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="HEATING_MODE", value=="Stand-by")
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 6"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.0");
+ commands.execute("UI_ECO_SCORE", 0);
+end
+
+rule "-PSB: energy efficiency 7"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="HEATING_MODE", value=="Stand-by")
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $t: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.5");
+ commands.execute("UI_ECO_SCORE", 1);
+end
+
+rule "-PSB: energy efficiency 8"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="HEATING_MODE", value=="ECO")
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $t: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.5");
+ commands.execute("UI_ECO_SCORE", 1);
+end
+
+rule "-PSB: energy efficiency 9"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.5");
+ commands.execute("UI_ECO_SCORE", 1);
+end
+
+rule "-PSB: energy efficiency 10"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 20), eval(Double.parseDouble(value.toString()) < 21)) // Comfort-
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $t: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "1.5");
+ commands.execute("UI_ECO_SCORE", 1);
+end
+
+rule "-PSB: energy efficiency 11"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "2.0");
+ commands.execute("UI_ECO_SCORE", 2);
+end
+
+rule "-PSB: energy efficiency 12 v02"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) >= 20), eval(Double.parseDouble(value.toString()) < 21)) // Comfort-
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes") // v02
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "2.5");
+ commands.execute("UI_ECO_SCORE", 3);
+end
+
+rule "-PSB: energy efficiency 13"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) < 20)) // Comfort--
+ SensorState(sensorName=="HEATING_MODE", value!="ECO") // needed because of race
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes")
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $t: value)
+ SensorState(sensorName=="CURRENT_COMFORT_TARGET_TEMP", eval(util.parseDouble($t) >= util.parseDouble(value))) // Higher outside temperature
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "3.0");
+ commands.execute("UI_ECO_SCORE", 4);
+end
+
+rule "-PSB: energy efficiency 14"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="HEATING_MODE", value=="ECO")
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="No")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "3.0");
+ commands.execute("UI_ECO_SCORE", 4);
+end
+
+rule "-PSB: energy efficiency 15"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", eval(Double.parseDouble(value.toString()) < 20)) // Comfort--
+ SensorState(sensorName=="PRESENCE_DETECTED_LATCHED", value=="Yes") // No important IMHO
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "3.0");
+ commands.execute("UI_ECO_SCORE", 4);
+end
+
+rule "-PSB: energy efficiency Summer"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="Yes")
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_IMAGE", "3.0");
+ commands.execute("UI_ECO_SCORE", 4);
+end
+
+rule "--PSB: increase total score every 15m"
+when
+ $timer: SensorState(sensorName=="TIME_HH:MM:SS", value!="N/A", eval(Integer.parseInt(value.toString().substring(3,5)) % 15 == 0)) // more reliable than timer(cron: )
+ SensorState(sensorName=="UI_ECO_SCORE", $s: value)
+ SensorState(sensorName=="LEGACY_UI_ECO_SCORE_CUMULATIVE", $ts: value, this before [1m] $timer)
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVE", Integer.parseInt($ts.toString())+Integer.parseInt($s.toString()));
+end
+
+rule "PSB: reward"
+when
+ $ts: SensorState(sensorName=="LEGACY_UI_ECO_SCORE_CUMULATIVE", $s: value, eval(Integer.parseInt(value.toString()) >= 1000))
+ SensorState(sensorName=="LEGACY_UI_ECO_SCORE_CUMULATIVE_SLIDER", $l: value, this before [1m] $ts)
+then
+ Integer i = Integer.parseInt($s.toString());
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVE", i-1000); // Reset score
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVE_SLIDER", Integer.parseInt($l.toString())+1);
+end
+
+rule "--PSB: display totalscore"
+when
+ SensorState(sensorName=="LEGACY_UI_ECO_SCORE_CUMULATIVE", $ts: value)
+then
+ commands.execute("LEGACY_UI_ECO_SCORE_CUMULATIVEdisp", $ts+" / 1000");
+end
+
+rule "PSB: summer"
+timer(int: 1h)
+when
+// SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $sp: value)
+// SensorState(sensorName=="UI_OUTSIDE_TEMP", value!="", eval(util.parseDouble($sp) <= util.parseDouble(value) )) // Outside temp higher than set point
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $o:value) // Only for logging
+ SensorState(sensorName=="YT.summer", value=="0") // Y-con test
+ SensorState(sensorName=="HEATING_DISABLED", value!="Yes")
+then
+ LOG.fine("Summer is ON; outside="+$o.toString());
+ commands.execute("HEATING_DISABLED", "Yes");
+end
+
+rule "PSB: no summer"
+timer(int: 1h)
+when
+// SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", $sp: value)
+// SensorState(sensorName=="UI_OUTSIDE_TEMP", value!="", eval(util.parseDouble($sp) > util.parseDouble(value) )) // Outside temp lower than set point
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", $o:value) // Only for logging
+ SensorState(sensorName=="YT.summer", value=="1") // Y-con test
+ SensorState(sensorName=="HEATING_DISABLED", value!="No")
+then
+ LOG.fine("Summer is OFF; outside="+$o.toString());
+ commands.execute("HEATING_DISABLED", "No");
+end
+
+rule "-PSB: advice 1"
+when
+ SensorState(sensorName=="WINDOW_STATE", value=="Open")
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", $sp: value)
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", value!="", eval(Double.parseDouble($sp.toString()) > util.parseDouble(value) )) // Outside temp lower than set point
+then
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "It's more energy efficient to close the windows when it is colder outside than it is inside");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+ insert(new AdviceGiven("It's more energy efficient to close the windows when it is colder outside than it is inside"));
+end
+
+rule "-PSB: advice 1 done"
+when
+ SensorState(sensorName=="ACTUATOR_TARGET_TEMP", $sp: value)
+(
+ SensorState(sensorName=="WINDOW_STATE", value=="Closed") ||
+ SensorState(sensorName=="UI_OUTSIDE_TEMP", value!="", eval(Double.parseDouble($sp.toString()) <= util.parseDouble(value) )) // Outside temp lower than set point
+)
+ SensorState(sensorName=="LEGACY_UI_ADVICE_TEXT",eval(value.toString().substring(0,9).equals("It's more")))
+then
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "You're doing great!");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+end
+
+rule "-PSB: advice 2"
+when
+ SensorState(sensorName=="HEATING_DISABLED", value=="No")
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", eval(util.parseDouble(value) > 20.5)) // Average is 20 hardcoded or from sensor?
+then
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "Your comfort temperature is set higher than average. You can adjust it on the settings page.");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+ insert(new AdviceGiven("Your comfort temperature is set higher than average. You can adjust it on the settings page."));
+end
+
+rule "-PSB: advice 2 done"
+when
+ SensorState(sensorName=="SETTINGS_COMFORT_TARGET_TEMP", eval(util.parseDouble(value) <= 20.5)) // Average is 20 hardcoded or from sensor?
+ SensorState(sensorName=="LEGACY_UI_ADVICE_TEXT",eval(value.toString().substring(0,12).equals("Your comfort")))
+then
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "You're doing great!");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+end
+
+rule "-PSB: advice 3"
+when
+// irregular attendence
+then
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+end
+
+rule "-PSB: advice 4"
+when
+(
+ SensorState(sensorName=="LEGACY_UI_ADVICE_SHOWN", value=="ON") ||
+ SensorState(sensorName=="HEATING_DISABLED", value=="Yes")
+)
+then
+ commands.execute("LEGACY_UI_ADVICE_TEXT", "You're doing great!");
+ commands.execute("LEGACY_UI_ADVICE_SHOWN", "OFF");
+ insert(new AdviceGiven("You're doing great!"));
+end
+
+declare AdviceGiven
+ @role(event)
+ @expires(10m)
+ advice : String
+end
+
+rule "-PSB: advices given counter"
+when
+ SensorState(sensorName=="LEGACY_UI_ADVICE_TEXT", value!="", value!="You're doing great!")
+ //AdviceGiven(advice!="You're doing great!") // This one fires with the same advice
+then
+ int cnt = 0;
+ try{
+ cnt = Integer.parseInt(persistence.readData("LEGACY_UI_ADVICE_TEXTGIVEN_0","0"));
+ }finally{
+ cnt += 1;
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_0", cnt);
+ }
+end
+
+rule "-PSB: vacation inc"
+ timer(int:300ms)
+when
+ SensorState(sensorName=="VACATION_DAYS", $v: value)
+ SensorState(sensorName=="VACATION_DAYS.inc", value=="ON")
+then
+ commands.execute("VACATION_DAYS", Integer.parseInt($v.toString())+1);
+ commands.execute("VACATION_DAYS.inc", "OFF");
+end
+
+rule "-PSB: vacation dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName=="VACATION_DAYS", $v: value, eval(Integer.parseInt(value.toString()) > 0))
+ SensorState(sensorName=="VACATION_DAYS.dec", value=="ON")
+then
+ commands.execute("VACATION_DAYS", Integer.parseInt($v.toString())-1);
+ commands.execute("VACATION_DAYS.dec", "OFF");
+end
+
+rule "-PSB: vacation inc/dec" // needed so the ON value does not hang
+ salience -10
+ timer(int:300ms)
+when
+ SensorState(sensorName matches "VACATION_DAYS...c", $s: sensorName, value=="ON")
+then
+ commands.execute($s, "OFF");
+end
+
+rule "PSB: start next week stats"
+ timer(cron: 0 0 0 ? * 1) // Every Sunday morning at midnight
+when
+ // Time scheduled
+ Number($arrive: longValue>0) from accumulate(SensorState(sensorName matches "UI_ESTIMATED_TIME_ARRIVAL.*", $a:value), sum(util.parseTimestamp($a)))
+ Number($departure: longValue>0) from accumulate(SensorState(sensorName matches "UI_ESTIMATED_TIME_DEPARTURE.*", $d:value), sum(util.parseTimestamp($d)))
+then
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_4" ,persistence.readData("MANUAL_SET_TEMP_COUNT_PER_WEEK_3","0"));
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_3" ,persistence.readData("MANUAL_SET_TEMP_COUNT_PER_WEEK_2","0"));
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_2" ,persistence.readData("MANUAL_SET_TEMP_COUNT_PER_WEEK_1","0"));
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_1" ,persistence.readData("MANUAL_SET_TEMP_COUNT_PER_WEEK_0","0"));
+ persistence.writeData("MANUAL_SET_TEMP_COUNT_PER_WEEK_0" , "0");
+
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_4" ,persistence.readData("MANUAL_SCHEDULE_CHANGE_COUNT_3","0"));
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_3" ,persistence.readData("MANUAL_SCHEDULE_CHANGE_COUNT_2","0"));
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_2" ,persistence.readData("MANUAL_SCHEDULE_CHANGE_COUNT_1","0"));
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_1" ,persistence.readData("MANUAL_SCHEDULE_CHANGE_COUNT_0","0"));
+ persistence.writeData("MANUAL_SCHEDULE_CHANGE_COUNT_0" , "0");
+
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_4" ,persistence.readData("LEGACY_UI_ADVICE_TEXTGIVEN_3","0"));
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_3" ,persistence.readData("LEGACY_UI_ADVICE_TEXTGIVEN_2","0"));
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_2" ,persistence.readData("LEGACY_UI_ADVICE_TEXTGIVEN_1","0"));
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_1" ,persistence.readData("LEGACY_UI_ADVICE_TEXTGIVEN_0","0"));
+ persistence.writeData("LEGACY_UI_ADVICE_TEXTGIVEN_0" , "0");
+
+ // Time scheduled
+ long minutes = ($departure-$arrive)/60000;
+ long hours = minutes/60;
+
+ persistence.writeData("PRESENCE_HOURS_CUMULATIVE_WEEK_4" ,persistence.readData("PRESENCE_HOURS_CUMULATIVE_WEEK_3","0:00"));
+ persistence.writeData("PRESENCE_HOURS_CUMULATIVE_WEEK_3" ,persistence.readData("PRESENCE_HOURS_CUMULATIVE_WEEK_2","0:00"));
+ persistence.writeData("PRESENCE_HOURS_CUMULATIVE_WEEK_2" ,persistence.readData("PRESENCE_HOURS_CUMULATIVE_WEEK_1","0:00"));
+ persistence.writeData("PRESENCE_HOURS_CUMULATIVE_WEEK_1" , String.format("%2d:%02d", hours, minutes%60));
+end
+
+// Fake sensors start
+
+rule "-Fake sensors init"
+then
+ commands.execute("SENSOR_OUTSIDE_TEMP", "15\u00B0");
+ commands.execute("SENSOR_INSIDE_TEMP", "19.5\u00B0");
+ commands.execute("SENSOR_PRESENCE", "off");
+ commands.execute("SENSOR_WINDOW", "off");
+end
+
+rule "--Fake sensors Toutside inc"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SENSOR_OUTSIDE_TEMP", $v: value, eval(util.parseDouble(value) < 50))
+ SensorState(sensorName == "SENSOR_OUTSIDE_TEMP.inc" , value == "on")
+then
+ commands.execute("SENSOR_OUTSIDE_TEMP.inc","off");
+ commands.execute("SENSOR_OUTSIDE_TEMP", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
+end
+
+rule "--Fake sensors Toutside dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SENSOR_OUTSIDE_TEMP", $v: value, eval(util.parseDouble(value) > -40))
+ SensorState(sensorName == "SENSOR_OUTSIDE_TEMP.dec" , value == "on")
+then
+ commands.execute("SENSOR_OUTSIDE_TEMP.dec","off");
+ commands.execute("SENSOR_OUTSIDE_TEMP", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
+end
+
+rule "--Fake sensors Tinside inc"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SENSOR_INSIDE_TEMP", $v: value, eval(util.parseDouble(value) < 40))
+ SensorState(sensorName == "SENSOR_INSIDE_TEMP.inc" , value == "on")
+then
+ commands.execute("SENSOR_INSIDE_TEMP.inc","off");
+ commands.execute("SENSOR_INSIDE_TEMP", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
+end
+
+rule "--Fake sensors Tinside dec"
+ timer(int:300ms)
+when
+ SensorState(sensorName == "SENSOR_INSIDE_TEMP", $v: value, eval(util.parseDouble(value) > 0))
+ SensorState(sensorName == "SENSOR_INSIDE_TEMP.dec" , value == "on")
+then
+ commands.execute("SENSOR_INSIDE_TEMP.dec","off");
+ commands.execute("SENSOR_INSIDE_TEMP", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
+end
+
+rule "--Fake sensors PIR off"
+ timer(int: 2s)
+when
+ SensorState(sensorName=="SENSOR_PRESENCE", value=="on")
+then
+ commands.execute("SENSOR_PRESENCE", "off");
+end
+
+// Fake sensors end
\ No newline at end of file
diff --git a/manager/test/src/test/resources/org.openremote.test.rules/ClimateControl.drl b/manager/test/src/test/resources/org.openremote.test.rules/ClimateControl.drl
deleted file mode 100644
index bd259311d..000000000
--- a/manager/test/src/test/resources/org.openremote.test.rules/ClimateControl.drl
+++ /dev/null
@@ -1,1358 +0,0 @@
-package org.openremote.agent.test.rules;
-
-import java.util.concurrent.*;
-import java.util.Date;
-import java.text.SimpleDateFormat;
-import java.io.*;
-import org.openremote.agent.sensor.*;
-
-global org.openremote.agent.command.Commands commands;
-global org.openremote.agent.rules.RulePersistence persistence;
-global org.openremote.agent.rules.RuleUtil util;
-global com.fasterxml.jackson.databind.ObjectMapper JSON;
-global java.util.logging.Logger LOG;
-
-declare SensorState
- @role(event)
-end
-
-rule "-PSB: Init"
-salience 10
-then
- commands.execute("VR1.ET", persistence.readData("VR1.ET","--:--"));
- commands.execute("VR1.ET.inc", "OFF");
- commands.execute("VR1.ET.dec", "OFF");
- commands.execute("VETA.inc", "OFF");
- commands.execute("VETA.dec", "OFF");
- commands.execute("VETD.inc", "OFF");
- commands.execute("VETD.dec", "OFF");
- commands.execute("VR1.COMFORT",persistence.readData("VR1.COMFORT","20.0\u00B0"));
- commands.execute("VR1.COMFORT.inc","OFF");
- commands.execute("VR1.COMFORT.dec","OFF");
- commands.execute("VR1.TEMPERATURE","19.5\u00B0");
- commands.execute("VR1.TEMPERATURE.inc","OFF");
- commands.execute("VR1.TEMPERATURE.dec","OFF");
- commands.execute("VNEXTACTION",persistence.readData("VNEXTACTION","-")); // Earlier arrive with reset
- commands.execute("VPERSONSENSETIME","-");
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", "0");
- commands.execute("VHEATINGSETPOINT", "16");
- commands.execute("VWINDOW","Closed");
- commands.execute("VADVICEDONE", "OFF");
- commands.execute("VSUMMER", "No");
- commands.execute("VADVICE", "You're doing great!");
- commands.execute("VACATION.inc", "OFF");
- commands.execute("VACATION.dec", "OFF");
- commands.execute("VACATION", persistence.readData("VACATION", "0"));
- commands.execute("VTOTALSCORE",persistence.readData("VTOTALSCORE", "0"));
- commands.execute("VLEVEL", persistence.readData("VLEVEL", "0"));
- commands.execute("VATA", persistence.readData("VATA","-"));
- commands.execute("VATD", persistence.readData("VATD","-"));
- commands.execute("VPRESENCE","No");
- commands.execute("GVconfig",persistence.readData("GVconfig", "OpenRemote"));
- commands.execute("VArrivalBackground", "on");
- commands.execute("VDepartureBackground", "off");
-end
-
-rule "-PSB: Init ETA when empty"
-salience 9
-when
- SensorState(sensorName matches "VETA.*", $s: sensorName, value=="")
-then
- commands.execute($s, persistence.readData($s, "09:00"));
-end
-
-rule "-PSB: Init ETD when empty"
-salience 8
-when
- SensorState(sensorName matches "VETD.*", $s: sensorName, value=="")
-then
- commands.execute($s, persistence.readData($s, "17:00"));
-end
-
-rule "--Show timers"
-salience 10
-// timer(int:100)
-when
- SensorState(sensorName=="TimerEEEE", $a:value!="N/A")
- SensorState(sensorName=="Timerd", $b:value!="N/A")
- SensorState(sensorName=="TimerHH", $d:value!="N/A")
- SensorState(sensorName=="TimerMMM", $c:value!="N/A")
- SensorState(sensorName=="TimerEEE", value!="N/A")
-then
- LOG.info("Sensor clock is: "+$a+" "+$b+" "+$c+" "+$d);
- LOG.info("Drools SessionClock() is: "+(new java.util.Date(drools.getWorkingMemory().getSessionClock().getCurrentTime())).toString());
-end
-
-rule "--PSB: store values"
-timer(int: 2s)
-when
-(
- SensorState($s:sensorName matches "VET.*", $v:value!="", eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VACATION", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VTOTALSCORE", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VLEVEL", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VR1.COMFORT", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VATA", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VATD", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VNEXTACTION", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VR1.ET", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VETA", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName=="VETD", $v:value, eval(!persistence.readData($s,"").equals($v))) ||
- SensorState($s:sensorName matches "^GV.*", $v:value, eval(!persistence.readData($s,"").equals($v)))
-)
-then
- LOG.fine($s+" old value: "+persistence.readData($s,"||")+"; new value:"+$v.toString());
- persistence.writeData($s, $v);
-end
-
-rule "-PSB: VR1.ET Inc"
- timer(int:300ms) // debounce & protect double click
-when
- SensorState(sensorName == "VR1.ET", $v: value)
- SensorState(sensorName == "VR1.ET.inc" , value == "ON")
-then
- commands.execute("VR1.ET", util.shiftTime($v.toString(), 5));
- commands.execute("VR1.ET.inc", "off");
- commands.execute("VR1.ET.dec", "OFF");
-end
-
-rule "-PSB: VETA Inc"
- timer(int:300ms) // debounce & protect double click
-when
- SensorState(sensorName == "VETA", $v: value)
- SensorState(sensorName == "VETA.inc" , value == "ON")
-then
- commands.execute("VETA", util.shiftTime($v.toString(), 5));
- commands.execute("VETA.inc", "off");
- commands.execute("VETA.dec", "OFF");
-end
-
-rule "-PSB: VETD Inc"
- timer(int:300ms) // debounce & protect double click
-when
- SensorState(sensorName == "VETD", $v: value)
- SensorState(sensorName == "VETD.inc" , value == "ON")
-then
- commands.execute("VETD", util.shiftTime($v.toString(), 5));
- commands.execute("VETD.inc", "off");
- commands.execute("VETD.dec", "OFF");
-end
-
-rule "-PSB: VR1.ET Dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.ET", $v: value)
- SensorState(sensorName == "VR1.ET.dec" , value == "ON")
-then
- commands.execute("VR1.ET", util.shiftTime($v.toString(), -15));
- commands.execute("VR1.ET.inc", "OFF");
- commands.execute("VR1.ET.dec", "off");
-end
-
-rule "-PSB: VETA Dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "VETA", $v: value)
- SensorState(sensorName == "VETA.dec" , value == "ON")
-then
- commands.execute("VETA", util.shiftTime($v.toString(), -15));
- commands.execute("VETA.inc", "OFF");
- commands.execute("VETA.dec", "off");
-end
-
-rule "-PSB: VETD Dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "VETD", $v: value)
- SensorState(sensorName == "VETD.dec" , value == "ON")
-then
- commands.execute("VETD", util.shiftTime($v.toString(), -15));
- commands.execute("VETD.inc", "OFF");
- commands.execute("VETD.dec", "off");
-end
-
-rule "PSB: VUSERSCHEDULECHANGES change counter"
- timer(int: 30s) // Wait 30s to mark user's schedule change
-when
-(
- SensorState($s:sensorName == "VR1.ET.inc" , value == "off") ||
- SensorState($s:sensorName == "VR1.ET.dec" , value == "off") ||
- SensorState($s:sensorName == "VETA.inc" , value == "off") ||
- SensorState($s:sensorName == "VETA.dec" , value == "off") ||
- SensorState($s:sensorName == "VETD.inc" , value == "off") ||
- SensorState($s:sensorName == "VETD.dec" , value == "off")
-)
-then
- // off - changed by user
- // OFF - idle state after restart
- commands.execute($s, "OFF");
- int cnt = 0;
- try{
- cnt = Integer.parseInt(persistence.readData("VUSERSCHEDULECHANGES","0"));
- }finally{
- cnt += 1;
- persistence.writeData("VUSERSCHEDULECHANGES", cnt);
- }
-end
-
-rule "PSB: set departure time on manual VR1.ET change"
- salience 10
- timer(int: 300ms)
-when
- SensorState(sensorName == "VR1.ET", $v: value)
-(
- SensorState(sensorName == "VR1.ET.inc" , value == "ON") ||
- SensorState(sensorName == "VR1.ET.dec" , value == "ON") ||
- SensorState(sensorName == "VETD.inc", value == "ON") ||
- SensorState(sensorName == "VETD.dec", value == "ON")
-)
- SensorState(sensorName == "VNEXTACTION", value == "-")
-then
- commands.execute("VNEXTACTION", "Departure");
-end
-
-rule "PSB: VR1.COMFORT inc"
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.COMFORT", $v: value, eval(util.parseDouble(value) < 24))
- SensorState(sensorName == "VR1.COMFORT.inc" , value == "ON")
-then
- commands.execute("VR1.COMFORT.inc","off");
- commands.execute("VR1.COMFORT.dec","OFF");
- commands.execute("VR1.COMFORT", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
-end
-
-rule "PSB: VR1.COMFORT dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.COMFORT", $v: value, eval(util.parseDouble(value) > 18))
- SensorState(sensorName == "VR1.COMFORT.dec" , value == "ON")
-then
- commands.execute("VR1.COMFORT.inc","OFF");
- commands.execute("VR1.COMFORT.dec","off");
- commands.execute("VR1.COMFORT", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
-end
-
-rule "PSB: VR1.COMFORT INC/dec" // needed when change on the boundary
- salience -10
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.COMFORT.inc" , value == "ON")
-then
- commands.execute("VR1.COMFORT.inc","off");
- commands.execute("VR1.COMFORT.dec","OFF");
-end
-
-rule "PSB: VR1.COMFORT inc/DEC" // needed when change on the boundary
- salience -10
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.COMFORT.dec" , value == "ON")
-then
- commands.execute("VR1.COMFORT.inc","OFF");
- commands.execute("VR1.COMFORT.dec","off");
-end
-
-rule "PSB: VR1.TEMPERATURE inc"
- timer(int:300ms)
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName == "VR1.TEMPERATURE", $v: value, eval(util.parseDouble(value) <26))
- SensorState(sensorName == "VR1.TEMPERATURE.inc" , value == "ON")
-then
- commands.execute("VR1.TEMPERATURE.inc","off");
- commands.execute("VR1.TEMPERATURE.dec","OFF"); // Do not increase change counter
- commands.execute("VR1.TEMPERATURE", util.shiftDouble($v.toString(), 0.5, "\u00B0"));
-end
-
-rule "PSB: VR1.TEMPERATURE dec"
- timer(int:300ms)
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName == "VR1.TEMPERATURE", $v: value, eval(util.parseDouble(value) > 16)) // Lower temp limit
- SensorState(sensorName == "VR1.TEMPERATURE.dec" , value == "ON")
-then
- commands.execute("VR1.TEMPERATURE.inc","OFF");
- commands.execute("VR1.TEMPERATURE.dec","off");
- commands.execute("VR1.TEMPERATURE", util.shiftDouble($v.toString(), -0.5, "\u00B0"));
-end
-
-rule "PSB: VR1.TEMPERATURE INC/dec" // needed when on the boundary and in summer
- salience -10
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.TEMPERATURE.inc" , value == "ON")
-then
- commands.execute("VR1.TEMPERATURE.inc","off");
- commands.execute("VR1.TEMPERATURE.dec","OFF");
-end
-
-rule "PSB: VR1.TEMPERATURE inc/DEC" // needed when on the boundary and in summer
- salience -10
- timer(int:300ms)
-when
- SensorState(sensorName == "VR1.TEMPERATURE.dec" , value == "ON")
-then
- commands.execute("VR1.TEMPERATURE.inc","OFF");
- commands.execute("VR1.TEMPERATURE.dec","off");
-end
-
-rule "PSB: VR1.TEMPERATURE change counter"
- timer(int: 30s) // Wait 30s to mark user's temperature change
-when
-(
- SensorState($s:sensorName == "VR1.TEMPERATURE.inc" , value == "off") ||
- SensorState($s:sensorName == "VR1.TEMPERATURE.dec" , value == "off") ||
- SensorState($s:sensorName == "VR1.COMFORT.inc" , value == "off") ||
- SensorState($s:sensorName == "VR1.COMFORT.dec" , value == "off")
-)
-then
- // off - changed by user
- // OFF - idle state after restart
- commands.execute($s, "OFF");
- int cnt = 0;
- try{
- cnt = Integer.parseInt(persistence.readData("VSETTEMPCHANGES","0"));
- }finally{
- cnt += 1;
- persistence.writeData("VSETTEMPCHANGES", cnt);
- }
-end
-
-rule "PSB: VR1.TEMPERATURE change summer"
-salience 10
-when
- SensorState(sensorName=="VSUMMER", value=="Yes")
-(
- SensorState(sensorName == "VR1.TEMPERATURE.inc" , $s: sensorName, value == "ON") ||
- SensorState(sensorName == "VR1.TEMPERATURE.dec", $s: sensorName, value == "ON")
-)
-then
- commands.execute($s, "OFF");
-end
-
-rule "PSB: set departure on manual TEMPERATURE change after expected attendance"
-salience 10
- timer(int:300ms)
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName == "VR1.ET", $et: value)
-(
- SensorState(sensorName == "VR1.TEMPERATURE.inc" , value == "ON") ||
- SensorState(sensorName == "VR1.TEMPERATURE.dec" , value == "ON")
-)
- SensorState(sensorName == "VNEXTACTION", value == "-")
-then
- // Set departure time when temp manually adjusted after leave
- commands.execute("VNEXTACTION", "Departure");
- commands.execute("VR1.ET", util.shiftTime($et.toString(), 60));
- commands.execute("VETD", util.shiftTime($et.toString(), 60));
-end
-
-rule "-PSB: Move ETA to ET at midnight"
-when
- SensorState(sensorName=="TimerEEE", $e:value)
- SensorState(sensorName=="TimerHH",$h:value,eval(util.parseTimestamp(value) >= util.parseTimestamp("00:02"))) // Wait 2 minutes to be sure that $e is OK
- SensorState(sensorName matches ("VETA."+$e), eval(util.parseTimestamp(value) > util.parseTimestamp($h)), $va:value)
- SensorState(sensorName matches ("VETD."+$e), $vd: value)
- SensorState(sensorName=="VNEXTACTION", value=="-")
- SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())==0))
-then
- commands.execute("VR1.ET", $va.toString());
- commands.execute("VETA", $va.toString());
- commands.execute("VETD", $vd.toString());
- commands.execute("VNEXTACTION", "Arrive");
-end
-
-rule "-Move ETA ETD for current day"
-when
- SensorState(sensorName=="TimerEEE", $e:value)
- SensorState(sensorName matches ("VETA."+$e), $va:value)
- SensorState(sensorName matches ("VETD."+$e), $vd: value)
-then
- commands.execute("VETA", $va.toString());
- commands.execute("VETD", $vd.toString());
-end
-
-rule "-PSB: reset VATA"
-when
- SensorState(sensorName=="VNEXTACTION", value=="Arrive")
-then
- commands.execute("VATA","-");
-end
-
-rule "-PSB: reset VATD"
-when
- SensorState(sensorName=="VATA",value=="-")
-then
- commands.execute("VATD","-");
-end
-
-rule "PSB: decrease vacation counter at midnight"
-when
- $timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
- SensorState(sensorName=="VACATION", $v: value, eval(Integer.parseInt(value.toString())>0), this before [2m] $timer)
-then
- commands.execute("VACATION", Integer.parseInt($v.toString())-1);
-end
-
-rule "PSB: reset action at midnight"
-when
- SensorState(sensorName=="TimerHH", value!="N/A", eval(value.toString().substring(0,5).equals("00:00"))) // more reliable than timer(cron: )
-then
- commands.execute("VR1.ET", "-");
- commands.execute("VNEXTACTION", "-");
-end
-
-rule "-PSB: Move ETD to ET at arrive init"
-// This one is needed for cases when system is restart after arrive time
-when
- SensorState(sensorName=="TimerEEE",$e:value)
- SensorState(sensorName=="TimerHH",$h:value)
- SensorState(sensorName matches ("VETA."+$e), eval(util.parseTimestamp(value) <= util.parseTimestamp($h)), eval(value.toString().length()==5))
- SensorState(sensorName matches ("VETD."+$e), $vd:value, eval(value.toString().length()==5))
-// SensorState(sensorName=="VNEXTACTION", value=="-")
- SensorState(sensorName=="VR1.ET", value == "--:--")
-then
- commands.execute("VR1.ET", $vd.toString());
- commands.execute("VETD", $vd.toString());
- commands.execute("VNEXTACTION", "Departure");
-end
-
-rule "-PSB: Move ETD to ET at arrive"
-when
- SensorState(sensorName=="TimerEEE",$e:value)
- SensorState(sensorName=="TimerHH",$h:value)
- SensorState(sensorName=="VNEXTACTION", value=="Arrive")
- SensorState(sensorName matches ("VETD."+$e), $vd:value)
- SensorState(sensorName=="VETA", value != "-", value != "--:--", value != "status")
- SensorState(sensorName=="VETA", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
- SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())==0))
-then
- commands.execute("VR1.ET", $vd.toString());
- commands.execute("VNEXTACTION", "Departure");
-end
-
-rule "PSB: actual arrival time earlier when temperature increased and person detected"
-timer(int: 10s) // Prevent glitch at midnight reset
-when
- // Before attendance schedule
- SensorState(sensorName=="TimerHH",$h:value)
- SensorState(sensorName=="VNEXTACTION", value=="Arrive")
- // Temperature increased manually (higher than ECO)
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VR1.COMFORT", $vc: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble(value) > java.lang.Math.max(util.parseDouble($vc)-5.0, 16.0)))
- // Person detected
- SensorState(sensorName=="VPERSONSENSE", value == "1")
- SensorState(sensorName=="VATA",value=="-")
-then
- commands.execute("VR1.ET", $h.toString().substring(0,5));
-end
-
-rule "PSB: fetch actual arrival time"
-when
- SensorState(sensorName=="TimerHH", $h:value)
- SensorState(sensorName=="VATA", value == "-")
- SensorState(sensorName=="VNEXTACTION", value=="Departure")
- SensorState(sensorName=="VPERSONSENSE", value=="1")
-then
- commands.execute("VATA", $h.toString().substring(0,5));
-end
-
-rule "PSB: fetch earlier actual arrival time up to 30 min v02"
-when
- SensorState(sensorName=="TimerHH", $h:value, eval(util.parseTimestamp(value) >= util.parseTimestamp("04:30"))) // Earliest time of arrival is 4:30 AM
- SensorState(sensorName=="VATA", value == "-")
- SensorState(sensorName=="VNEXTACTION", value=="Arrive")
- SensorState(sensorName=="VPERSONSENSE", value=="1")
- SensorState(sensorName=="VETA", value != "-", value != "--:--")
- SensorState(sensorName=="VETA", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
-then
- commands.execute("VATA", $h.toString().substring(0,5));
-end
-
-rule "PSB: Move - to ET at end of work"
-timer(int: 1s) // avoid racing
-when
- SensorState(sensorName=="TimerHH",$h:value)
- SensorState(sensorName=="VETD", value != "-", value != "--:--")
- SensorState(sensorName=="VETD", eval(util.parseTimestamp(value) < util.parseTimestamp($h)))
- SensorState(sensorName=="VNEXTACTION", value=="Departure")
-then
- commands.execute("VR1.ET", "-");
- commands.execute("VNEXTACTION", "-");
-end
-
-rule "PSB: Move - to ET on vacation"
-when
- SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())>0))
-then
- commands.execute("VR1.ET", "-");
- commands.execute("VNEXTACTION", "-");
-end
-
-rule "PSB: fetch actual departure time"
-when
- SensorState(sensorName=="VATA", value != "-")
- SensorState(sensorName=="VATD", value == "-")
- SensorState(sensorName=="VNEXTACTION", value=="-")
- SensorState(sensorName=="VPERSONSENSETIME", $v:value, eval(value.toString().length()>4))
-then
- commands.execute("VATD", $v.toString().substring(0,5));
- commands.execute("VPERSONSENSETIME","-");
-end
-
-rule "PSB: fetch later departure time"
-when
- SensorState(sensorName=="TimerEEE",$e:value)
- SensorState(sensorName=="VNEXTACTION", value=="-")
- SensorState(sensorName matches ("VETD."+$e), $vd:value)
- SensorState(sensorName=="VATA", value != "-")
- SensorState(sensorName=="VATD", value != "-")
- SensorState(sensorName=="VPERSONSENSETIME", $v:value, eval(value.toString().length()>4),
- eval(util.parseTimestamp(value)<=util.parseTimestamp(util.shiftTime($vd,15))), // Till 15 min after scheduled departure
- eval(util.parseTimestamp(value)<=util.parseTimestamp("23:55"))) // Till 23:55 - does not wrap on midnight
- SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())==0))
-then
- commands.execute("VATD", $v.toString().substring(0,5));
- commands.execute("VPERSONSENSETIME","-");
-end
-
-rule "PSB: adjust estimated times at midnight"
-when
- SensorState(sensorName=="TimerEEE", $e: value)
- $timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(value.toString().substring(0,5).equals("23:58"))) // more reliable than timer(cron: )
- SensorState(sensorName matches ("VETD."+$e), $ved:value, this before [1m] $timer) // Loop cut
- SensorState(sensorName matches ("VETA."+$e), $vea:value, this before [1m] $timer)
- SensorState(sensorName=="VATD", $vd:value, value!="-")
- SensorState(sensorName=="VATA", $va:value, value!="-")
- SensorState(sensorName=="VACATION", eval(Integer.parseInt(value.toString())==0))
-then
- Double alpha = 2.0/(3+1); // 3 stays for 3 days exponential average
- long nt = (long) (alpha*util.parseTimestamp($va) + (1-alpha)*util.parseTimestamp($vea));
- commands.execute("VETA."+$e.toString(), util.formatTimestamp(nt));
- LOG.fine("EA="+$vea.toString()+" AA="+$va.toString()+" NA="+ util.formatTimestamp(nt));
- nt = (long) (alpha*util.parseTimestamp($vd) + (1-alpha)*util.parseTimestamp($ved));
- commands.execute("VETD."+$e.toString(), util.formatTimestamp(nt));
- LOG.fine("ED="+$ved.toString()+" AD="+$vd.toString()+" ND="+ util.formatTimestamp(nt));
-end
-
-rule "--PSB: move sense"
-when
- SensorState($s:sensorName=="FS.PIR", value=="on")
- SensorState(sensorName=="TimerHH", $h:value)
-then
- LOG.info("Move sense on "+$s+" @"+$h);
- commands.execute("VPERSONSENSETIME", $h.toString());
-end
-
-rule "--pir echo"
-when
- SensorState(sensorName=="FS.PIR", $v:value)
- SensorState(sensorName=="TimerHH", $h:value)
-then
- LOG.info("PIR state "+$v.toString()+" @"+$h);
-end
-
-rule "-PSB: person sense"
-when
- SensorState($s:sensorName=="FS.PIR", value=="on")
- SensorState(sensorName=="VPERSONSENSE", value!="1")
-then
- commands.execute("VPERSONSENSE", "1");
-end
-
-rule "-PSB: no person sense"
-timer(int: 2s)
-when
- SensorState(sensorName=="FS.PIR", value!="on")
- SensorState(sensorName=="VPERSONSENSE", value!="0")
-then
- commands.execute("VPERSONSENSE", "0");
-end
-
-rule "-PSB: window open sense"
-when
- SensorState(sensorName=="FS.Window", value=="on")
-then
- commands.execute("VWINDOW","Open");
-end
-
-rule "-PSB: window closed sense"
-when
- SensorState(sensorName=="FS.Window", value=="off")
-then
- commands.execute("VWINDOW","Closed");
-end
-
-rule "--FS outside temperature sense"
-when
- SensorState(sensorName=="FS.Toutside", $v: value)
-then
- commands.execute("VOUTSIDE", $v.toString() );
- LOG.fine("Fake outside temperature: "+$v.toString() );
-end
-
-rule "--FS inside temperature sense"
-when
- SensorState(sensorName=="FS.Tinside", $v: value)
-then
- LOG.fine("Fake inside temperature: "+ $v.toString() );
- commands.execute("VROOMTEMPERATURE", $v.toString() );
-end
-
-rule "PSB: Presence"
-when
- SensorState(sensorName == "VPERSONSENSE", value == "1")
- SensorState(sensorName=="VNEXTACTION", value=="Departure") // within expected attendance schedule
-then
- commands.execute("VPRESENCE","Yes");
-end
-
-rule "PSB: Absence when 30 min no movement"
-timer(int: 30m)
-when
- SensorState(sensorName == "VPERSONSENSE", value == "0")
- SensorState(sensorName=="VNEXTACTION", value=="Departure") // within expected attendance schedule
-then
- commands.execute("VPRESENCE","No");
-end
-
-rule "PSB: Absence after 15 min v02"
-timer(int: 15m)
-when
- SensorState(sensorName == "VPERSONSENSE", value == "0")
-then
- commands.execute("VPRESENCE","No");
-end
-
-rule "-PSB: Absence after scheduled presence time"
-when
- SensorState(sensorName=="VNEXTACTION", value!="Departure") // outsidse expected attendance schedule
-then
- commands.execute("VPRESENCE","No");
-end
-
-rule "-PSB: heating ECO"
-when
-(
- SensorState(sensorName=="VNEXTACTION", value!="Departure") || // outsidse expected attendance schedule
- SensorState(sensorName=="VSUMMER", value=="Yes")
-)
-then
- commands.execute("VHEATING","ECO");
-end
-
-rule "-PSB: heating Stand-by from ECO"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VNEXTACTION", value=="Departure") // within expected attendance schedule
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VHEATING", value == "ECO")
- SensorState(sensorName=="VR1.COMFORT", $vc: value)
-then
- commands.execute("VR1.TEMPERATURE", $vc.toString());
- commands.execute("VHEATING", "Stand-by");
-end
-
-rule "-PSB: heating Stand-by from ECO preheating 30 min v02"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VNEXTACTION", value=="Arrive") // within expected attendance schedule
- SensorState(sensorName=="VHEATING", value == "ECO")
- SensorState(sensorName=="VR1.COMFORT", $vc: value)
-
- SensorState(sensorName=="TimerHH", $h:value, eval(util.parseTimestamp(value) >= util.parseTimestamp("04:30"))) // Earliest time of arrival is 4:30 AM
- SensorState(sensorName=="VETA", value != "-", value != "--:--")
- SensorState(sensorName=="VETA", eval(util.parseTimestamp(util.shiftTime(value,-30)) <= util.parseTimestamp($h)))
-then
- commands.execute("VR1.TEMPERATURE", $vc.toString());
- commands.execute("VHEATING", "Stand-by");
-end
-
-rule "-PSB: heating Stand-by from Comfort"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VNEXTACTION", value=="Departure") // within expected attendance schedule
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VHEATING", value == "Comfort")
- SensorState(sensorName=="VR1.COMFORT", $vc: value)
- SensorState(sensorName=="VR1.TEMPERATURE", value==$vc) // Only when no manual temperature increase
-then
- commands.execute("VHEATING","Stand-by");
-end
-
-rule "-PSB: heating Comfort on presence"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VPRESENCE", value=="Yes")
- SensorState(sensorName=="VR1.COMFORT", $v: value)
-then
- commands.execute("VHEATING","Comfort");
- commands.execute("VR1.TEMPERATURE", $v.toString());
-end
-
-rule "-PSB: heating Comfort on temperature increase"
-timer(int: 1s) // debounce
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VR1.COMFORT", $vc: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble(value) > util.parseDouble($vc)))
- SensorState(sensorName=="VHEATING", value != "Comfort")
-then
- commands.execute("VHEATING","Comfort");
-end
-
-rule "-PSB: heating setpoint ECO"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATING", value=="ECO")
- SensorState(sensorName=="VR1.COMFORT", $v: value)
-then
- String s = $v.toString();
- Double t;
- try{
- t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-5); // 5 degrees below comfort
- } catch (NumberFormatException e){
- t = 16.0;
- }
- commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
- commands.execute("VR1.TEMPERATURE", String.format("%.1f\u00B0",t));
-end
-
-rule "-PSB: heating setpoint ECO summer"
-when
- SensorState(sensorName=="VSUMMER", value=="Yes")
- SensorState(sensorName=="VHEATING", value=="ECO")
- SensorState(sensorName=="VR1.COMFORT", $v: value)
-then
- String s = $v.toString();
- Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-5); // 5 degrees below comfort
- commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
- commands.execute("VR1.TEMPERATURE", "-");
-end
-
-rule "-PSB: heating setpoint Stand-by"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATING", value=="Stand-by")
- SensorState(sensorName=="VR1.COMFORT", $v: value)
- SensorState(sensorName=="VR1.TEMPERATURE", value==$v) // When temperature changed manually keep it till ECO
-then
- String s = $v.toString();
- Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1))-1); // 1 degree below comfort
- commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
- commands.execute("VR1.TEMPERATURE", s); // But the user is not aware as on display there is comfort
-end
-
-rule "-PSB: heating setpoint Comfort"
-timer(int: 1s) // avoid race between "VHEATING" & "VR1.TEMPERATURE"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATING", value=="Comfort")
- SensorState(sensorName=="VR1.TEMPERATURE", $v: value) // set by rule "PSB: heating Comfort" to VR1.COMFORT or manually
-then
- String s = $v.toString();
- Double t = java.lang.Math.max(16.0, Double.parseDouble(s.substring(0,s.length()-1)));
- commands.execute("VHEATINGSETPOINT", String.format("%.1f",t));
-end
-
-rule "-PSB: leaves 0"
-when
- SensorState(sensorName=="VLEAVES", value=="0.0")
-then
- commands.execute("VLEAF1", "l0.png");
- commands.execute("VLEAF2", "l0.png");
- commands.execute("VLEAF3", "l0.png");
-end
-
-rule "-PSB: leaves 0.5"
-when
- SensorState(sensorName=="VLEAVES", value=="0.5")
-then
- commands.execute("VLEAF1", "l1.png");
- commands.execute("VLEAF2", "l0.png");
- commands.execute("VLEAF3", "l0.png");
-end
-
-rule "-PSB: leaves 1"
-when
- SensorState(sensorName=="VLEAVES", value=="1.0")
-then
- commands.execute("VLEAF1", "l2.png");
- commands.execute("VLEAF2", "l0.png");
- commands.execute("VLEAF3", "l0.png");
-end
-
-rule "-PSB: leaves 1.5"
-when
- SensorState(sensorName=="VLEAVES", value=="1.5")
-then
- commands.execute("VLEAF1", "l2.png");
- commands.execute("VLEAF2", "l1.png");
- commands.execute("VLEAF3", "l0.png");
-end
-
-rule "-PSB: leaves 2"
-when
- SensorState(sensorName=="VLEAVES", value=="2.0")
-then
- commands.execute("VLEAF1", "l2.png");
- commands.execute("VLEAF2", "l2.png");
- commands.execute("VLEAF3", "l0.png");
-end
-
-rule "-PSB: leaves 2.5"
-when
- SensorState(sensorName=="VLEAVES", value=="2.5")
-then
- commands.execute("VLEAF1", "l2.png");
- commands.execute("VLEAF2", "l2.png");
- commands.execute("VLEAF3", "l1.png");
-end
-
-rule "-PSB: leaves 3"
-when
- SensorState(sensorName=="VLEAVES", value=="3.0")
-then
- commands.execute("VLEAF1", "l2.png");
- commands.execute("VLEAF2", "l2.png");
- commands.execute("VLEAF3", "l2.png");
-end
-
-rule "-PSB: energy efficiency 1"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="No")
-then
- commands.execute("VLEAVES", "0.0");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 2"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
- SensorState(sensorName=="VWINDOW", value=="Open")
-then
- commands.execute("VLEAVES", "0.5");
- commands.execute("VSCORE", 0);
-end
-
-// v02
-rule "-PSB: energy efficiency 2-1 v02"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) < 23)) // Comfort, Comfort-, Comfort--
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VOUTSIDE", $t: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
-then
- commands.execute("VLEAVES", "0.5");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 2-2 v02"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="No")
-then
- commands.execute("VLEAVES", "0.5");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 2-3 v02"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) < 23), eval(Double.parseDouble(value.toString()) >= 18)) // Comfort, Comfort-, Comfort--, not eco
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="No")
-then
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", 0);
-end
-// v02
-
-rule "-PSB: energy efficiency 3"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="No")
-then
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 4"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open") // Added because otherwise it overrules efficiency 11
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
-then
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 5"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATING", value=="Stand-by")
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
-then
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 6"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
- SensorState(sensorName=="VWINDOW", value=="Open")
-then
- commands.execute("VLEAVES", "1.0");
- commands.execute("VSCORE", 0);
-end
-
-rule "-PSB: energy efficiency 7"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VHEATING", value=="Stand-by")
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VOUTSIDE", $t: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
-then
- commands.execute("VLEAVES", "1.5");
- commands.execute("VSCORE", 1);
-end
-
-rule "-PSB: energy efficiency 8"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VHEATING", value=="ECO")
- SensorState(sensorName=="VPRESENCE", value=="No")
- SensorState(sensorName=="VOUTSIDE", $t: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
-then
- commands.execute("VLEAVES", "1.5");
- commands.execute("VSCORE", 1);
-end
-
-rule "-PSB: energy efficiency 9"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 23)) // Comfort+
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
-then
- commands.execute("VLEAVES", "1.5");
- commands.execute("VSCORE", 1);
-end
-
-rule "-PSB: energy efficiency 10"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 20), eval(Double.parseDouble(value.toString()) < 21)) // Comfort-
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
- SensorState(sensorName=="VOUTSIDE", $t: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble($t) < util.parseDouble(value))) // Lower outside temperature
-then
- commands.execute("VLEAVES", "1.5");
- commands.execute("VSCORE", 1);
-end
-
-rule "-PSB: energy efficiency 11"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 21), eval(Double.parseDouble(value.toString()) < 23)) // Comfort
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
-then
- commands.execute("VLEAVES", "2.0");
- commands.execute("VSCORE", 2);
-end
-
-rule "-PSB: energy efficiency 12 v02"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) >= 20), eval(Double.parseDouble(value.toString()) < 21)) // Comfort-
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes") // v02
-then
- commands.execute("VLEAVES", "2.5");
- commands.execute("VSCORE", 3);
-end
-
-rule "-PSB: energy efficiency 13"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) < 20)) // Comfort--
- SensorState(sensorName=="VHEATING", value!="ECO") // needed because of race
- SensorState(sensorName=="VPRESENCE", value=="Yes")
- SensorState(sensorName=="VOUTSIDE", $t: value)
- SensorState(sensorName=="VR1.TEMPERATURE", eval(util.parseDouble($t) >= util.parseDouble(value))) // Higher outside temperature
-then
- commands.execute("VLEAVES", "3.0");
- commands.execute("VSCORE", 4);
-end
-
-rule "-PSB: energy efficiency 14"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATING", value=="ECO")
- SensorState(sensorName=="VPRESENCE", value=="No")
-then
- commands.execute("VLEAVES", "3.0");
- commands.execute("VSCORE", 4);
-end
-
-rule "-PSB: energy efficiency 15"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VWINDOW", value=="Closed")
- SensorState(sensorName=="VHEATINGSETPOINT", eval(Double.parseDouble(value.toString()) < 20)) // Comfort--
- SensorState(sensorName=="VPRESENCE", value=="Yes") // No important IMHO
-then
- commands.execute("VLEAVES", "3.0");
- commands.execute("VSCORE", 4);
-end
-
-rule "-PSB: energy efficiency Summer"
-when
- SensorState(sensorName=="VSUMMER", value=="Yes")
-then
- commands.execute("VLEAVES", "3.0");
- commands.execute("VSCORE", 4);
-end
-
-rule "--PSB: increase total score every 15m"
-when
- $timer: SensorState(sensorName=="TimerHH", value!="N/A", eval(Integer.parseInt(value.toString().substring(3,5)) % 15 == 0)) // more reliable than timer(cron: )
- SensorState(sensorName=="VSCORE", $s: value)
- SensorState(sensorName=="VTOTALSCORE", $ts: value, this before [1m] $timer)
-then
- commands.execute("VTOTALSCORE", Integer.parseInt($ts.toString())+Integer.parseInt($s.toString()));
-end
-
-rule "PSB: reward"
-when
- $ts: SensorState(sensorName=="VTOTALSCORE", $s: value, eval(Integer.parseInt(value.toString()) >= 1000))
- SensorState(sensorName=="VLEVEL", $l: value, this before [1m] $ts)
-then
- Integer i = Integer.parseInt($s.toString());
- commands.execute("VTOTALSCORE", i-1000); // Reset score
- commands.execute("VLEVEL", Integer.parseInt($l.toString())+1);
-end
-
-rule "--PSB: display totalscore"
-when
- SensorState(sensorName=="VTOTALSCORE", $ts: value)
-then
- commands.execute("VTOTALSCOREdisp", $ts+" / 1000");
-end
-
-rule "PSB: summer"
-timer(int: 1h)
-when
-// SensorState(sensorName=="VR1.COMFORT", $sp: value)
-// SensorState(sensorName=="VOUTSIDE", value!="", eval(util.parseDouble($sp) <= util.parseDouble(value) )) // Outside temp higher than set point
- SensorState(sensorName=="VOUTSIDE", $o:value) // Only for logging
- SensorState(sensorName=="YT.summer", value=="0") // Y-con test
- SensorState(sensorName=="VSUMMER", value!="Yes")
-then
- LOG.fine("Summer is ON; outside="+$o.toString());
- commands.execute("VSUMMER", "Yes");
-end
-
-rule "PSB: no summer"
-timer(int: 1h)
-when
-// SensorState(sensorName=="VR1.COMFORT", $sp: value)
-// SensorState(sensorName=="VOUTSIDE", value!="", eval(util.parseDouble($sp) > util.parseDouble(value) )) // Outside temp lower than set point
- SensorState(sensorName=="VOUTSIDE", $o:value) // Only for logging
- SensorState(sensorName=="YT.summer", value=="1") // Y-con test
- SensorState(sensorName=="VSUMMER", value!="No")
-then
- LOG.fine("Summer is OFF; outside="+$o.toString());
- commands.execute("VSUMMER", "No");
-end
-
-rule "-PSB: advice 1"
-when
- SensorState(sensorName=="VWINDOW", value=="Open")
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VHEATINGSETPOINT", $sp: value)
- SensorState(sensorName=="VOUTSIDE", value!="", eval(Double.parseDouble($sp.toString()) > util.parseDouble(value) )) // Outside temp lower than set point
-then
- commands.execute("VADVICE", "It's more energy efficient to close the windows when it is colder outside than it is inside");
- commands.execute("VADVICEDONE", "OFF");
- insert(new AdviceGiven("It's more energy efficient to close the windows when it is colder outside than it is inside"));
-end
-
-rule "-PSB: advice 1 done"
-when
- SensorState(sensorName=="VHEATINGSETPOINT", $sp: value)
-(
- SensorState(sensorName=="VWINDOW", value=="Closed") ||
- SensorState(sensorName=="VOUTSIDE", value!="", eval(Double.parseDouble($sp.toString()) <= util.parseDouble(value) )) // Outside temp lower than set point
-)
- SensorState(sensorName=="VADVICE",eval(value.toString().substring(0,9).equals("It's more")))
-then
- commands.execute("VADVICE", "You're doing great!");
- commands.execute("VADVICEDONE", "OFF");
-end
-
-rule "-PSB: advice 2"
-when
- SensorState(sensorName=="VSUMMER", value=="No")
- SensorState(sensorName=="VR1.COMFORT", eval(util.parseDouble(value) > 20.5)) // Average is 20 hardcoded or from sensor?
-then
- commands.execute("VADVICE", "Your comfort temperature is set higher than average. You can adjust it on the settings page.");
- commands.execute("VADVICEDONE", "OFF");
- insert(new AdviceGiven("Your comfort temperature is set higher than average. You can adjust it on the settings page."));
-end
-
-rule "-PSB: advice 2 done"
-when
- SensorState(sensorName=="VR1.COMFORT", eval(util.parseDouble(value) <= 20.5)) // Average is 20 hardcoded or from sensor?
- SensorState(sensorName=="VADVICE",eval(value.toString().substring(0,12).equals("Your comfort")))
-then
- commands.execute("VADVICE", "You're doing great!");
- commands.execute("VADVICEDONE", "OFF");
-end
-
-rule "-PSB: advice 3"
-when
-// irregular attendence
-then
- commands.execute("VADVICEDONE", "OFF");
-end
-
-rule "-PSB: advice 4"
-when
-(
- SensorState(sensorName=="VADVICEDONE", value=="ON") ||
- SensorState(sensorName=="VSUMMER", value=="Yes")
-)
-then
- commands.execute("VADVICE", "You're doing great!");
- commands.execute("VADVICEDONE", "OFF");
- insert(new AdviceGiven("You're doing great!"));
-end
-
-declare AdviceGiven
- @role(event)
- @expires(10m)
- advice : String
-end
-
-rule "-PSB: advices given counter"
-when
- SensorState(sensorName=="VADVICE", value!="", value!="You're doing great!")
- //AdviceGiven(advice!="You're doing great!") // This one fires with the same advice
-then
- int cnt = 0;
- try{
- cnt = Integer.parseInt(persistence.readData("VADVICEGIVEN","0"));
- }finally{
- cnt += 1;
- persistence.writeData("VADVICEGIVEN", cnt);
- }
-end
-
-rule "-PSB: vacation inc"
- timer(int:300ms)
-when
- SensorState(sensorName=="VACATION", $v: value)
- SensorState(sensorName=="VACATION.inc", value=="ON")
-then
- commands.execute("VACATION", Integer.parseInt($v.toString())+1);
- commands.execute("VACATION.inc", "OFF");
-end
-
-rule "-PSB: vacation dec"
- timer(int:300ms)
-when
- SensorState(sensorName=="VACATION", $v: value, eval(Integer.parseInt(value.toString()) > 0))
- SensorState(sensorName=="VACATION.dec", value=="ON")
-then
- commands.execute("VACATION", Integer.parseInt($v.toString())-1);
- commands.execute("VACATION.dec", "OFF");
-end
-
-rule "-PSB: vacation inc/dec" // needed so the ON value does not hang
- salience -10
- timer(int:300ms)
-when
- SensorState(sensorName matches "VACATION...c", $s: sensorName, value=="ON")
-then
- commands.execute($s, "OFF");
-end
-
-rule "PSB: start next week stats"
- timer(cron: 0 0 0 ? * 1) // Every Sunday morning at midnight
-when
- // Time scheduled
- Number($arrive: longValue>0) from accumulate(SensorState(sensorName matches "VETA.*", $a:value), sum(util.parseTimestamp($a)))
- Number($departure: longValue>0) from accumulate(SensorState(sensorName matches "VETD.*", $d:value), sum(util.parseTimestamp($d)))
-then
- persistence.writeData("VSETTEMPCHANGES4" ,persistence.readData("VSETTEMPCHANGES3","0"));
- persistence.writeData("VSETTEMPCHANGES3" ,persistence.readData("VSETTEMPCHANGES2","0"));
- persistence.writeData("VSETTEMPCHANGES2" ,persistence.readData("VSETTEMPCHANGES1","0"));
- persistence.writeData("VSETTEMPCHANGES1" ,persistence.readData("VSETTEMPCHANGES","0"));
- persistence.writeData("VSETTEMPCHANGES" , "0");
-
- persistence.writeData("VUSERSCHEDULECHANGES4" ,persistence.readData("VUSERSCHEDULECHANGES3","0"));
- persistence.writeData("VUSERSCHEDULECHANGES3" ,persistence.readData("VUSERSCHEDULECHANGES2","0"));
- persistence.writeData("VUSERSCHEDULECHANGES2" ,persistence.readData("VUSERSCHEDULECHANGES1","0"));
- persistence.writeData("VUSERSCHEDULECHANGES1" ,persistence.readData("VUSERSCHEDULECHANGES","0"));
- persistence.writeData("VUSERSCHEDULECHANGES" , "0");
-
- persistence.writeData("VADVICEGIVEN4" ,persistence.readData("VADVICEGIVEN3","0"));
- persistence.writeData("VADVICEGIVEN3" ,persistence.readData("VADVICEGIVEN2","0"));
- persistence.writeData("VADVICEGIVEN2" ,persistence.readData("VADVICEGIVEN1","0"));
- persistence.writeData("VADVICEGIVEN1" ,persistence.readData("VADVICEGIVEN","0"));
- persistence.writeData("VADVICEGIVEN" , "0");
-
- // Time scheduled
- long minutes = ($departure-$arrive)/60000;
- long hours = minutes/60;
-
- persistence.writeData("VHOURSPRESENT4" ,persistence.readData("VHOURSPRESENT3","0:00"));
- persistence.writeData("VHOURSPRESENT3" ,persistence.readData("VHOURSPRESENT2","0:00"));
- persistence.writeData("VHOURSPRESENT2" ,persistence.readData("VHOURSPRESENT1","0:00"));
- persistence.writeData("VHOURSPRESENT1" , String.format("%2d:%02d", hours, minutes%60));
-end
-
-// New StrijpS 2016
-
-rule "-PSB16: Full Timer"
-when
- SensorState(sensorName=="TimerEEEE", $EEEE:value)
- SensorState(sensorName=="Timerd", $d: value)
- SensorState(sensorName=="TimerMMM", $MMM:value)
-then
- commands.execute("VTimer", $EEEE.toString()+" "+$d.toString()+" "+$MMM.toString()+". I will be:");
-end
-
-rule "-PSB16: background arrival on"
-when
- SensorState(sensorName=="TimerHH", $h:value)
- SensorState(sensorName=="VETA", eval(util.parseTimestamp(value) > util.parseTimestamp($h)) )
- SensorState(sensorName=="VArrivalBackground", value!="on")
-then
- commands.execute("VArrivalBackground", "on");
-end
-
-rule "-PSB16: background departure on"
-when
- SensorState(sensorName=="TimerHH", $h:value)
- SensorState(sensorName=="VETD", eval(util.parseTimestamp(value) > util.parseTimestamp($h)) )
- SensorState(sensorName=="VDepartureBackground", value!="on")
-then
- commands.execute("VDepartureBackground", "on");
-end
-
-rule "-PSB16: background arrival off"
-when
- SensorState(sensorName=="TimerHH", $h:value)
- SensorState(sensorName=="VETA", eval(util.parseTimestamp(value) <= util.parseTimestamp($h)) )
- SensorState(sensorName=="VArrivalBackground", value!="off")
-then
- commands.execute("VArrivalBackground", "off");
-end
-
-rule "-PSB16: background departure off"
-when
- SensorState(sensorName=="TimerHH", $h:value)
- SensorState(sensorName=="VETD", eval(util.parseTimestamp(value) <= util.parseTimestamp($h)) )
- SensorState(sensorName=="VDepartureBackground", value!="off")
-then
- commands.execute("VDepartureBackground", "off");
-end
-
-// Fake sensors start
-
-rule "-Fake sensors init"
-then
- commands.execute("FS.Toutside", "15\u00B0");
- commands.execute("FS.Tinside", "19.5\u00B0");
- commands.execute("FS.PIR", "off");
- commands.execute("FS.Window", "off");
-end
-
-rule "--Fake sensors Toutside inc"
- timer(int:300ms)
-when
- SensorState(sensorName == "FS.Toutside", $v: value, eval(util.parseDouble(value) < 50))
- SensorState(sensorName == "FS.Toutside.inc" , value == "on")
-then
- commands.execute("FS.Toutside.inc","off");
- commands.execute("FS.Toutside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
-end
-
-rule "--Fake sensors Toutside dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "FS.Toutside", $v: value, eval(util.parseDouble(value) > -40))
- SensorState(sensorName == "FS.Toutside.dec" , value == "on")
-then
- commands.execute("FS.Toutside.dec","off");
- commands.execute("FS.Toutside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
-end
-
-rule "--Fake sensors Tinside inc"
- timer(int:300ms)
-when
- SensorState(sensorName == "FS.Tinside", $v: value, eval(util.parseDouble(value) < 40))
- SensorState(sensorName == "FS.Tinside.inc" , value == "on")
-then
- commands.execute("FS.Tinside.inc","off");
- commands.execute("FS.Tinside", util.shiftDouble($v.toString(), 0.1, "\u00B0"));
-end
-
-rule "--Fake sensors Tinside dec"
- timer(int:300ms)
-when
- SensorState(sensorName == "FS.Tinside", $v: value, eval(util.parseDouble(value) > 0))
- SensorState(sensorName == "FS.Tinside.dec" , value == "on")
-then
- commands.execute("FS.Tinside.dec","off");
- commands.execute("FS.Tinside", util.shiftDouble($v.toString(), -0.1, "\u00B0"));
-end
-
-rule "--Fake sensors PIR off"
- timer(int: 2s)
-when
- SensorState(sensorName=="FS.PIR", value=="on")
-then
- commands.execute("FS.PIR", "off");
-end
-
-// Fake sensors end
\ No newline at end of file