Detect peaks in humidity

Hi!

I have a humidity sensor that I need to detect peaks. The image attached is an example of these peaks.

I tried using the trend sensor but it is difficult to calculate the gradient.

Any help is appreciated.

Thanks.

You don’t need to calculate it. Look at the more info pop-up or the attributes in developer tools states menu. It will list the current gradient. Make your trip level 20-30% larger than that (assuming it is not currently peaking).

I tried, but the problem is that I can’t record the gradient, I need to watch while it happens, which I don’t know when.

I kind of made it work, but still some spurious triggering. Will try to optimize it.
Thanks.

No you dont. read what I wrote again.

Look what the gradient is when there are no peaks (most of the time), make the trip point bigger than that.

I’m using a binary sensor to detect a humidity increase to turn on a fan.

/entities/binary_sensors/master_bathroom_humidity_increase.yaml

platform: trend
sensors:
  # Tracks 3 humidity readings over 10 minutes. If the change is greater than 10%, evals to true. (10/(60*10))
  # Percent / (60 sec * Minutes)
  master_bathroom_humidity_increase:
    max_samples: 3
    entity_id: sensor.master_bathroom_multisensor_humidity
    sample_duration: 600
    min_gradient: 0.01666

When this binary sensor turns on I know to turn on the fan. That part was easy.

I was having trouble with determining when to turn off the fan. After trying many different options I have settled on this for turning off the fan. I turn off the fan once the humidity gets back to within 10% of what it was before the shower. I have a statistics sensor like this that tracks the humidity over time.

/sensors/master_bathroom_humidity_statistics.yaml

platform: statistics
name: Master Bathroom Humidity Statistics
entity_id: sensor.master_bathroom_multisensor_humidity
sampling_size: 20
max_age:
  hours: 8

This copes with different times of the year when the general humidy might be dry or wetter in the summer. Within this sensor there is an attribute for median which evens out the outliers in the data specifically any recent increases due to a shower.

I have an automation with a trigger of a change in the humidity. Any change. In my case it is entity_id: sensor.master_bathroom_multisensor_humidity.

The automation turns off the fan when a condition is met that the humidity is now within 10% of what it was.

      - condition: template
        value_template: "{{  ((( states.sensor.master_bathroom_multisensor_humidity.state | float - state_attr('sensor.master_bathroom_humidity_statistics', 'median') | float ) / state_attr('sensor.master_bathroom_humidity_statistics', 'median') | float ) * 100 ) | round(2) | abs < 10 }}"
      sequence:
        - service: switch.turn_off
          target:
            entity_id: switch.master_bathroom_fan_switch

I have not had any false positives and the fan has turned on and remained on perfectly.

Also there is a generic hygrostat integration coming up: Add generic hygrostat integration by Shulyaka · Pull Request #36759 · home-assistant/core · GitHub

Thanks for posting this. I have a question on the automation turning it off.
To me it looks like you have current value - (ave /ave). Which will come out to current value say 50 - ~1 * 100 which the abs will always be greater than 10.
Maybe I am reading this incorrectly ( good chance), but I do not see why you are using the same statistics sensor twice in your automation.

Thanks for this. I have two questions:

  1. How does the sample duration work? If the length is readings over 10 minutes, will the sensor turn on if there is a 10% increase within the first 30 seconds, or does it wait until the full 10 minutes has been observed in order to turn on?

  2. Why go with 10 minutes instead of say, 2? I intend to use this for a shower fan, and I would expect the humidity to climb fast once the shower is turned on.

Lastly, the sensor just shows as unknown - any idea why?