Bug with the rules

Hello

I’m having trouble with the 2.6.0 beta3 controller

I am using java 8

By the time I have the rules that does not work anymore.

in the log y 'has this error which appears:

2017-11-07 18:17:31,914 ERROR [Polling Sensor Thread ID = 100118, Name =‘virtual_volet_salon_status’]: Error in executing rule : virtual_volet_salon_status:java.lang.Integer cannot be cast to java.lang.String

Event org.openremote.controller.model.event.CustomState@88f8eeca not processed!

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at java.lang.String.compareTo(String.java:111)

at ConditionEvaluator39b0ecb05ada40729038151938a5ae45.evaluate(Unknown Source)

at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:258)

at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:226)

at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:138)

at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:113)

at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:76)

at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:519)

at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)

at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)

at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)

at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)

at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)

at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)

at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)

at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1007)

at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1350)

at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1288)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1306)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1297)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1278)

at org.openremote.controller.statuscache.rules.RuleEngine.push(RuleEngine.java:203)

at org.openremote.controller.statuscache.EventProcessorChain.push(EventProcessorChain.java:196)

at org.openremote.controller.statuscache.StatusCache.update(StatusCache.java:293)

at org.openremote.controller.model.sensor.Sensor.update(Sensor.java:367)

at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Sensor.java:655)

at java.lang.Thread.run(Thread.java:744)

2017-11-07 18:17:41,929 ERROR [Polling Sensor Thread ID = 100266, Name =‘thermostat_varia’]: Error in executing rule : thermostat_varia:java.lang.Integer cannot be cast to java.lang.String

Event Range Event (ID = 100266, Source = ‘thermostat_varia’, Value = ‘15’, Boundaries = [15…30]) not processed!

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at java.lang.String.compareTo(String.java:111)

at ConditionEvaluatorb7240dd69dd44b86906e848648e42427.evaluate(Unknown Source)

at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:258)

at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:226)

at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:138)

at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:113)

at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:76)

at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:519)

at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)

at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)

at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)

at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)

at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)

at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)

at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)

at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1007)

at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1350)

at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1288)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1306)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1297)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1278)

at org.openremote.controller.statuscache.rules.RuleEngine.push(RuleEngine.java:203)

at org.openremote.controller.statuscache.EventProcessorChain.push(EventProcessorChain.java:196)

at org.openremote.controller.statuscache.StatusCache.update(StatusCache.java:293)

at org.openremote.controller.model.sensor.Sensor.update(Sensor.java:367)

at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Sensor.java:655)

at java.lang.Thread.run(Thread.java:744)

2017-11-07 18:17:41,934 ERROR [Polling Sensor Thread ID = 100291, Name =‘VKEY4’]: Error in executing rule : VKEY4:java.lang.Integer cannot be cast to java.lang.String

Event org.openremote.controller.model.event.CustomState@4e092ee not processed!

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at java.lang.String.compareTo(String.java:111)

at ConditionEvaluator39b0ecb05ada40729038151938a5ae45.evaluate(Unknown Source)

at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:258)

at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:226)

at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:138)

at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:113)

at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:76)

at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:519)

at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)

at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)

at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)

at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)

at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)

at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)

at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)

at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1007)

at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1350)

at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1288)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1306)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1297)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1278)

at org.openremote.controller.statuscache.rules.RuleEngine.push(RuleEngine.java:203)

at org.openremote.controller.statuscache.EventProcessorChain.push(EventProcessorChain.java:196)

at org.openremote.controller.statuscache.StatusCache.update(StatusCache.java:293)

at org.openremote.controller.model.sensor.Sensor.update(Sensor.java:367)

at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Sensor.java:655)

at java.lang.Thread.run(Thread.java:744)

2017-11-07 18:19:28,634 ERROR [Polling Sensor Thread ID = 100266, Name =‘thermostat_varia’]: Error in executing rule : thermostat_varia:java.lang.Integer cannot be cast to java.lang.String

Event Range Event (ID = 100266, Source = ‘thermostat_varia’, Value = ‘22’, Boundaries = [15…30]) not processed!

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at java.lang.String.compareTo(String.java:111)

at ConditionEvaluatorb7240dd69dd44b86906e848648e42427.evaluate(Unknown Source)

at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:258)

at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:226)

at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:138)

at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:113)

at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:76)

at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:519)

at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)

at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)

at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)

at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)

at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)

at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)

at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)

at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1007)

at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1350)

at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1288)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1306)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1297)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1278)

at org.openremote.controller.statuscache.rules.RuleEngine.push(RuleEngine.java:203)

at org.openremote.controller.statuscache.EventProcessorChain.push(EventProcessorChain.java:196)

at org.openremote.controller.statuscache.StatusCache.update(StatusCache.java:293)

at org.openremote.controller.model.sensor.Sensor.update(Sensor.java:367)

at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Sensor.java:655)

at java.lang.Thread.run(Thread.java:744)

``

It seems like a cast problem

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

Show your rule, it should be easy to fix.

I think I have things to improve in my rules but in general it works.

it may be these rules that are problematic because it requires the function strings

rule “Key pressed”

timer(int: 300ms) // debounce

when

$code:Event(source==“VCODE”)

Event($s:source matches “VKEY\d+”, value==“ON”)

then

execute.command($s, “off”);

if($code.getValue().toString().equals("-")){

execute.command("VCODE", $s.substring(4,5));

}else{

execute.command("VCODE", $code.getValue().toString() + $s.substring(4,5));

}

end

rule “Code clear”

timer(int: 5s) // clear code after 5 seconds

when

Event(source==“VCODE”, value!="-")

then

execute.command(“VKEY”, “-”);

execute.command(“VCODE”, “-”);

end

rule “Last key”

when

Event($s:source matches “VKEY\d”, value==“ON”)

then

execute.command(“VKEY”, $s.substring(4,5));

end

``

You have many rules, too many to read and analyze in my spare time. Anyway, you can narrow it down by looking in the rules log file logs/rules/drools.log, where you should be able to see which rule triggers the exception. On a quick look I see that you are doing numerical compare like
Event( source == “battery_multisensor”, value == 255)

Not sure how the “battery_multisensor” is defined. If it is of type Custom the the value is a string and the LHS should be

Event( source == “battery_multisensor”, value == “255”)

For more complicated <= compare you should either use a sensor which returns numeric value or use eval() with parseInt or parseDouble inside.

do I have to change this rule ?

rule “battery_capteur_fumee_moyen” when

Event( source == “battery_capteur_fumee”, value >= 10 && <= 49)

then

execute.command( “virtual_battery_capteur_fumee”, 1 );

end

``

like this :

rule “battery_capteur_fumee_moyen” when

Event( source == “battery_capteur_fumee”, value >= “10” && <= “49”)

then

execute.command( “virtual_battery_capteur_fumee”, 1 );

end

``

thank you

Probably it won’t work in Drools which is based on Java. For this you better use eval() like in the example:

Event( source == “battery_capteur_fumee”, eval(Integer.parseInt(value.toString()) >= 10), eval(Integer.parseInt(value.toString()) <= 49))

I would also like to add the value 255 to reduce my number of rules.

can I do like this:

Event( source == “battery_capteur_fumee”, eval(Integer.parseInt(value.toString()) <= 9))

or

Event( source == “battery_capteur_fumee”, value == “255”)

``

or rather

Event( source == “battery_capteur_fumee”, eval(Integer.parseInt(value.toString()) <= 9))

or

Event( source == “battery_capteur_fumee”,eval(Integer.parseInt(value.toString()) == 255))

``

Thank you for your help

use || between eval()

so

Event( source == “battery_capteur_fumee”, eval(Integer.parseInt(value.toString()) <= 9)) || eval(Integer.parseInt(value.toString()) == 255))

``

it’s better to use “eval(Integer.parseInt(value.toString())” because it’s numeric value or it’s because there’s a comparison ?

I’m sorry but I admit that I’m lost

That’s what the sensor returns to me:

Apparently this rule is problematic !!

rule “thermostat_salon_1” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, value < $h)

then

execute.command( “chauffage_on” );

end

rule “thermostat_salon_2” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, value > $h)

then

execute.command( “chauffage_off” );

end

``

