Trend sensor and how to calculate

Hi All,

I want try the trend sensor to manage something’s.

I have a humidity sensor in bathroom and want create automation when the humidity is rising with 10% and stop the fan when its going down with 10%

example:
Normal humidity is lets say 50% and it takes 10-30 seconds to hit the 60% when the shower is in use
When fan is on the humidity from 60% will go down back to 50% between 5-10minutes (depend on how long you shower)

The humidity sensor will send every 5 seconds the new value, also when the value is the same.

I was trying to understand the settings of the trend sensor:

10% rising / 30 seconds = 0.33 gradient. 30sec / 5sec = 6 samples (new values from the hum sensor)

- platform: trend
  sensors:
    test_trend_up:
      friendly_name: "TEST Trend up"
      device_class: heat
      max_samples: 6
      entity_id: sensor.bathroom_humidity
      sample_duration: 20
      min_gradient: 0.33

10% go down / 10min (600sec) = -0.01666 gradient. 600sec / 5sec = 120 samples (new values from the hum sensor)

- platform: trend
  sensors:
    test_trend_down:
      friendly_name: "TEST Trend down"
      device_class: cold
      max_samples: 120
      entity_id: sensor.bathroom_humidity
      sample_duration: 600
      min_gradient: -0.01666

Is this the right calculation and settings or not? how can assist me with this?

Thanks

Hi, I think you did not calculate the gradient correctly.

The gradient is measured in sensor units per second
Trend - Home Assistant

So if you want to calculate a rise of 10% humidity per hour, it would be:
0,1/(60*60) = 0,000028

0.33 would be 10000% per hour.

br,
Olli

Yes that’s 10% in 1 hour. But I calculated 10% in 30seconds. I think that’s 10/30=0.33

I suggest “playing around” with different values a little and watch it on a chart. The gradient just seemed a little too high for me, a lower gradient would also “catch” your high rise in humidity.

BTW, s.o. is doing the exact same that you do here.

I’m using this to detect when to close the window in the morning again, when it starts getting hotter.

     bedroom_temperature_rising:
        entity_id: sensor.bedroom_temperature
        friendly_name: Schlafen Temperatur ansteigend
        sample_duration: 300
        max_samples: 120
        min_gradient: 0.000139 #  0.00027 -> 1 ;  0.000139 -> 0,5 degree per hour
        device_class: heat
2 Likes

Yes im playing around now. I think the trend option is the best way to let this work…

Hi! And how is this sensor used in automation?