Bug with the rules

110 views
Skip to first unread message

Pierre Pierrot

unread,
Nov 7, 2017, 12:38:53 PM11/7/17
to OpenRemote
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)



Michal Rutka

unread,
Nov 7, 2017, 2:19:54 PM11/7/17
to OpenRemote
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.
Message has been deleted

Pierre Pierrot

unread,
Nov 7, 2017, 2:31:10 PM11/7/17
to OpenRemote
I think I have things to improve in my rules but in general it works.

package org.openremote.controller.protocol

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;


import org.openremote.controller.utils.Logger;
import org.openremote.controller.Constants;
import org.openremote.controller.model.event.*
import java.util.Date;
import java.text.SimpleDateFormat;




rule "start_system"

when eval(true)


 then

 execute.command( "thermostat_varia", 15);
 execute.command( "securite_status", 0);
 execute.command( "virtual_etat_multisensor", 0);
 execute.command( "virtual_etat_porte", 0);
 execute.command( "virtual_etat_capteur_fumee", 0);
 execute.command( "virtual_etat_capteur_eau", 0);
 execute.command( "armement_on" );
 execute.command( "thermostat_image", 0);

  execute.command("VCODE","-");
  execute.command("VKEY","-");

end





rule "Alarme" when

  Event( source == "detection_porte", value == "on" )
  Event( source == "armement_status", value == "on" )
  

then
  
  execute.command( "sms_ouverture" );

end





rule "Time detecteur fumee" when

  Event( source ==  "detection_fumee", value == "on" )


then

  Date now = new Date();
  SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM' ---- 'H:mm:ss");
  execute.command("heure_detection_fumee", "" +dateFormatter.format(now));

end





rule "Time detecteur eau" when

  Event( source ==  "detection_innondation", value == "on" )


then

  Date now = new Date();
  SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM' ---- 'H:mm:ss");
  execute.command("heure_detection_innondation", "" +dateFormatter.format(now));

end






rule "Time multisensor" when

  Event( source ==  "detection", value == "on" )


then

  Date now = new Date();
  SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM' ---- 'H:mm:ss");
  execute.command("heure_detection_multisensor", "" +dateFormatter.format(now));

end








rule "Time porte" when

  Event( source ==  "detection_porte", value == "on" )


then

  Date now = new Date();
  SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM' ---- 'H:mm:ss");
  execute.command("heure_detection_porte", "" +dateFormatter.format(now));

end






rule "etat_multisensor_on"


 when

   Event( source == "etat_multisensor" , value == "on" )
  

 then

   execute.command( "virtual_etat_multisensor", 0); 

  end






rule "etat_multisensor_off"

timer (int: 175000s)

 when

   Event( source == "etat_multisensor" , value == "off" )
  

 then

   execute.command( "virtual_etat_multisensor", 1); 

  end






rule "battery_multisensor_hs" when

   Event( source == "battery_multisensor", value == 255)


 then

   execute.command( "virtual_battery_multisensor", 0); 

  end





rule "battery_multisensor_faible" when

   Event( source == "battery_multisensor", value <= 9)


 then

   execute.command( "virtual_battery_multisensor", 0); 

  end





rule "battery_multisensor_moyen"  when

   Event( source == "battery_multisensor", value >= 10 && <= 49)


 then

   execute.command( "virtual_battery_multisensor", 1 ); 

  end





rule "battery_multisensor_elevee" when

   Event( source == "battery_multisensor", value >= 50 && <= 100)

 then

   execute.command( "virtual_battery_multisensor", 2 ); 

  end












rule "etat_detecteur_porte_on"


 when

   Event( source == "etat_porte" , value == "on" )
  

 then

   execute.command( "virtual_etat_porte", 0); 

  end






rule "etat_detecteur_porte_off"

timer (int: 175000s)

 when

   Event( source == "etat_porte" , value == "off" )
  

 then

   execute.command( "virtual_etat_porte", 1); 

  end





rule "battery_porte_hs" when

   Event( source == "battery_porte", value == 255)


 then

   execute.command( "virtual_battery_porte", 0); 

  end





rule "battery_porte_faible" when

   Event( source == "battery_porte", value <= 9)


 then

   execute.command( "virtual_battery_porte", 0); 

  end




rule "battery_porte_moyen"  when

   Event( source == "battery_porte", value >= 10 && <= 49)


 then

   execute.command( "virtual_battery_porte", 1 ); 

  end




rule "battery_porte_elevee" when

   Event( source == "battery_porte", value >= 50 && <= 100)

 then

   execute.command( "virtual_battery_porte", 2 ); 

  end









