Is it possible to use old value to decide in automation? like boolen= true now and was false for 2 hours

Hello everyone,

I try to write an automation checking for my various plant monitors and send notifications to my wife and me. The plant monitor I use (GitHub - Olen/homeassistant-plant: Alternative Plant component of home assistant) has a nice integration with OpenPlantBook and finds the need levels of water/… and gives an problem status back.
The problem is that the water level has some noise, so it might change back and forth. For sending a ‘please water me’-notification I can simply wait until the waterlevel is low for quite some time. That logic can not be used for the ‘thanks, that’s enough’ as it would only trigger hours later.
Is there a way to check the previous state of a variable? I would like to trigger it only after the level was low for >2 hours and is now high again.

Thanks for any help,
4nduril

There’s a HACS integration called Variables+History which allows you to save the value of a sensor and its previous value - you might be able to do something with that.

Set up an input boolean (toggle) helper with an automation to turn it on when the water level has been low for two hours.

Then include that helper’s state as a condition in your main automation, and reset it to off in the action of your main automation.