Automation trigger on specific temperature change moment

I would like to start an automation as soon as the temperature (see attached graph) increases after decline. See yellow marked spot. How to detect this properly and code this? Can someone point me in a good directon? T

Temperature is an entity measured by a netatmo sensor.

Thanks!

temp_development

You could store the temp value into an input_number every (say) 10 mins and compare current with input number value

1 Like

Have never used this integration myself but if the derivative from is negative and and now is positive then trigger?

I think that is how it works…

And there is also statistics sensor with min_value
plenty of choices :slight_smile:

I was also thinking along this direction. I think some extra logic or config might be needed to avoid jitter (aka flapping) if the measurement is quite flat and to compensate for sensor noise. I would first filter the data to make it smoother.

I’d personally use a trend sensor - that tells you if the value is increasing or decreasing and is really easy to use in a state trigger:

trigger:
  - platform: state
    entity_id: binary_sensor.whale_temperature_increasing
    to: 'on'
1 Like

And why not using a simple trigger on the value and then compare old value and new value (from and to)?

Because it is prone to flapping.

Sure the provided example shows a smooth transition. But that isn’t always the case. If the temp rises then falls, cloud cover, rain, etc all impact this behaviour.

The trend sensor has ‘debouncing’ features such as samples and duration to prevent this.

2 Likes

But that was not a request in the initial post.

yes, OP didn’t consider debouncing.

1 Like

TIL. Thanks for that.

1 Like

Thanks parautenbach! Could you elaborate a litter your reasoning on what you mean with filtering to avoid jitter?

Wat is debouncing exacty? Does it mean it compensates for little up/down measurements? And what about missing data for some period?

Flapping, debouncing, jitter, sensor noise, etc.: I think a few people are trying to say the same thing, so I’ll try to answer this collectively: The data you posted seem fairly smooth in the highlighted part, but this may not always be the case. You probably don’t want to trigger immediately, because the larger trend might be going one way, but for a moment it could go in the other direction, so you’ll get a false positive (look at your initial post in the period between 15h00 and 19h00).

Before I learnt about the trend sensor Tinkerer posted, my suggestion was to smooth the data more before taking the derivative. With the trend sensor, you don’t need that part though (if I read the docs correctly): min_gradient will probably do the job. It does seem you’d need to set up 2 of these if you want to track both an upward and downward trend (from your initial post it seems you only need the former).

3 Likes

This is great Pieter. I am going to work both with the trend sensor and filter sensor. Use these to compare values…

About Filtering. For temperature sensor purposes, what filtering would you apply? The sensor on average gives a measurement every 9 mins… but sometimes this is missing. How to get one filtered line of data indicating the temperature for every point in time based on filter.

any example config for this…? would help me thanks!
i probably do some filtering before

Great. Keen to see your results.

I would go for the lowpass option and pick a time_constant of 3 for starters. I don’t have enough experience with this particular integration to say how it will deal with missing values, but it might well be that it only looks at the state when the sensor is available. Practically, the 3 means it will take about 3 updates to get to the new value as the filtered value, if that new value is constant for the next 3 samples. For one update it will take 3 times 9 minutes, if you have a measurement available every time.

PS: A time constant of 2 in this case would be the same as a 2-sample moving average (the current and previous samples being weighed 50/50). A very high time constant basically means you give all the weight to the latest measurement.

1 Like

See Automation Conditions - Home Assistant and Automation Trigger Variables - Home Assistant, which results to something like

trigger:
  - platform: state
    entity_id:
      - sensor.abc
condition:
  - condition: template
    value_template: >-
      {{ float(trigger.to_state.state,default=0) >
      float(trigger.from_state.state,default=0) }}