Trigger automation based on previous and current state/value duration

Hello,

I have an automation which sends me a notification whenever the power consumption of the house is more than 500W for 2 minutes when nobody’s home.
The thing is it “resets” everytime the power is less than 500W even for a second leading to multiple notifications a day…

I’d like to trigger only if :
power was less than 500W from t-7 to t-2 minutes then is more than 500W from t-2 to now (ie. power less than 500W for 5 minutes then over 500W for 2 minutes, then trigger now)

I have the feeling that it should be fairly simple, yet all I can think of is needing at least 2 automations to do it…

Any ideas ?

Thanks in advance :slight_smile:

See this thread

Template Binary sensors have an optional parameter called delay_off where you can set an amount of time the template state must be render false before this sensor states will switch to off. Take a look at your sensor’s history and find the largest gap that you would want to still be included in the period of “over 500”, then set the time for the delay_off to that value. Your automation would then trigger on the binary sensor being “on” for 5 minutes.

If that approach doesn’t work for your situation, there are also a few math-based integrations the can be used to either “smooth” the sensor’s output.

Filter

thanks that should work for my case :slight_smile: