Is there a relatively simple way to discard readings that are wrong? I’ve got a couple of dht22 sensors on two raspberry pis.
Occasionally they’ll post a 6 degree reading when it’s about 18 degrees in the room. It’s obviously an error. I’d there some sort of comparison rule I could put in place to discard changes >5 degree difference from the last reading?
If you create a second item for each sensor item, like
Number Temperature "Temperature [%.1f]" (groupA,groupB)
Number Temperature_from_sensor "Temperature from sensor [%.1f]" { ...your current binding... }
and then a rule like this:
import org.openhab.core.library.types.DecimalType // not needed in OH2
rule TemperatureFilter
when
Item Temperature_from_sensor changed
then
if ((Temperature.state instanceof DecimalType) && Math::abs((Temperature.state as DecimalType) - (Temperature_from_sensor.state as DecimalType)) > 5) {
logWarn("dht22", "Discarding unbelievable sensor value " + Temperature_from_sensor.state)
} else {
Temperature.postUpdate(Temperature_from_sensor.state)
}
end
The above intends (untested) to discard updates when a previous value is known and it differs from the new proposed value by more than 5 degrees. Otherwise, it forwards it on to the item you want to monitor.
I have items from a weather source that occasionally report wildly incorrect temperatures, which are then persisted and will pollute charts. If I add a rule like above, these bad values ought to be discarded.
Do you know of a what of taking variable sensors and applying the same rules to it? or can I create a rule that takes a sensor and operate on the passed in variable?