This page last changed on Jan 22, 2016 by nokk3r1.

Hello,

I have problem which is bit weird: A rule which compares two sensor values fires multiple times after controller has been up and running some time. First 24h it works as it should(correctly fires only once). On second day it begins to fire two times and on third day three times and so on. Also after first day it sometimes fires even though it shouldn't(eval is false).

I have also other similar rule which use the other sensor data but it works as it should. Below is screenshot about it.

Below are my rules(I have changed the command to be scene and also tested two CustomStates instead of event since taking screenshot, but it didn't help...)

rule "Boileron"
when
CustomState(source=="CurrentPriceSensor", $pri11 : value)
CustomState(source == "cheap3", $pri12 : value)
eval(Float.parseFloat((String)$pri12)>=Float.parseFloat((String)$pri11))
then
execute.command("BoilerScene", 0 );
end

rule "Boileroff"
when
CustomState(source=="CurrentPriceSensor", $pri21 : value)
CustomState(source == "cheap3", $pri22 : value)
eval(Float.parseFloat((String)$pri22)<Float.parseFloat((String)$pri21))
then
execute.command("BoilerScene", 1 );
end

rule "HeatingcontrolCheap"
when
Event( source=="CurrentPriceSensor", $pri31 : value)
CustomState( source == "cheap8", $pri32 : value)
eval(Float.parseFloat((String)$pri32)>=Float.parseFloat((String)$pri31))
Switch( source == "KotonaTietoSensor", value == "on" )
then
execute.command("LammitysScene", 1 );
end

rule "HeatingControlExpensive"
when
Event( source=="CurrentPriceSensor", $pri41 : value)
CustomState( source == "cheap8", $pri42 : value)
eval(Float.parseFloat((String)$pri42) < Float.parseFloat((String)$pri41))
Switch( source == "KotonaTietoSensor", value =="on")
then
execute.command("LammitysScene", 2 );
end

I'm running latest stable controller(from february) on x64 debian jessie and
java version "1.6.0_36"
OpenJDK Runtime Environment (IcedTea6 1.13.8) (6b36-1.13.8-1~deb7u1)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

Is it some weird bug in drools or what?


multiple.JPG (image/jpeg)

Using of eval() is depreciated. You are going outside of Drools and rare things can happen, especially when you are using unsafe typecasting and parsing. Instead try:

rule "Boileron"
when
  CustomState(source=="CurrentPriceSensor", $pri11 : value)
  CustomState(source == "cheap3", value>=$pri11)
then
  execute.command("BoilerScene", 0 );
end
Posted by aktur at Jan 23, 2016 12:21

I use similar code when comparing range sensors, but it doesn't work on custom sensors:

ERROR 2016-01-23 14:35:02,572 : Rule definition 'heatingcontrol.drl' could not be deployed. See errors below.
ERROR 2016-01-23 14:35:02,572 : Evaluator '>=' does not support type 'ValueType = 'String'
ERROR 2016-01-23 14:35:02,572 : Unable to create restriction '[VariableRestriction: >= $pri11 ]' for field 'value' in the rule 'Boileron'
ERROR 2016-01-23 14:35:02,573 : Evaluator '<' does not support type 'ValueType = 'String'
ERROR 2016-01-23 14:35:02,573 : Unable to create restriction '[VariableRestriction: < $pri21 ]' for field 'value' in the rule 'Boileroff'
ERROR 2016-01-23 14:35:02,573 : There was an error parsing the rule definition 'heatingcontrol.drl' : Could not parse knowledge.
java.lang.IllegalArgumentException: Could not parse knowledge.

Values in those sensors are read using http GET commands and are in format 1.2345 if that helps

Posted by nokk3r1 at Jan 23, 2016 12:48

Then simply change CustomState() to Event(), what they in fact are. You don't need to use anything else than Event().

rule "Boileron"
when
  Event(source=="CurrentPriceSensor", $pri11 : value)
  Event(source == "cheap3", value>=$pri11)
then
  execute.command("BoilerScene", 0 );
end
Posted by aktur at Jan 23, 2016 12:57

Thank you Michal!

Will report back tomorrow.

Posted by nokk3r1 at Jan 23, 2016 16:06
Document generated by Confluence on Jun 05, 2016 09:33