This page last changed on May 19, 2015 by ckbsmart.

Hello,
I have been trying to make a Button that increments a in memory value(Alarm-pin1 Sensor). Every time the Button is pushed on, the number for the in memory value goes up with one. I first saw that the incrementation does not stop because the value of in memory sensor(the range sensor Alarm-pin1 Sensor) changes and I have that value as a request after WHEN statement so I tryed to make it only active when a new Event is triggered. I am not sure why it's not working.... can someone please help?

rule "test rule"
when
Switch(source == "Alarm Sensor", value == "on")
( $pin : Range( source == "Alarm-pin1 Sensor" ) AND
Event(source == "Alarm Sensor") )
then
Integer contor = Integer.parseInt( $pin.getValue().toString() ) + 1;
execute.command("Alarm-pin1", contor);

end

Increasing/decreasing of in-memory variables is a part of my design. The rules for doing it look like this:

rule "ARC: VACSetPoint.inc"
  timer(int:300ms) // debounce
when
  Event(source == "GVACSetPoint", $v: value, eval(_GetTemp(value) <30))
  Event($s:source == "VACSetPoint.inc", value == "ON")
then
  execute.command($s,"OFF");
  execute.command("GVACSetPoint", _ShiftTemp($v.toString(), 0.5));
end

rule "ARC: VACSetPoint.dec"
  timer(int:300ms) // debounce
when
  Event(source == "GVACSetPoint", $v: value, eval(_GetTemp(value) >15))
  Event($s:source == "VACSetPoint.dec", value == "ON")
then
  execute.command($s,"OFF");
  execute.command("GVACSetPoint", _ShiftTemp($v.toString(), -0.5));
end

You can adopt them for your needs.

Posted by aktur at May 19, 2015 14:35

I am not sure what is that I am doing wrong.

THIS WORKS:
rule "Alarm get1"
when
Event(source == "Alarm-get1 Sensor", value == "ON")
then
execute.command("Alarm-get1","OFF");
execute.command("Alarm-pin1", 1);
end

THIS DOES NOT WORK
rule "Alarm get1"
when
Event(source == "Alarm-pin1 Sensor", $pin: value)
Event(source == "Alarm-pin2 Sensor", $pin2: value)
Event(source == "Alarm-get1 Sensor", value == "ON")
then
execute.command("Alarm-get1","OFF");
execute.command("Alarm-pin1", 1);
end

Posted by ckbsmart at May 19, 2015 16:46

I not see anything wrong in rules, but there can be problems in sensor definition itself.

Please remember that there is a long time living bug in the drools engine implementation, that you need to hard reboot the controller after every design sync.

Posted by aktur at May 19, 2015 18:13

For example if i do the following:

rule "hour Increase"
when
  Event(source=="hour-Alarm", $hour: value)
  Event($s:source=="hPlus", value=="ON")
then
  execute.command($s, "off");
  int cnt = Integer.parseInt($hour.toString())+1;
  execute.command("hour-Alarm", ""+cnt);
end

I am not sure why when i press the button it increments twice(+2) instead of incrementing only once.

Posted by ckbsmart at May 23, 2015 19:45

Because you don't debounce the button.

Posted by aktur at May 23, 2015 20:57
Document generated by Confluence on Jun 05, 2016 09:33