Trend Integration: Current Behavior - Bug or Feature?

Hello,

This is a question about the current implementation/behavior of the trend integration: Trend - Home Assistant

I had the demand to get informed about certain humidity increases, delivered by one of my sensors. So at first I thought I would implement something on my own but later found the “trend integration”.
So I have been fiddling around with this integration for some time now and it basically detects the “rising slope” I am after. That is, the sensor sets the trend correctly to “true” as I expected it.

However, after an initial enthusiasm I discovered, that the trend stays in this state (true) for much too long. The humidity felll again, but the sensor still claimed a rising trend.

I debugged this down (by logging all sensor values and timestamps) and came to the conclusion that the following happened:

  • the condition to set the trend to true was given: number of minimum samples in the given time frame + the minimum gradient was reached → fine
  • now the humidity fell again, but unfortunately slower than it rose. This means, there were not enough samples in the desired time frame to let the Integration compute a trend

This means, after the initial rise, the trend sensor was unable to compute a trend at all, which is fine. If you start in such a condition the sensor gets the value “unknown”, which is also fine.

My expectation would be, if this situation happens, and the current state of the trend is “true”, let’s say for 5 minutes, but then the trend sensor cannot determine the trend anymore, it switches back to unknown(!). Today it just stays in the state of “true”, until there are enough samples again, which might take forever. This is in my opinion at least misleading if not even wrong. A trend in the state of “true” should reflect the current state. If it is not possible to determine this state, it should switch to “unknown”. Any other types of sensors would behave the same, if the value cannot be fetched anymore (for whatever reason), the state switches to “unknown”.

I hope you could follow my thoughts and I am curious to hear your opinions about the observed behavior. What do you think?

Dan

Update: maybe I am not the first wondering: