Check for how long an item has had a certain state from InfluxDB

Hi,

I want to check if there is an elevated risk for mold in my attic. I’m measuring temperature and humidity and calculating the “mould index” which is in which part of the below graph I’m in (I have the function already for the lines). I then store this value in InfluxDB. As you can see from the graph there is a “Spore germination time [days]” which I want to write a rule for. So I’m wondering if it’s somehow possible to check for how long an item has had a certain value in InfluxDB? So for instance if my attic temp and humidity is above the second to last line more than 16 days I want a notification, so how can I check if the item for the mold index has had a value for a certain amount of days?
image

I hope you understand the question :slight_smile:

Can’t you use minimumSince and check if that is above the threshold? If the minimum is higher, than for sure all other values are, too.

These are two different things though. What you really care about is the first one: “attic temp and humidity are above a threashold for a certain number of days.” But what you are asking for is “temp and humidity hasn’t changed at all in a number of days.”

So rephrasing the question to “Check how long an item has exceeded a threshold using InfuxDB” shows that @J-N-K is right on. You want to use minimumSince and maximumSince (depending on whether you care about going under the threshold or over the threshold.

The temp and humidity could change with every reading. If your sensor is reporting at all, every report could be different, if only just a little bit.

But to answer your original question, to test if an Item has been in the same state for a number of days (i.e. it hasn’t changed at all in all that time) you can make sure that the Item is only saving to persistence on every change and then use lastUpdate which will return a DateTime for when the Item changed to that state.

Awesome thanks @J-N-K and @rlkoshak!

Now that I got two options I think I’ll combine both lastUpdate and minimumSince in the rule to get the notification more informative.