Hi,
I have a rule that is triggered by something like Item MyItem changed
. As “MyItem” is a hardware object this rule gets to execution in two possible ways:
- by a hardware event (e.g. a knob is touched)
- by some of my rules which changes the Item state with sendCommand/postUpdate
My issue is that a rule which does a sendCommand/postUpdate has to decide if it’s necessary that the other rule is also triggered. Sometimes I want to execute all rules defining MyItem changed
after updating the state; sometimes the execution should simply omit these rules.
At the first try I used postUpdate instead of sendCommand and thought that it should do. But I misunderstood the meaning of postUpdate. My actors didn’t get the new values and the other rules were still executed.
Now I followed my second approch which seems to work at first sight:
var Boolean blockRules = false
rule "Samplerule"
when
<Somthing happend. E.g. user pushed a button>
then
if (sampleCondition_1) {
blockRules = true // do NOT execute other rules
MyItem.sendCommand(NEWVALUE)
}
if (sampleCondition_2) {
MyItem.sendCommand(NEWVALUE) // DO execute other rules
}
Thread::sleep(500) // Is this necessary? I do not know how "fast" or multi-threaded rules execution is
blockRules = false
end
rule "Second Rule"
when
Item MyItem changed
then
if (!blockRules) {
// Some other tasks
}
end
Anyhow I wanted to ask if this is the best method to solve my issue or if there are already patterns for this that can do better. Also I do not know if there are “side-effects” which I haven’t figured out so far.
Thanks for reading and discussion this topic!
Greetings from Germany!