Rain sensor, reset and influxdb

Hi, I have an annoying issue with a RFX rain sensor. It has a Rain Total value that I bind to a persisted item (Influxdb) I then show the diff as hourly/daily precipitation. The thing is, when I change batteries, the rain total gets reset to 0 and then I get a very weird diagram showing there’s been negative precipitation. The reason is of course that until I changed batteries the Rain Total had a value (X) > 0, and after battery change it is 0, thus 0 - X = -X.
So I need some clever way to deal with the cyclic behaviour.
Does anyone have a suggestion for this?

Maybe it would be better to use a rule and another item.

rule "rain total to rain now"
when
    Item rainTotal changed
then
    if(previousState == NULL) return; // after startup of openHAB
    if(!(previousState instanceof Number)) return; // would cause error
    if(!(rainTotal.state instanceof Number)) return; // would cause error
    if(rainTotal.state as Number < previousState as Number) return; // new value less than old value -> battery changed

    rainAmount.postUpdate((rainTotal.state as Number) - (previousState as Number))
end

Now persist rainAmount with everyUpdate. Amount of rain within an hour should be the sum of each stored value within this hour.

1 Like

Hi Udo,

Yes, that’s a good solution I think.
I just found this NON_NEGATIVE_DIFFERENCE () in influx, that also seem to do the trick.

Thanks!

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.