rule "etat_capteur_eau_on"


 when

   Event( source == "etat_capteur_eau" , value == "on" )
  

 then

   execute.command( "virtual_etat_capteur_eau", 0); 

  end






rule "etat_capteur_eau_off"

timer (int: 175000s)

 when

   Event( source == "etat_capteur_eau" , value == "off" )
  

 then

   execute.command( "virtual_etat_capteur_eau", 1); 

  end







rule "battery_capteur_eau_hs" when

   Event( source == "battery_capteur_eau", value == 255)


 then

   execute.command( "virtual_battery_capteur_eau", 0); 

  end





rule "battery_capteur_eau_faible" when

   Event( source == "battery_capteur_eau", value <= 9)


 then

   execute.command( "virtual_battery_capteur_eau", 0); 

  end




rule "battery_capteur_eau_moyen"  when

   Event( source == "battery_capteur_eau", value >= 10 && <= 49)


 then

   execute.command( "virtual_battery_capteur_eau", 1 ); 

  end




rule "battery_capteur_eau_elevee" when

   Event( source == "battery_capteur_eau", value >= 50 && <= 100)

 then

   execute.command( "virtual_battery_capteur_eau", 2 ); 

  end









rule "etat_capteur_fumee_on"


 when

   Event( source == "etat_capteur_fumee" , value == "on" )
  

 then

   execute.command( "virtual_etat_capteur_fumee", 0); 

  end






rule "etat_capteur_fumee_off"

timer (int: 175000s)

 when

   Event( source == "etat_capteur_fumee" , value == "off" )
  

 then

   execute.command( "virtual_etat_capteur_fumee", 1); 

  end







rule "battery_capteur_fumee_hs" when

   Event( source == "battery_capteur_fumee", value == 255)


 then

   execute.command( "virtual_battery_capteur_fumee", 0); 

  end





rule "battery_capteur_fumee_faible" when

   Event( source == "battery_capteur_fumee", value <= 9)


 then

   execute.command( "virtual_battery_capteur_fumee", 0); 

  end




rule "battery_capteur_fumee_moyen"  when

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


 then

   execute.command( "virtual_battery_capteur_fumee", 1 ); 

  end




rule "battery_capteur_fumee_elevee" when

   Event( source == "battery_capteur_fumee", value >= 50 && <= 100)

 then

   execute.command( "virtual_battery_capteur_fumee", 2 ); 

  end












rule "Depart1"

  timer (cron: 0 30 08 * * ?)

when eval(true)


 then

 execute.command( "securite_status", 1);

end





rule "Depart2"

  timer (cron: 0 00 10 * * ?)

when eval(true)


 then

  execute.command( "securite_status", 0);

end







rule "Arrivee1"

  timer (cron: 0 00 15 * * ?)

when eval(true)


 then

  execute.command( "securite_status", 2);

end




rule "Arrivee2"

  timer (cron: 0 30 17 * * ?)

when eval(true)


 then

  execute.command( "securite_status", 0);

end






rule "Allez" when

  Event( source == "securite_status", value == 1)
  Event( source == "detection_porte", value == "on" )
  

then
  
  execute.command("volet_salon_varia", 30);
  execute.command("volet_cuisine_varia", 50);

end








rule "Viens" when

  Event( source == "securite_status", value == 2)
  Event( source == "detection_porte", value == "on" )
  

then
  
  execute.command("volet_salon_varia", 99);
  execute.command("volet_cuisine_varia", 99);

end







rule "status_volet_salon_off" when

   Event( source == "volet_salon_conso", value <= 10)

 then

   execute.command( "virtual_volet_salon_status", 0 ); 

  end






rule "status_volet_salon_on" when

   Event( source == "volet_salon_conso", value >= 15)

 then

   execute.command( "virtual_volet_salon_status", 1 ); 

  end








rule "status_volet_cuisine_off" when

   Event( source == "volet_cuisine_conso", value <= 10)

 then

   execute.command( "virtual_volet_cuisine_status", 0 ); 

  end








rule "status_volet_cuisine_on" when

   Event( source == "volet_cuisine_conso", value >= 15)

 then

   execute.command( "virtual_volet_cuisine_status", 1 ); 

  end







rule "Dodo_off"

   timer (int: 2s)

 when

   Event( source == "dodo_status" , value == "on" )
 
 then

   execute.command( "dodo_off" ); 

  end






rule "dodo" when

  Event( source == "dodo_status", value == "on" )
  

