I have mapdb configured to persist all Items, along with restoreOnStartup.
I have some temperature sensors that occasionally fail, so I’m using the Expire binding to set these Items to UNDEF if they don’t receive an update at their expected interval (this avoids having erroneous values showing in sitemaps).
However, I’ve found that these UNDEF values aren’t being stored in mapdb, so when restoreOnStartup is called, I get the last decimal value. Example here:
This isn’t overly helpful but why don’t you fix the sensors? If it were me, I would put the effort there instead of compensating for their failure. To me, an unreliable sensor is not worth having.
Your projected dummy value and rule is definitely an option. Why not simply not restore it on startup… that would default it to UNDEF until it successfully reports in right?
@Moxified Oh absolutely I’ll fix the sensors, I just want to ensure I gracefully handle any failure that may occur in the future.
One of the reasons I’m doing this is to more easily spot if/when they do fail (battery exhaustion usually). Using UNDEF seems to work very elegantly, except this persistence issue. Do you know of a better way of doing this, generally?
@rlkoshak Thanks for the System started rule suggestion. I wonder if that rule could go further than that and check lastUpdate itself to avoid waiting for the Expire binding to trigger.
I would not restoreOnStartup. You already have to deal with the fact that the Items might be NULL at some point, so I would leave them as NULL until you get a valid reading. This ensures that you are not acting on stale and incorrect data. When the Item has a value you know that the Item value is valid and recent.
For my sensors, I implement what Moxified describes as well.
The sensor in question is an Jeenode board sending data into OpenHAB via the Serial binding, but I was planning to apply the same principles to various Z-Wave Fibaro sensors.
I figured the great thing about checking the value is up to date is that it would detect various kinds of failure.
Absolutely. If you need to generate an alert or suchlike, it should work to put all relevant Items in a Group with an OR aggregation. A rule can watch for the Group changing to UNDEF
EDIT (years later!) - you can now trigger from a Group using member of ... changed to UNDEF to spot timeouts