Confusion about the trend binary sensor

Can someone explain what’s going on with this sensor?

I’ve got a trend binary sensor set up to trend the value of the average humidity in my room.

here is the config for both the trend sensor and the average humidity sensors:

binary_sensor:
  - platform: trend
    sensors:
      master_bedroom_humidity_trend:
        entity_id: sensor.master_bedroom_humidity_averaged
        friendly_name: Master Bedroom Humidity Trend

sensor:
  - platform: average
    name: 'Master Bedroom Humidity Averaged'
    duration:
      minutes: 5
    entities:
      - sensor.master_bedroom_humidity

here is the hostory charts for those entities:

the trend sensor isn’t trending the average sensor correctly.

you can see at 3:56 the average sensor is flat but the trend sensor is on

then at 3:57 the average sensor is still flat (no change in value) but the trend sensor turns back off.

then the trend sensor turns off and between 3:58 and 4:01 but the average sensor is totally flat between those same times.

then it does some other funky stuff later as the humidity dips and climbs again after the humidifier is switched back on.

You have not specified any settings for the trend sensor so it is using the defaults:

max_samples: 2
min_samples: 2
min_gradient: 0.0
sample_duration: 0

So your trend sensor is on when the average sensor gradient is at or above 0 %RH per second over a sample of 2 state changes. So it should be on whenever your average is increasing in value. Which it mostly appears to be doing.

Your average sensor might have more significant digits in its state than the 2 displayed in your graph, which is causing the changes when the average appears to be flat on the graph.

You can check the full precision of your sensor by pasting this into the Settings → Developer Tools → Template editor

{{ states('sensor.master_bedroom_humidity_averaged') }}

Or by checking the average sensor state value in in Settings → Developer Tools → States

One way to stop this binary sensor flapping would be to specify a minimum gradient very slightly above 0.

1 Like

Yeah I agree that’s what it generally does I just don’t know why it oscillates off and on when the sampled sensor flat lines.

I checked the actual sensor value in dev tools and the template editor and it has only 2 digits of precision as displayed in the graph.

unless the graph precision is hiding the actual fluctuations of the sensor even tho it’s only 2 digits of precision? It’s hard to know if that’s the case if the only way to see the history of the sensor is the very graph that’s hiding the actual changes.

I guess I’ll need to play around more with the sampling rates/etc and see if I can get it closer to reality.

it ordinarily wouldn’t be a big deal but I use the trend sensor to let me know when the humidifier is empty so I don’t run it dry for too long. The little fluctuations are messing with my automation since during normal operation the humidity changes consistently over time so I use a 15 minute window that if the humidity is decreasing and the humidifier is on then it’s likely empty. The 15 minute delay is necessary because it takes around 10+/- minutes for the humidity to start increasing again once the humidifier switches on.

thanks for the suggestions.