TRACE 2017-11-19 13:13:37,291 (Drools): Inserted event Range Event (ID = 100266, Source = ‘thermostat_varia_salon’, Value = ‘15’, Boundaries = [15…30])

TRACE 2017-11-19 13:13:37,291 (Drools): Fact count: 68

ERROR 2017-11-19 13:13:37,292 (Drools): Error in executing rule : thermostat_varia_salon:java.lang.Integer cannot be cast to java.lang.String

Event Range Event (ID = 100266, Source = ‘thermostat_varia_salon’, Value = ‘15’, Boundaries = [15…30]) not processed!

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

at java.lang.String.compareTo(String.java:111)

at ConditionEvaluator15fe55c2cfa74c5ebfec216d2c692deb.evaluate(Unknown Source)

at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:258)

at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:226)

at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:138)

at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:113)

at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:76)

at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:519)

at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:505)

at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:341)

at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:301)

at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:136)

at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:94)

at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:194)

at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:73)

at org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1007)

at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1350)

at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1288)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1306)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1297)

at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1278)

at org.openremote.controller.statuscache.rules.RuleEngine.push(RuleEngine.java:203)

at org.openremote.controller.statuscache.EventProcessorChain.push(EventProcessorChain.java:196)

at org.openremote.controller.statuscache.StatusCache.update(StatusCache.java:293)

at org.openremote.controller.model.sensor.Sensor.update(Sensor.java:367)

at org.openremote.controller.model.sensor.Sensor$DeviceReader.run(Sensor.java:655)

at java.lang.Thread.run(Thread.java:744)

``

It seems that the “thermostat_varia_salon” sensor is a type of range while “temperature” is a custom type. Please make the second one range or level then the error should be gone.

Yes that’s correct the “thermostat_varia_salon” sensor is a type of range while “temperature” is a custom type.

I do not understand what I have to do when you say “make the second one range or level” ?

for example, I have to change the “temperature” sensor type level is that?

thank you

You need to go to the designer, create a sensor “temperature_range” type range which uses the same command as your custom “temperature” sensor. Use the new “temperature_range” sensor in the rule.

There is another way of solving the problem, which is less elegant than the previous solution but faster to do and I would personally go this way - rewrite the rules LHS as:

rule “thermostat_salon_1” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, eval(Integer.parseInt(value.toString()) < $h) )

then

execute.command( “chauffage_on” );

end

``

thank you very much I will try the 2nd method but I keep aside the first method.

:slight_smile:

I modified the rules:

rule “thermostat_salon_1” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, eval(Integer.parseInt(value.toString()) < $h))

then

execute.command( “chauffage_on” );

end

rule “thermostat_salon_2” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, eval(Integer.parseInt(value.toString()) > $h))

then

execute.command( “chauffage_off” );

end

``

But now I have this error that appears :

ERROR 2017-11-19 17:13:09,560 : Rule definition ‘modeler_rules.drl’ could not be deployed. See errors below.

ERROR 2017-11-19 17:13:09,561 : Rule Compilation error The operator < is undefined for the argument type(s) int, Object

ERROR 2017-11-19 17:13:09,561 : Rule Compilation error The operator > is undefined for the argument type(s) int, Object

ERROR 2017-11-19 17:13:09,561 : Cannot start event processor ‘Drools Rule Engine’ : Cannot find KieModule: org.default:artifact:1.0.0-SNAPSHOT

``

You can try to put $h also inside the Integer.parseInt(). Anyway, this kind of errors forced me long time ago to use only custom type for sensors which I use in rules.

I want to try to put $h inside Integer.parseInt () but I do not know how to write it.

If I could the sensor thermostat_varia_salon I will have done custom type but it is a virtual command.

this kind of rule works but only a few hours:

rule “thermostat_salon_1” when

Event( source == “thermostat_varia_salon”, $h : value)

Event( source == “temperature”, value < $h)

then

execute.command( “chauffage_on” );

end

``

I do not remember having this kind of problem with drools version 5.1.1.

to put $h inside Integer.parseInt () do I have to do that ?

Event( source == “thermostat_varia_salon”, eval(Integer.parseInt(value.toString()) : $h) )

the temperature sensor gives me a decimal value is that it can be the origin of my problem ?