And here's the complete code of the rules for my thermostat:
package org.openremote.controller.protocol;
import java.util.*;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.*;
import org.openremote.controller.model.event.*;
import org.openremote.controller.utils.Logger;
import org.openremote.controller.Constants;
global org.openremote.controller.statuscache.CommandFacade execute;
function void log(String msg)
{
Logger.getLogger(Constants.RUNTIME_EVENTPROCESSOR_LOG_CATEGORY + ".drools").debug(msg);
}
declare Event
@role(event)
end
rule "init"
salience 10
when
CustomState(source == "kachel-setpoint-status", setpointinit : value)
Event(source == "kachel-setpoint", value == "")
then
execute.command("kachel-setpoint",setpointinit);
execute.command("kachel-setpoint-inc","OFF");
execute.command("kachel-setpoint-dec","OFF");
end
function Double _GetTemp(Object o){
String s = o.toString();
try{
if(s.length()>1){
return(Double.parseDouble(s.substring(0, s.length()-1)));
}else{
return(0.0);
}
} catch (NumberFormatException e) {
return(0.0);
}
}
function String _ShiftTemp(Object o, double sh){
String s = o.toString();
try{
Double t = Double.parseDouble(s.substring(0,s.length()-1)) + sh;
return(String.format("%.1f\u00B0",t));
} catch (NumberFormatException e) {
return("0.0\u00B0");
}
}
function String _ShiftTemp_noformat(Object o, double sh){
String s = o.toString();
try{
Double t = Double.parseDouble(s.substring(0,s.length()-1)) + sh;
String rs = t.toString();
return(rs.substring(0,4));
} catch (NumberFormatException e) {
return("0.0\u00B0");
}
}
rule "kachel-setpoint inc"
timer(int:10ms)
when
Event(source == "kachel-setpoint", $v: value, eval(_GetTemp(value) < 23))
Event(source == "kachel-setpoint-inc" , value == "ON")
then
execute.command("kachel-setpoint-inc","off");
execute.command("kachel-setpoint-dec","OFF");
execute.command("kachel-setpoint", _ShiftTemp($v.toString(), 0.5));
execute.command("kachel-setpoint-set", _ShiftTemp_noformat($v.toString(), 0.5));
end
rule "kachel-setpoint dec"
timer(int:10ms)
when
Event(source == "kachel-setpoint", $v: value, eval(_GetTemp(value) > 15))
Event(source == "kachel-setpoint-dec" , value == "ON")
then
execute.command("kachel-setpoint-inc","OFF");
execute.command("kachel-setpoint-dec","off");
execute.command("kachel-setpoint", _ShiftTemp($v.toString(), -0.5));
execute.command("kachel-setpoint-set", _ShiftTemp_noformat($v.toString(), -0.5));
end
rule "kachel-setpoint INC/dec" // needed when change on the boundary
salience -10
timer(int:300ms)
when
Event(source == "kachel-setpoint-inc" , value == "ON")
then
execute.command("kachel-setpoint-inc","off");
execute.command("kachel-setpoint-dec","OFF");
end
rule "kachel-setpoint inc/DEC" // needed when change on the boundary
salience -10
timer(int:300ms)
when
Event(source == "kachel-setpoint-dec" , value == "ON")
then
execute.command("kachel-setpoint-inc","OFF");
execute.command("kachel-setpoint-dec","off");
end
On Sunday, May 14, 2017 at 7:05:37 PM UTC+2, ReneS wrote: