CustomState( source == "oregon1temp", eval(Float.parseFloat((String)value) < -5.0 ))
rule "Start car heater"
when
CustomState( source == "GVMonSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "1" ) ||
CustomState( source == "GVTueSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "2" ) ||
CustomState( source == "GVWedSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "3" ) ||
CustomState( source == "GVThuSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "4" ) ||
CustomState( source == "GVFriSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "5" ) ||
CustomState( source == "GVSatSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "6" ) ||
CustomState( source == "GVSunSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "7" )
CustomState( source == "GVActivateTimer1Status", value == "on" )
Event( source == "TimeSweHour", $htime1:value )
Event( source == "GVStartTimeHour1", value == $htime1 )
Event( source == "TimeSweMinute", $mtime1:value )
Event( source == "GVStartTimeMinute1", value == $mtime1 )
then
execute.command( "Garage Socket(ON)" );
end
rule "Stop car heater"
when
CustomState( source == "GVMonSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "1" ) ||
CustomState( source == "GVTueSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "2" ) ||
CustomState( source == "GVWedSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "3" ) ||
CustomState( source == "GVThuSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "4" ) ||
CustomState( source == "GVFriSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "5" ) ||
CustomState( source == "GVSatSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "6" ) ||
CustomState( source == "GVSunSwitchStatus", value == "on" ) && Event( source == "Weekday", value == "7" )
CustomState( source == "GVActivateTimer1Status", value == "on" )
Event( source == "TimeSweHour", $htime2:value )
Event( source == "GVStopTimeHour1", value == $htime2 )
Event( source == "TimeSweMinute", $mtime2:value )
Event( source == "GVStopTimeMinute1", value == $mtime2 )
then
execute.command( "Garage Socket(OFF)" );
end
Cheers,
Erik
ERROR 2016-10-23 15:00:52,511 : Rule definition 'CarHeater.drl' could not be deployed. See errors below.ERROR 2016-10-23 15:00:52,512 : Rule Compilation error The method _ShiftTime(String, int) is undefined for the type Rule_CarHeaterTimeInc1227608620ERROR 2016-10-23 15:00:52,513 : Rule Compilation error The method _ShiftTime(String, int) is undefined for the type Rule_CarHeaterTimeDec816805169
package org.openremote.controller.protocol;import java.util.concurrent.*;import java.util.Date;import java.text.SimpleDateFormat;import java.io.*;import org.openremote.controller.model.event.*;
global org.openremote.controller.statuscache.CommandFacade execute;
rule "inc/dec clear" salience -10 timer(int:300ms)when Event($s:source matches "^.*\\.(de|in)c$", value!="OFF")then execute.command($s,"OFF");end
rule "CarHeaterTimeInc" timer(int:300ms) // debounce & protect double clickwhen Event(source == "GVCHTime", $v: value) Event($s:source == "CHTime.inc" , value == "ON")then execute.command($s,"OFF"); execute.command("GVCHTime", _ShiftTime($v.toString(), 5));end
rule "CarHeaterTimeDec" timer(int:300ms)when Event(source == "GVCHTime", $v: value) Event($s:source == "CHTime.dec" , value == "ON")then execute.command($s,"OFF"); execute.command("GVCHTime", _ShiftTime($v.toString(), -5));end
function String _ShiftTime(Object o, int min){
String mt = o.toString();
if(mt.equals("")){mt="-";}
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
Date date = null;
if(mt.substring(0,1).equals("-")){
date = new Date();
date.setTime(date.getTime()+60*60000);
}else{
date = sdf.parse(mt);
date.setTime(date.getTime()+min*60000);
}
return(sdf.format(date));
}