then
  
  execute.command("volet_salon_varia", 0);
  execute.command("volet_cuisine_varia", 0);

end





rule "Confort" when

  Event( source == "thermostat_varia", $h : value)
  Event( source == "temperature", value < $h)


then

  execute.command( "chauffage_on" );

end




rule "Confort2" when

  Event( source == "thermostat_varia", $h : value)
  Event( source == "temperature", value > $h)
   

then

  execute.command( "chauffage_off" );

end







rule "thermostat_froid" when

   Event( source == "temperature", value <= 18)


 then

   execute.command( "thermostat_image", 0); 

  end





rule "thermostat_chaud"  when

   Event( source == "temperature", value >= 19)


 then

   execute.command( "thermostat_image", 1 ); 

  end








rule "temperature_froid" when

   Event( source == "temperature_ext", value <= 18)


 then

   execute.command( "virtual_temperature_ext", 0); 

  end





rule "temperature_chaud"  when

   Event( source == "temperature_ext", value >= 19)


 then

   execute.command( "virtual_temperature_ext", 1 ); 

  end










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





rule "armement_off" when

  Event( source == "VCODE", value == "1987" )
  

then
  
  execute.command("armement_off");

end



Message has been deleted

Pierre Pierrot

unread,
Nov 7, 2017, 10:08:41 PM11/7/17
to OpenRemote
it may be these rules that are problematic because it requires the function strings

Michal Rutka

unread,
Nov 8, 2017, 5:45:00 AM11/8/17
to OpenRemote
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.

Pierre Pierrot

unread,
Nov 8, 2017, 5:56:54 PM11/8/17
to openremot...@googlegroups.com
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

Michal Rutka

unread,
Nov 9, 2017, 5:52:05 AM11/9/17
to OpenRemote
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))

Pierre Pierrot

unread,
Nov 9, 2017, 9:35:22 AM11/9/17
to openremot...@googlegroups.com
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

Michal Rutka

unread,
Nov 9, 2017, 10:09:50 AM11/9/17
to OpenRemote
use || between eval()

Pierre Pierrot

unread,
Nov 9, 2017, 10:28:36 AM11/9/17
to openremot...@googlegroups.com

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:






Pierre Pierrot

unread,
Nov 19, 2017, 7:17:41 AM11/19/17
to openremot...@googlegroups.com
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)

Michal Rutka

unread,
Nov 19, 2017, 7:46:40 AM11/19/17
to OpenRemote
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.

Pierre Pierrot

unread,
Nov 19, 2017, 8:13:45 AM11/19/17
to openremot...@googlegroups.com
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


Michal Rutka

unread,
Nov 19, 2017, 8:27:30 AM11/19/17
to OpenRemote
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

 

On Sunday, November 19, 2017 at 2:13:45 PM UTC+1, Pierre Pierrot wrote:
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" ?

thank you


Pierre Pierrot

unread,
Nov 19, 2017, 8:38:15 AM11/19/17
to OpenRemote
thank you very much I will try the 2nd method but I keep aside the first method.

:-)

Pierre Pierrot

unread,
Nov 19, 2017, 11:16:10 AM11/19/17
to OpenRemote
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


Michal Rutka

unread,
Nov 20, 2017, 5:09:44 AM11/20/17
to OpenRemote
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.

Pierre Pierrot

unread,
Nov 20, 2017, 7:37:18 AM11/20/17
to OpenRemote
I want to try to put $h inside Integer.parseInt () but I do not know how to write it.

Pierre Pierrot

unread,
Nov 20, 2017, 12:01:36 PM11/20/17
to openremot...@googlegroups.com
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.

Pierre Pierrot

unread,
Nov 21, 2017, 3:20:23 PM11/21/17
to openremot...@googlegroups.com
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 ?

Michal Rutka

unread,
Nov 22, 2017, 11:24:32 AM11/22/17
to OpenRemote
No, the rule rather should read:

rule "thermostat_salon_1" when

  Event( source == "thermostat_varia_salon", $h : value)
 Event( source == "temperature", eval(Integer.parseInt(value.toString()) < Integer.parseInt($h.toString()) ))


then

  execute.command( "chauffage_on" );

end


Just after your last post I've realised that the answer is not so obvious for non programmers.

Pierre Pierrot

unread,
Nov 26, 2017, 12:17:42 PM11/26/17
to openremot...@googlegroups.com
It seems like it works.
By cons I do not know yet if it's because I made sure not to have any decimal or  if it is to have changed the rules.
I confirm that it's not easy when you're not a programmer. Thank you for your help
Reply all
Reply to author
Forward
0 new messages