Multiple rules with similar triggers - would it work?

Hello!

I’m not sure if this approach would make a conflict, so, I was wondering if someone knows if it’s possible. I would like to make two rules, but both rules would use the same trigger item, with different state changes. For example:

rule "Rule #1"
when
   Item1 changed
then
   some code
end

rule "Rule #2"
when
   Item1 changed from 1 to 0
then
   some code
end

I know there is previousState, but, since I’m using MapDB as a persistence service, I can’t use it. I need this, because I need to handle one specific case differently then all the others. Thank you in advance.

Best regards,
Davor

You can do that.

I prefer the following construct:

rule "Rule #1+#2"
when
   Item1 changed
then
   //some code
   if (Item1.state == 0) {
      // some specific code
   }
end

Hello @ThomDietrich

I prefer that approach too, but in this case, it is not enough. The item state will become 0, but I need to handle it differently if it is updated to 0 from 1, and if it is updated to 0 from other values.

Best regards,
Davor

Aaah I see. In this case your approach seems good to me :thumbsup:

1 Like

Thank you for your help!

Best regards,
Davor