[SOLVED] UNDEF state results in executing the rule

Hi,
I just check my logfile and see every 30s and error message from a rule.
The rule is compacting three (rain-) values into on string (so I can show them in one line)

rule "Compact Rain  actuall / 24h"
when
   Item Rain_Actual received update or
    Item Rain_1h received update or
     Item Rain_24h received update
then
    Summary_Rain.postUpdate(Rain_Actual.state.format("%.1f")+" L | "+Rain_1h.state.format("%.1f")+" L | "+Rain_24h.state.format("%.1f")+" L")
end

Actuall the weather station is offline and the values from all three variables are “UNDEF” (checked in the Karaf).
So I don’t understand why the rule is executed, because (imho) no item received an “update”.

Thie is from the log

...
2019-05-23 14:15:29.612 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Compact Rain  actuall / 24h': f != java.lang.String
2019-05-23 14:15:29.641 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Compact Rain  actuall / 24h': f != java.lang.String
2019-05-23 14:15:29.647 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Compact Rain  actuall / 24h': f != java.lang.String
...

How can I suppress the error? Modify my when-part?

Item Rain_Actual (received update AND != UNDEF) or

What makes you think that? At boot up time, all Items get set to NULL or have previous state restored by persistence.
When say a communication error occurs, many bindings will update an Item to UNDEF to indicate indeterminate (which is different from “not set yet”).
If the binding retries from time to time, it can issue another update to UNDEF, “yep, still broken”.

No. Work in the then part.

when
   Item someItem updated
then
   if ( someItem.state != UNDEF ) {
       // do stuff
   }

In your case with several Items that will each be getting updates, you’d probably do something like

if ( someItem.state != UNDEF && otherItem.state !=UNDEF && thirdItem.state != UNDEF ) {
1 Like

I understand, but the weaterstation is simply" off", so no update can be received (only: since 3 days is it “UNDEF”, but no chance from “0.5” to “UNDEF” or from “NULL” to “UNDEF” (OK, this is one time possible, but than: UNDEF!).
This is why I donÄt understand the error message from the rulle every 30s …

Or is “UNDEF” for oH sometimes different to “UNDEF” ?

Whichever mystery binding you use presumably tries to read your broken station every 30 seconds, only to find it is still broken.

Updating the Items with UNDEF is the right thing to do. Many users will want to test “Is this valid data” so leaving stale data in the Item is no good.

Updating the Items at every read is also the right thing to do, allowing people to test things like “how old is this data”. The updates take place whether they are different from last time or not This happens with real values, not just UNDEF. UNDEF is not a special case here.

You probably don’t notice when the station is working, but your rule will be running every 30 seconds (and I expect running three times) due to updates.

If you only want to run the rule when values change, a more appropriate rule trigger would be
when Item someItem changed.
I think I’d do it that way here - but you’d still need to cater for UNDEF as that causes change as well when it either gets broken or fixed.

It’s the Netatmo binding, so I wondering also about the issue I see in the log (30s intervall).
I think I have not set this intervall, and also unshure if I can change anywere …

You wrote this can be a bether trigger:

" when Item someItem changed ."

What is the difference to my “Solution” I already use ?
" when Item Rain_Actual received update …"

Docs says

Weather station does not need any refreshInterval setting. Based on a standard update period of 10mn by Netatmo systems - it will auto adapt

I guess that means that since the last successful read was more than ten minutes ago, the binding will keep trying. The 30 secs between retries must be built into the binding.
I wouldn’t worry about it if you fix the rule.

As explained above, any Item may be updated at any time by bindings or by a rule.
These updates may or may not cause a change of state.

I look at a meter reading “2.5” and mark that on a graph.
Next day, I look again - it’s still reading “2.5”. There is no change, but is that is still a valid reading with more meaning than not reading it or not recording it. I mark the next point on my graph and it tells me something more than just yesterdays reading did.
You’ll understand that idea from your rainfall readings, you can tell a dry day from a rainy one.

Let’s accept that you can update a state without changing it, and it is a useful thing to do?

So, openHAB allows you to trigger rules by update, and this does what it says - for every update even if no change.

If you only want to trigger a rule from an actual change, openHAB allows you to do that as well. That does what it says, and only triggers for changes - not updates to the same value.

For example, you might have a rule adding two numbers. You could run that rule at every update - it will work.
But if the numbers don’t actually change, there is no point, you’re just doing the adding over and over to get the same result.
Using a changed trigger would avoid unnecessary processing. It’s up to you, it’s your system.

2 Likes

Thanks a lot, I think I undestand!

In my case, the single real rain- and temperature values are written already in the DB every 5 minutes, also if teher was no change.
I just check it, the “UNDEF” seems not written, so perfect.

And the compact view should be also fine followed your idea to change from “…update …” to “…changed …”
The log entries disappear now.

Does this help finding the issue if the rain station if offline?

I struggle with the same issue (offline rain station although the according Thing is online !?)
So I would like to know by this check above if it’s not updating.

By the way: When did this happen to your rain station (mine was just offline after dropping below 17% battery.

How did you “revive” it without climbing on the roof? :wink: