Migration to OH3: Calculation no longer working within a rule which is firing

First to say: my migration to OH3 has been very smooth overall. Thanks for the great work.

I’m only confronted with 1 minor thing no longer working.
I have a rule which calculates a percentage value from a current (mA) value. This is the filling rate of my rain water tank (input in mA, which I then convert to a percentage).

The rule is as following:

Rule "mA into pct"
when
    Item Niveau_regenwaterput changed
then
    val current = triggeringItem.state as Number
    val a = 0.41 as Number
    val b = -1.6636 as Number
    var y = ( a * current + b ) / 2.3 * 100
    Niveau_regenwaterput_pct.postUpdate(y)
end

Niveau_regenwaterput_pct is defined as a dummy item in a customs.items file:

Number      Niveau_regenwaterput_pct                "Niveau Regenwaterput [%d %%]"      <water>     // [%d %%] om percent weer te geven. [%.4f] voor decimal

Also Niveau_regenwaterput is defined as an item and I can see the corresponding value in openhab.

To be clear: the rule does fire in OH3. I have tested it with a light switch, which effectively turns on when the item ‘niveau_regenwaterput’ changes.
Moreover, the above rule worked flawlessly in OH2.5.

Problem is, since mygrating to OH3.0, Niveau_regenwaterput_pct no longer shows a value. It’s as if the caluclation is no longer performed, or the postUpdate is no longer working.

Any clues?

Hmmm, nothing obviously wrong. Probably worth adding some log lines at each step to see how far the rule goes, and what the outputs are?

There have been very recent changes with the triggeringItem implicit variable in OH3 DSL rules engine. Log out what you get there, and identify OH3 version for better understanding.

If your rule only triggers from one named Item you don’t need to use triggeringItem at all.

1 Like

Yes, That’s the reason!
I’ve changed the first line of the rule into:

val current = Niveau_regenwaterput.state as Number

And now it works.

So apparently, triggeringItem no longer works within rules in OH3